mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 19:16:08 +00:00
test: bring the packing, todo and dashboard changes in line with the CI gates
Lower the lint and strict baselines the redesign made smaller, keep the detail window and the todo tab under the complexity limit by moving their choices into helpers, read the toast in the detail test through its module rather than a window global, keep the new dialog focus case in the module's existing test file, show the panel's progress once in the standalone header, and point the planner wiring tests at the Lists menu.
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { focusDialog } from './dialogFocus';
|
||||
|
||||
function panelWith(html: string): HTMLElement {
|
||||
const panel = document.createElement('div');
|
||||
panel.tabIndex = -1;
|
||||
panel.innerHTML = html;
|
||||
document.body.appendChild(panel);
|
||||
return panel;
|
||||
}
|
||||
|
||||
describe('focusDialog', () => {
|
||||
const realMatchMedia = window.matchMedia;
|
||||
afterEach(() => {
|
||||
window.matchMedia = realMatchMedia;
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
const desktop = () => {
|
||||
Object.defineProperty(window, 'innerWidth', { configurable: true, writable: true, value: 1400 });
|
||||
window.matchMedia = vi
|
||||
.fn()
|
||||
.mockImplementation((q: string) => ({
|
||||
matches: q.includes('pointer: fine'),
|
||||
media: q,
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
})) as unknown as typeof window.matchMedia;
|
||||
};
|
||||
|
||||
it('FE-DIALOGFOCUS-001: on a desktop the first text field takes the focus', () => {
|
||||
desktop();
|
||||
const panel = panelWith('<input id="a" type="text"><input id="b" type="text">');
|
||||
focusDialog(panel);
|
||||
expect(document.activeElement?.id).toBe('a');
|
||||
});
|
||||
|
||||
it('FE-DIALOGFOCUS-002: a field marked as the start wins over the first one', () => {
|
||||
desktop();
|
||||
const panel = panelWith('<input id="a" type="text"><input id="b" type="text" data-initial-focus>');
|
||||
focusDialog(panel);
|
||||
expect(document.activeElement?.id).toBe('b');
|
||||
});
|
||||
|
||||
it('FE-DIALOGFOCUS-003: a focus already inside stays where it is', () => {
|
||||
desktop();
|
||||
const panel = panelWith('<input id="a" type="text"><input id="b" type="text" data-initial-focus>');
|
||||
(panel.querySelector('#a') as HTMLElement).focus();
|
||||
focusDialog(panel);
|
||||
expect(document.activeElement?.id).toBe('a');
|
||||
});
|
||||
});
|
||||
@@ -1,10 +1,10 @@
|
||||
// FE-SHARED-DIALOGFOCUS-001 to FE-SHARED-DIALOGFOCUS-009
|
||||
// FE-SHARED-DIALOGFOCUS-001 to FE-SHARED-DIALOGFOCUS-010
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { useState } from 'react'
|
||||
import { render, screen, fireEvent } from '../../../tests/helpers/render'
|
||||
import { DialogShell } from './DialogShell'
|
||||
import Modal from './Modal'
|
||||
import { firstTextField } from './dialogFocus'
|
||||
import { firstTextField, focusDialog } from './dialogFocus'
|
||||
|
||||
/** A desktop with a mouse: the only case the first field takes the focus. */
|
||||
function asDesktop() {
|
||||
@@ -138,4 +138,18 @@ describe('Modal focus (#1302)', () => {
|
||||
fireEvent.keyDown(save, { key: 'Tab' })
|
||||
expect(screen.getByRole('button', { name: 'Close' })).toHaveFocus()
|
||||
})
|
||||
|
||||
it('FE-SHARED-DIALOGFOCUS-010: a field marked as the start wins over the first one, a focus inside stays', () => {
|
||||
restore = asDesktop()
|
||||
const panel = document.createElement('div')
|
||||
panel.tabIndex = -1
|
||||
panel.innerHTML = '<input id="first" type="text"><input id="start" type="text" data-initial-focus>'
|
||||
document.body.appendChild(panel)
|
||||
focusDialog(panel)
|
||||
expect(document.activeElement?.id).toBe('start')
|
||||
;(panel.querySelector('#first') as HTMLElement).focus()
|
||||
focusDialog(panel)
|
||||
expect(document.activeElement?.id).toBe('first')
|
||||
panel.remove()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user