Skip to content

test: add coverage suite for the onboarding PermissionsStep#333

Merged
quiet-node merged 2 commits into
quiet-node:mainfrom
andrewholzbach:test/permissions-step-coverage
Jul 20, 2026
Merged

test: add coverage suite for the onboarding PermissionsStep#333
quiet-node merged 2 commits into
quiet-node:mainfrom
andrewholzbach:test/permissions-step-coverage

Conversation

@andrewholzbach

@andrewholzbach andrewholzbach commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Description

Closes #137. Adds a test suite for PermissionsStep, the onboarding screen that gates the app on macOS Accessibility and Screen Recording permissions, which previously had no dedicated tests.

Changes

  • Add src/view/onboarding/__tests__/PermissionsStep.test.tsx: covers initial render states, button interactions, the Accessibility/Screen Recording grant-and-poll flows, the resume-after-relaunch flow, and each mountedRef/in-flight guard, bringing the component to 100% line/branch/function/statement coverage.
  • No changes to PermissionsStep.tsx itself this is test-only. Note: the component currently has no try/catch around its invoke() calls, so there's no reject-path/error-handling behavior to test yet; the suite covers every guard and branch that actually exists in the source.

Checklist

  • Tests added or updated for all changed code
  • bun run test:all:coverage passes with 100% coverage
  • bun run validate-build passes with zero warnings and zero errors
  • Commit message follows Conventional Commits (feat:, fix:, etc.) so the changelog is generated automatically

@quiet-node quiet-node left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for shipping this for #137. Looking great but some feedback below.

Btw one thing is could you add Closes #137 or Fixes #137 in the PR description so this PR auto-close the issue on merge. Addresses #137 links it but leaves the issue open.

check_accessibility_permission: false,
};

describe('PermissionsStep', () => {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: Co-located path is right for #137, but src/__tests__/OnboardingView.test.tsx already tests only PermissionsStep (misnamed). Heavy overlap with this suite.

Prefer migrate/trim the old file, or drop duplicated cases here, so we don't maintain two copies.

Comment thread src/view/onboarding/__tests__/PermissionsStep.test.tsx
Comment thread src/view/onboarding/__tests__/PermissionsStep.test.tsx
Comment thread src/view/onboarding/__tests__/PermissionsStep.test.tsx
Comment thread src/view/onboarding/__tests__/PermissionsStep.test.tsx
@andrewholzbach
andrewholzbach force-pushed the test/permissions-step-coverage branch from 01b5eb9 to 71c278a Compare July 19, 2026 14:31
expect(invoke).toHaveBeenCalledWith('request_screen_recording_access');
expect(invoke).toHaveBeenCalledWith('open_screen_recording_settings');
expect(
screen.getAllByRole('button', { name: 'Checking...' }).length,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: getAllByRole already throws on zero matches, so .length).toBeGreaterThan(0) can't fail. Use getByRole. Same at 275.

it('skips starting Accessibility polling when unmounted right after settings succeed', async () => {
let resolveOpenSettings: () => void = () => {};
enableChannelCaptureWithResponses(BASE_RESPONSES);
vi.useFakeTimers();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fake timers restored only by the trailing vi.useRealTimers(). setup.ts restores mocks, not timers, so a mid-test throw leaks fake timers into the rest of the file. Move the restore into an afterEach. Same at 449, 495, 578, 626, 675.

...BASE_RESPONSES,
reset_and_relaunch_for_grant: false,
open_accessibility_settings: undefined,
});

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: open_accessibility_settings: undefined is a no-op, fallthrough returns undefined anyway. Same at 101.

@quiet-node

Copy link
Copy Markdown
Owner

btw Thanks, Closes #137 is sorted.

Blocking: the duplicate suite is still here. src/__tests__/OnboardingView.test.tsx is untouched, and I checked, each suite alone already puts PermissionsStep.tsx at 100%. So this lands a second full suite for one component with no net coverage. Divergence is the real cost: a behavior change needs edits in two files, and missing one leaves a stale suite that stays green. Delete the old file and keep this one.

Withdrawing my mountedRef comments. I tried it, deleting both guards (PermissionsStep.tsx:205, :231) leaves this suite green and the old console.error-spy tests green too. React 18 is silent on setState-after-unmount and stopAxPolling()/stopScreenPolling() no-op after cleanup, so there's nothing observable to assert. My earlier ask was wrong. The open_screen_recording_settings one is fine to skip too, call order already covers it.

@andrewholzbach

Copy link
Copy Markdown
Contributor Author

Hi Logan, thanks for your feedback! Just pushed some changes to address your comments

@quiet-node

Copy link
Copy Markdown
Owner

Hi Logan, thanks for your feedback! Just pushed some changes to address your comments

Heyy @andrewholzbach LGTM! Merged! Thanks much for the effort!

@quiet-node
quiet-node merged commit 6228792 into quiet-node:main Jul 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test: Write tests for PermissionsStep.tsx

2 participants