test(ext/setup): cover SetupStep registry shape + clearWizardState (Plan C Phase 3)
Asserts STEPS has the six steps in canonical order, each renders non-empty HTML and returns a teardown from attach, and clearWizardState zero-fills the reachable Uint8Array fields before resetting state. Keeps the existing finishSetup tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { finishSetup } from '../setup';
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { finishSetup, STEPS } from '../setup';
|
||||
import { state, clearWizardState } from '../setup-steps';
|
||||
|
||||
describe('finishSetup', () => {
|
||||
beforeEach(() => {
|
||||
@@ -35,3 +36,47 @@ describe('finishSetup', () => {
|
||||
expect(chrome.tabs.create).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('setup step registry', () => {
|
||||
it('has the six steps in canonical order', () => {
|
||||
expect(STEPS.map((s) => s.id)).toEqual(['mode', 'host', 'connection', 'vault', 'device', 'done']);
|
||||
});
|
||||
|
||||
it('each step renders non-empty HTML and attach returns a teardown', () => {
|
||||
const ctx = { state: {} as never, rerender: vi.fn(), goto: vi.fn() };
|
||||
for (const step of STEPS) {
|
||||
const html = step.render(ctx as never);
|
||||
expect(typeof html).toBe('string');
|
||||
expect(html.length).toBeGreaterThan(0);
|
||||
// render output must be in the DOM before attach (attach wires getElementById listeners)
|
||||
document.body.innerHTML = `<div id="app">${html}</div>`;
|
||||
const teardown = step.attach(document.body, ctx as never);
|
||||
expect(typeof teardown).toBe('function');
|
||||
teardown(); // must not throw
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('clearWizardState', () => {
|
||||
afterEach(() => {
|
||||
clearWizardState();
|
||||
});
|
||||
|
||||
it('zero-fills the reachable Uint8Array fields and resets state', () => {
|
||||
const carrier = new Uint8Array([1, 2, 3, 4]);
|
||||
const ref = new Uint8Array([5, 6, 7, 8]);
|
||||
state.carrierImageBytes = carrier;
|
||||
state.referenceImageBytes = ref;
|
||||
state.passphrase = 'secret';
|
||||
state.mode = 'new';
|
||||
|
||||
clearWizardState();
|
||||
|
||||
expect(Array.from(carrier)).toEqual([0, 0, 0, 0]); // fill(0) ran on the captured ref
|
||||
expect(Array.from(ref)).toEqual([0, 0, 0, 0]);
|
||||
expect(state.carrierImageBytes).toBeNull(); // field reset
|
||||
expect(state.referenceImageBytes).toBeNull();
|
||||
expect(state.passphrase).toBe('');
|
||||
expect(state.mode).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user