refactor(ext/test): extract TYPED_FORMS shared list for it.each tests
Code-review feedback on Task 7: the same Array<[name, renderForm]> of all 7 typed forms appeared in three test files (required-pill, popout-button, popout-button-fullscreen). A new typed form would have required updating all three. Now defined once in __tests__/_typed-forms.ts. Future typed-form additions get regression coverage automatically. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/// Shared list of typed-form (`renderForm`) entries for it.each parameterization
|
||||
/// across regression tests. Add a new typed form here ONCE — popup + fullscreen
|
||||
/// suites pick it up automatically.
|
||||
|
||||
import * as login from '../login';
|
||||
import * as secureNote from '../secure-note';
|
||||
import * as identity from '../identity';
|
||||
import * as card from '../card';
|
||||
import * as key from '../key';
|
||||
import * as totp from '../totp';
|
||||
import * as documentType from '../document';
|
||||
|
||||
type RenderFn = (app: HTMLElement, mode: 'add' | 'edit', existing: null) => void;
|
||||
|
||||
export const TYPED_FORMS: Array<[string, RenderFn]> = [
|
||||
['login', login.renderForm],
|
||||
['secure-note', secureNote.renderForm],
|
||||
['identity', identity.renderForm],
|
||||
['card', card.renderForm],
|
||||
['key', key.renderForm],
|
||||
['totp', totp.renderForm],
|
||||
['document', documentType.renderForm],
|
||||
];
|
||||
@@ -18,28 +18,12 @@ vi.mock('../../generator-panel', () => ({
|
||||
isGeneratorPanelOpen: () => false,
|
||||
}));
|
||||
|
||||
import * as login from '../login';
|
||||
import * as secureNote from '../secure-note';
|
||||
import * as identity from '../identity';
|
||||
import * as card from '../card';
|
||||
import * as key from '../key';
|
||||
import * as totp from '../totp';
|
||||
import * as documentType from '../document';
|
||||
|
||||
const forms: Array<[string, (app: HTMLElement, mode: 'add' | 'edit', existing: null) => void]> = [
|
||||
['login', login.renderForm],
|
||||
['secure-note', secureNote.renderForm],
|
||||
['identity', identity.renderForm],
|
||||
['card', card.renderForm],
|
||||
['key', key.renderForm],
|
||||
['totp', totp.renderForm],
|
||||
['document', documentType.renderForm],
|
||||
];
|
||||
import { TYPED_FORMS } from './_typed-forms';
|
||||
|
||||
describe('popout-to-tab button (fullscreen context)', () => {
|
||||
beforeEach(() => { document.body.innerHTML = '<div id="app"></div>'; });
|
||||
|
||||
it.each(forms)('%s form does NOT render the popout button', (_name, render) => {
|
||||
it.each(TYPED_FORMS)('%s form does NOT render the popout button', (_name, render) => {
|
||||
render(document.getElementById('app')!, 'add', null);
|
||||
expect(document.getElementById('popout-btn')).toBeNull();
|
||||
});
|
||||
|
||||
@@ -18,28 +18,12 @@ vi.mock('../../generator-panel', () => ({
|
||||
isGeneratorPanelOpen: () => false,
|
||||
}));
|
||||
|
||||
import * as login from '../login';
|
||||
import * as secureNote from '../secure-note';
|
||||
import * as identity from '../identity';
|
||||
import * as card from '../card';
|
||||
import * as key from '../key';
|
||||
import * as totp from '../totp';
|
||||
import * as documentType from '../document';
|
||||
|
||||
const forms: Array<[string, (app: HTMLElement, mode: 'add' | 'edit', existing: null) => void]> = [
|
||||
['login', login.renderForm],
|
||||
['secure-note', secureNote.renderForm],
|
||||
['identity', identity.renderForm],
|
||||
['card', card.renderForm],
|
||||
['key', key.renderForm],
|
||||
['totp', totp.renderForm],
|
||||
['document', documentType.renderForm],
|
||||
];
|
||||
import { TYPED_FORMS } from './_typed-forms';
|
||||
|
||||
describe('popout-to-tab button (popup context)', () => {
|
||||
beforeEach(() => { document.body.innerHTML = '<div id="app"></div>'; });
|
||||
|
||||
it.each(forms)('%s form renders the popout button', (_name, render) => {
|
||||
it.each(TYPED_FORMS)('%s form renders the popout button', (_name, render) => {
|
||||
render(document.getElementById('app')!, 'add', null);
|
||||
expect(document.getElementById('popout-btn')).not.toBeNull();
|
||||
});
|
||||
|
||||
@@ -18,33 +18,17 @@ vi.mock('../../generator-panel', () => ({
|
||||
isGeneratorPanelOpen: () => false,
|
||||
}));
|
||||
|
||||
import * as login from '../login';
|
||||
import * as secureNote from '../secure-note';
|
||||
import * as identity from '../identity';
|
||||
import * as card from '../card';
|
||||
import * as key from '../key';
|
||||
import * as totp from '../totp';
|
||||
import * as documentType from '../document';
|
||||
|
||||
const forms: Array<[string, (app: HTMLElement, mode: 'add' | 'edit', existing: null) => void]> = [
|
||||
['login', login.renderForm],
|
||||
['secure-note', secureNote.renderForm],
|
||||
['identity', identity.renderForm],
|
||||
['card', card.renderForm],
|
||||
['key', key.renderForm],
|
||||
['totp', totp.renderForm],
|
||||
['document', documentType.renderForm],
|
||||
];
|
||||
import { TYPED_FORMS } from './_typed-forms';
|
||||
|
||||
describe('required-pill migration', () => {
|
||||
beforeEach(() => { document.body.innerHTML = '<div id="app"></div>'; });
|
||||
|
||||
it.each(forms)('%s form has no legacy <span class="req"> markup', (_name, render) => {
|
||||
it.each(TYPED_FORMS)('%s form has no legacy <span class="req"> markup', (_name, render) => {
|
||||
render(document.getElementById('app')!, 'add', null);
|
||||
expect(document.body.innerHTML).not.toContain('class="req"');
|
||||
});
|
||||
|
||||
it.each(forms)('%s form contains the .req-pill markup on at least one label', (_name, render) => {
|
||||
it.each(TYPED_FORMS)('%s form contains the .req-pill markup on at least one label', (_name, render) => {
|
||||
render(document.getElementById('app')!, 'add', null);
|
||||
expect(document.body.innerHTML).toContain('class="req-pill">required</span>');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user