-
-
Notifications
You must be signed in to change notification settings - Fork 11
fix(meshcore): restore chat hop pills for packed pathLen and late RF #761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // @vitest-environment jsdom | ||
| import { cleanup, render, screen } from '@testing-library/react'; | ||
| import { afterEach, describe, expect, it } from 'vitest'; | ||
| import { axe } from 'vitest-axe'; | ||
|
|
||
| import { hydrateAxeThemeColors } from '../lib/a11yTestHelpers'; | ||
| import { | ||
| markMeshcoreHopCorrected, | ||
| resetMeshcoreHopCorrectedMarksForTests, | ||
| } from '../lib/meshcoreLateRfHopEnrichment'; | ||
| import { ChatRfHopLabel, chatRfHopLabelPresentation } from './ChatRfHopLabel'; | ||
|
|
||
| /** Production Tailwind gray-400 / amber-400 on chat slate-800 for axe contrast. */ | ||
| const HOP_LABEL_BG_SLATE_800 = '#1e293b'; | ||
| const HOP_LABEL_GRAY_400 = '#9ca3af'; | ||
| const HOP_LABEL_AMBER_400 = '#fbbf24'; | ||
|
|
||
| /** jsdom has no Tailwind CSS — set chat-like slate + label colors for axe contrast. */ | ||
| function prepareHopLabelForAxe(container: HTMLElement, label: HTMLElement, color: string): void { | ||
| container.style.backgroundColor = HOP_LABEL_BG_SLATE_800; | ||
| label.style.color = color; | ||
| hydrateAxeThemeColors(container); | ||
| } | ||
|
|
||
| describe('chatRfHopLabelPresentation', () => { | ||
| it('uses amber accent only when corrected and motion is allowed', () => { | ||
| expect(chatRfHopLabelPresentation(false, false).className).toContain('text-gray-400'); | ||
| expect(chatRfHopLabelPresentation(true, false).className).toContain('text-amber-400'); | ||
| expect(chatRfHopLabelPresentation(true, true).className).toContain('text-gray-400'); | ||
| expect(chatRfHopLabelPresentation(true, true).refined).toBe(true); | ||
| expect(chatRfHopLabelPresentation(false, false).refined).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('ChatRfHopLabel', () => { | ||
| afterEach(() => { | ||
| cleanup(); | ||
| resetMeshcoreHopCorrectedMarksForTests(); | ||
| }); | ||
|
|
||
| it('renders hop count with default title when not corrected', async () => { | ||
| const { container } = render( | ||
| <ChatRfHopLabel | ||
| rxHops={3} | ||
| msg={{ storeId: 'ch:0:1:x', sender_id: 2, timestamp: Date.now(), channel: 0 }} | ||
| />, | ||
| ); | ||
| const label = screen.getByText('3 hops'); | ||
| expect(label).toBeInTheDocument(); | ||
| expect(label).toHaveAttribute('title', expect.stringMatching(/hop|routing/i)); | ||
| expect(label.className).toContain('text-gray-400'); | ||
| prepareHopLabelForAxe(container, label, HOP_LABEL_GRAY_400); | ||
| expect(await axe(container)).toHaveNoViolations(); | ||
| }); | ||
|
|
||
| it('uses refined title when a correction mark is active', async () => { | ||
| markMeshcoreHopCorrected('ch:0:2:x'); | ||
| const { container } = render( | ||
| <ChatRfHopLabel | ||
| rxHops={4} | ||
| msg={{ storeId: 'ch:0:2:x', sender_id: 2, timestamp: Date.now(), channel: 0 }} | ||
| />, | ||
| ); | ||
| const label = screen.getByText('4 hops'); | ||
| expect(label).toHaveAttribute('title', 'Updated from RF path'); | ||
| expect(label.className).toContain('text-amber-400'); | ||
| prepareHopLabelForAxe(container, label, HOP_LABEL_AMBER_400); | ||
| expect(await axe(container)).toHaveNoViolations(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { useSyncExternalStore } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| import { useReduceMotion } from '@/renderer/lib/icons/iconMotionContext'; | ||
| import { | ||
| isMeshcoreHopCorrected, | ||
| meshcoreChatHopUiKey, | ||
| subscribeMeshcoreHopCorrected, | ||
| } from '@/renderer/lib/meshcoreLateRfHopEnrichment'; | ||
|
|
||
| export interface ChatRfHopLabelProps { | ||
| rxHops: number; | ||
| msg: { | ||
| storeId?: string; | ||
| id?: number; | ||
| sender_id: number; | ||
| timestamp: number; | ||
| channel: number; | ||
| }; | ||
| } | ||
|
|
||
| /** Class/title for the hop pill when a late RF correction mark is active. */ | ||
| export function chatRfHopLabelPresentation( | ||
| corrected: boolean, | ||
| reduceMotion: boolean, | ||
| ): { className: string; refined: boolean } { | ||
| // gray-400 (#9ca3af) on chat slate-800 (#1e293b) keeps 4.5:1+ for text-[10px]. | ||
| if (!corrected) { | ||
| return { | ||
| className: 'text-[10px] text-gray-400 transition-colors duration-500', | ||
| refined: false, | ||
| }; | ||
| } | ||
| if (reduceMotion) { | ||
| return { | ||
| className: 'text-[10px] text-gray-400 transition-colors duration-500', | ||
| refined: true, | ||
| }; | ||
| } | ||
| return { | ||
| className: 'text-[10px] text-amber-400/80 transition-colors duration-500', | ||
| refined: true, | ||
| }; | ||
| } | ||
|
|
||
| /** Incoming RF hop count; briefly accents when late event 136 corrected a stored value. */ | ||
| export function ChatRfHopLabel({ rxHops, msg }: ChatRfHopLabelProps) { | ||
| const { t } = useTranslation(); | ||
| const reduceMotion = useReduceMotion(); | ||
| const uiKey = meshcoreChatHopUiKey(msg); | ||
| const corrected = useSyncExternalStore( | ||
| subscribeMeshcoreHopCorrected, | ||
| () => isMeshcoreHopCorrected(uiKey), | ||
| () => false, | ||
| ); | ||
| const { className, refined } = chatRfHopLabelPresentation(corrected, reduceMotion); | ||
| const title = refined | ||
| ? t('chatPanel.hopCountRefinedFromRf') | ||
| : t('nodeDetailModal.hopsFromRoutingTitle'); | ||
|
|
||
| return ( | ||
| <span className={className} title={title} aria-label={title}> | ||
| {t('nodeDetailModal.hopLabel', { count: rxHops })} | ||
| </span> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.