Repository navigation
fix(mobile): drop repeated section headers from personal Security Agent notification settings #9454
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
Open
iscekic
wants to merge
6
commits into
main
Choose a base branch
from
drain/notifications-heading-scope
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6141909
fix(mobile): drop repeated section headers from personal Security Age…
iscekic bbb621b
fix(mobile): space the personal notification groups apart without the…
iscekic 672d755
fix(mobile): space the personal notification groups like the space ab…
iscekic 58c2374
fix(mobile): separate the personal notification groups with a wider b…
iscekic 4ca2444
test(mobile): assert the organization notification headings render
iscekic 342a861
Merge remote-tracking branch 'origin/main' into drain/notifications-h…
iscekic 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
190 changes: 190 additions & 0 deletions
190
apps/mobile/src/components/security-agent/notification-settings-sections.mounted.test.tsx
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,190 @@ | ||
| // The personal notification settings screen titles each of its two switches | ||
| // after the notification it turns on ("Email me about new findings", "Email me | ||
| // about SLA warnings"), so a section heading above a single switch only restates | ||
| // it. The organization screen titles both switches "Email organization owners", | ||
| // so a heading is the only thing that tells the two of them apart. | ||
|
|
||
| import { createElement } from 'react'; | ||
| import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { i18n } from '@/i18n'; | ||
| import { act, TestRenderer } from '@/test/renderer'; | ||
|
|
||
| import { NotificationSettingsScreen } from './notification-settings-screen'; | ||
|
|
||
| vi.mock('expo-crypto', () => ({ randomUUID: () => '00000000-0000-4000-8000-000000000000' })); | ||
| vi.mock('expo-haptics', () => ({ selectionAsync: vi.fn() })); | ||
| vi.mock('react-native', () => ({ | ||
| View: 'View', | ||
| ScrollView: 'ScrollView', | ||
| TextInput: 'TextInput', | ||
| Pressable: 'Pressable', | ||
| Switch: 'Switch', | ||
| Platform: { OS: 'android' }, | ||
| useColorScheme: () => 'light', | ||
| Alert: { alert: vi.fn() }, | ||
| I18nManager: { isRTL: false }, | ||
| })); | ||
| vi.mock('expo-router', () => ({ | ||
| useRouter: () => ({ back: vi.fn(), replace: vi.fn(), push: vi.fn() }), | ||
| useNavigation: () => ({ dispatch: vi.fn(), goBack: vi.fn() }), | ||
| usePreventRemove: () => undefined, | ||
| // The screen's disabled-config redirect only runs on focus, and the config | ||
| // these cases mount is enabled, so it never redirects here. | ||
| useFocusEffect: () => undefined, | ||
| })); | ||
| vi.mock('sonner-native', () => ({ toast: { success: vi.fn(), error: vi.fn() } })); | ||
| vi.mock('@/components/ui/icons', () => ({ Check: 'Check' })); | ||
| vi.mock('@/lib/hooks/use-theme-colors', () => ({ | ||
| useThemeColors: () => ({ | ||
| mutedForeground: '#000', | ||
| primaryForeground: '#fff', | ||
| primary: '#00f', | ||
| }), | ||
| })); | ||
| vi.mock('@/lib/hooks/use-security-agent', () => ({ | ||
| useSecurityAgentCapability: () => ({ | ||
| canManage: true, | ||
| status: 'allowed', | ||
| isLoading: false, | ||
| isFetching: false, | ||
| isError: false, | ||
| refetch: vi.fn(), | ||
| }), | ||
| useSecurityAgentConfig: () => ({ | ||
| data: { | ||
| isEnabled: true, | ||
| newFindingNotificationsEnabled: true, | ||
| newFindingNotificationMinSeverity: 'high', | ||
| slaNotificationsEnabled: true, | ||
| slaNotificationMinSeverity: 'medium', | ||
| slaNotificationWarningDays: 7, | ||
| }, | ||
| isLoading: false, | ||
| isError: false, | ||
| refetch: vi.fn(), | ||
| }), | ||
| useSaveSecurityAgentConfig: () => ({ mutateAsync: vi.fn(), isPending: false }), | ||
| useTrackSecurityAgentInteraction: () => ({ mutate: vi.fn() }), | ||
| })); | ||
| vi.mock('@rn-primitives/dialog', () => ({ | ||
| Action: 'AlertDialog.Action', | ||
| Cancel: 'AlertDialog.Cancel', | ||
| Content: 'AlertDialog.Content', | ||
| Description: 'AlertDialog.Description', | ||
| Overlay: 'AlertDialog.Overlay', | ||
| Portal: 'AlertDialog.Portal', | ||
| Root: 'AlertDialog.Root', | ||
| Title: 'AlertDialog.Title', | ||
| })); | ||
| vi.mock('@/components/destructive-confirm-dialog', () => ({ | ||
| DestructiveConfirmDialog: () => null, | ||
| })); | ||
| vi.mock('@/components/ui/input', () => ({ Input: 'Input' })); | ||
| vi.mock('@/components/ui/skeleton', () => ({ Skeleton: () => null })); | ||
| vi.mock('@/components/ui/text', () => ({ Text: 'Text' })); | ||
| vi.mock('@/components/ui/radio-group', () => ({ | ||
| RadioGroup: (props: { children?: unknown }) => props.children ?? null, | ||
| radioItemA11y: ({ | ||
| label, | ||
| checked, | ||
| disabled, | ||
| }: { | ||
| label: string; | ||
| checked: boolean; | ||
| disabled: boolean; | ||
| }) => ({ | ||
| accessibilityRole: 'radio', | ||
| accessibilityLabel: label, | ||
| accessibilityState: { checked, disabled, busy: false }, | ||
| }), | ||
| })); | ||
| vi.mock('@/components/screen-header', () => ({ ScreenHeader: () => null })); | ||
| vi.mock('@/components/platform-error-screen', () => ({ | ||
| PlatformErrorScreen: 'PlatformErrorScreen', | ||
| })); | ||
| vi.mock('@/components/security-agent/settings-save-button', () => ({ | ||
| SettingsSaveButton: () => null, | ||
| })); | ||
| vi.mock('@/components/tab-screen', () => ({ TabScreenScrollView: 'TabScreenScrollView' })); | ||
|
|
||
| const PERSONAL_SCOPE = 'personal'; | ||
| const ORGANIZATION_SCOPE = '00000000-0000-4000-8000-000000000001'; | ||
|
|
||
| let renderer: TestRenderer.ReactTestRenderer | undefined = undefined; | ||
|
|
||
| afterEach(() => { | ||
| act(() => { | ||
| renderer?.unmount(); | ||
| }); | ||
| renderer = undefined; | ||
| }); | ||
|
|
||
| function mount(scope: string): TestRenderer.ReactTestRenderer { | ||
| act(() => { | ||
| renderer = TestRenderer.create(createElement(NotificationSettingsScreen, { scope })); | ||
| }); | ||
| if (!renderer) { | ||
| throw new Error('renderer was not created'); | ||
| } | ||
| return renderer; | ||
| } | ||
|
|
||
| /** | ||
| * The section headings the tree paints, in order. A switch's accessible label | ||
| * is composed from the same strings on separate lines, so it cannot stand in | ||
| * for the heading itself. | ||
| */ | ||
| function sectionHeadings(screen: TestRenderer.ReactTestRenderer): string[] { | ||
| const sectionKeys = new Set([ | ||
| i18n.t('securityAgent.notifications.newFindingSection'), | ||
| i18n.t('securityAgent.notifications.slaSection'), | ||
| ]); | ||
| return screen.root | ||
| .findAllByType('Text') | ||
| .map(node => node.props.children) | ||
| .filter((child): child is string => typeof child === 'string' && sectionKeys.has(child)); | ||
| } | ||
|
|
||
| describe('personal scope', () => { | ||
| it('titles each switch after its notification and shows no section heading', () => { | ||
| const screen = mount(PERSONAL_SCOPE); | ||
| const copy = screen.root.findAllByType('Text').map(node => node.props.children); | ||
|
|
||
| expect(copy).toContain(i18n.t('securityAgent.notifications.newFindingPersonalTitle')); | ||
| expect(copy).toContain(i18n.t('securityAgent.notifications.slaPersonalTitle')); | ||
| expect(sectionHeadings(screen)).toEqual([]); | ||
| }); | ||
|
|
||
| it('separates the two switch groups by a break wider than the steps inside one', () => { | ||
| const screen = mount(PERSONAL_SCOPE); | ||
|
|
||
| expect(screen.root.findByType('TabScreenScrollView').props.contentContainerClassName).toBe( | ||
| 'px-6 pt-4 gap-7' | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('organization scope', () => { | ||
| it('heads each switch with its notification section, because both read the same recipient', () => { | ||
| const screen = mount(ORGANIZATION_SCOPE); | ||
| const names = screen.root.findAllByType('Switch').map(node => node.props.accessibilityLabel); | ||
|
|
||
| expect(names).toHaveLength(2); | ||
| expect(names[0]).toContain(i18n.t('securityAgent.notifications.newFindingSection')); | ||
|
iscekic marked this conversation as resolved.
Resolved
|
||
| expect(names[1]).toContain(i18n.t('securityAgent.notifications.slaSection')); | ||
| expect(names[1]).not.toContain(i18n.t('securityAgent.notifications.newFindingSection')); | ||
| expect(sectionHeadings(screen)).toEqual([ | ||
| i18n.t('securityAgent.notifications.newFindingSection'), | ||
| i18n.t('securityAgent.notifications.slaSection'), | ||
| ]); | ||
| }); | ||
|
|
||
| it('keeps the standard group gap, next to its headings', () => { | ||
| const screen = mount(ORGANIZATION_SCOPE); | ||
|
|
||
| expect(screen.root.findByType('TabScreenScrollView').props.contentContainerClassName).toBe( | ||
| 'px-6 pt-4 gap-6' | ||
| ); | ||
| }); | ||
| }); | ||
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.