mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-01 04:16:24 -05:00
All 43 cypress specs pass now (was 36 of 43). Five of the seven failures were
stale selectors, two were real.
Real, and both mine:
The search modal stopped focusing its input. Mantine mounts modal content on
a later tick, so the effect that focused it ran while the ref was still null;
Semantic's modal mounted synchronously, which is why focusing there had been
enough. Fixed declaratively -- the field asks for focus itself, and SearchBox
also sets `data-autofocus`, which is what Mantine's focus trap honours when it
takes focus away from a plain autoFocus.
Escape closed the suggestion list and the enclosing modal at once, so a user
correcting a mistyped query lost the whole modal. Escape now dismisses the
suggestions and stops there; a second Escape, with the list closed, still
closes the modal.
Stale selectors, all in the specs: Semantic's icon font (`i.search.icon`) is
SVG now, its `.ui.modal`/`.ui.dimmer` are the library's modal and overlay, and
one test asserted a button carried the classes `ui button secondary`. That last
one is rewritten to check what a user can actually perceive -- that Edit is a
real link pointing at the edit route -- because framework class names say
nothing and break on every library change.
Two accessibility gaps the tests walked into:
The nav's search control was an anchor with an onClick, no name and no
keyboard path. It now has a name, a role and Enter/Space activation, which is
also what let the spec stop matching on icon-font classes.
The search dialog had no accessible name at all; it has one now.
One `{force: true}` remains, with its reason recorded: Cypress judges that
field covered because it sits in a fixed modal under a sticky header, and I
verified by hand at Cypress's own viewport that it is the topmost element at
its centre, unobscured, and focused on open.
Also closed a hole in the ratchet that this uncovered. A file could drop its
`semantic-ui-react` imports, leave the baseline, and still render Semantic
through Theme.tsx's wrappers -- which is exactly how a Semantic modal survived
in the search shortcut long after that file looked migrated. A test now
forbids it, and the three files doing it (Calculators, KeyboardShortcutsProvider,
and Common.js reaching for theme names) import from the library or from
themes/names instead.
247 lines
8.4 KiB
JavaScript
247 lines
8.4 KiB
JavaScript
describe('Keyboard Shortcuts', () => {
|
|
beforeEach(() => {
|
|
// Mock status API
|
|
cy.intercept('GET', '/api/status', {
|
|
statusCode: 200,
|
|
body: {
|
|
version: '1.0.0',
|
|
flags: {},
|
|
cpu_percent: 10,
|
|
memory_percent: 30,
|
|
}
|
|
}).as('getStatus');
|
|
|
|
// Mock settings API
|
|
cy.intercept('GET', '/api/settings', {
|
|
statusCode: 200,
|
|
body: {settings: {}}
|
|
}).as('getSettings');
|
|
|
|
// Mock tags API
|
|
cy.intercept('GET', '/api/tags', {
|
|
statusCode: 200,
|
|
body: {tags: []}
|
|
}).as('getTags');
|
|
|
|
// Mock events API
|
|
cy.intercept('GET', '/api/events', {
|
|
statusCode: 200,
|
|
body: {events: []}
|
|
}).as('getEvents');
|
|
|
|
// Mock search suggestions API
|
|
cy.intercept('POST', '/api/search/suggestions', {
|
|
statusCode: 200,
|
|
body: {
|
|
fileGroups: 0,
|
|
zimsEstimates: [],
|
|
channels: [],
|
|
domains: []
|
|
}
|
|
}).as('getSuggestions');
|
|
});
|
|
|
|
describe('Search Modal via Click', () => {
|
|
it('clicking search icon opens modal', () => {
|
|
cy.visit('/');
|
|
cy.wait('@getStatus');
|
|
|
|
// Search modal should be closed initially
|
|
cy.get('[role="dialog"]').should('not.exist');
|
|
|
|
// Click the search icon
|
|
cy.get('[aria-label="Search"]').click();
|
|
|
|
// Search modal should open
|
|
cy.get('[role="dialog"]').should('be.visible');
|
|
cy.get('[role="dialog"] input').should('be.visible');
|
|
});
|
|
|
|
it('search modal closes when clicking outside', () => {
|
|
cy.visit('/');
|
|
cy.wait('@getStatus');
|
|
|
|
// Open search modal via click
|
|
cy.get('[aria-label="Search"]').click();
|
|
cy.get('[role="dialog"]').should('be.visible');
|
|
|
|
// Click the overlay behind the modal to close it.
|
|
cy.get('.mantine-Modal-overlay').click({force: true});
|
|
|
|
// Modal should close
|
|
cy.get('[role="dialog"]').should('not.exist');
|
|
});
|
|
|
|
it('search modal has input focused', () => {
|
|
cy.visit('/');
|
|
cy.wait('@getStatus');
|
|
|
|
// Open search modal via click
|
|
cy.get('[aria-label="Search"]').click();
|
|
|
|
// Input should be focused (can type immediately)
|
|
cy.get('[role="dialog"] input').should('be.focused');
|
|
});
|
|
});
|
|
|
|
describe('Search Modal via Keyboard', () => {
|
|
it('opens search modal with Ctrl+K', () => {
|
|
cy.visit('/');
|
|
cy.wait('@getStatus');
|
|
|
|
// Search modal should be closed initially
|
|
cy.get('[role="dialog"]').should('not.exist');
|
|
|
|
// Press Ctrl+K
|
|
cy.get('body').type('{ctrl}k');
|
|
|
|
// Search modal should open
|
|
cy.get('[role="dialog"]').should('be.visible');
|
|
});
|
|
|
|
it('opens search modal with Cmd+K (Mac)', () => {
|
|
cy.visit('/');
|
|
cy.wait('@getStatus');
|
|
|
|
// Press Cmd+K (meta key)
|
|
cy.get('body').type('{meta}k');
|
|
|
|
// Search modal should open
|
|
cy.get('[role="dialog"]').should('be.visible');
|
|
});
|
|
|
|
it('closes search modal with Escape', () => {
|
|
cy.visit('/');
|
|
cy.wait('@getStatus');
|
|
|
|
// Open search modal
|
|
cy.get('body').type('{ctrl}k');
|
|
cy.get('[role="dialog"]').should('be.visible');
|
|
|
|
// Press Escape
|
|
cy.get('body').type('{esc}');
|
|
|
|
// Modal should close
|
|
cy.get('[role="dialog"]').should('not.exist');
|
|
});
|
|
|
|
it('Escape closes modal when input is focused', () => {
|
|
cy.visit('/');
|
|
cy.wait('@getStatus');
|
|
|
|
// Open search modal via click
|
|
cy.get('[aria-label="Search"]').click();
|
|
cy.get('[role="dialog"]').should('be.visible');
|
|
|
|
/*
|
|
* Assert the focus, then press Escape the way a user does -- as a document-level
|
|
* key. Typing into the field itself makes Cypress run its actionability checks
|
|
* against an element inside a `position: fixed` modal with a sticky header,
|
|
* which it reports as covered even when the browser paints it clear; verified
|
|
* by hand at this exact viewport. The behaviour under test is unchanged.
|
|
*/
|
|
cy.get('[role="dialog"] input').should('be.focused');
|
|
cy.get('body').type('{esc}');
|
|
|
|
// Modal should close
|
|
cy.get('[role="dialog"]').should('not.exist');
|
|
});
|
|
});
|
|
|
|
describe('Help Modal Accessibility', () => {
|
|
// Note: The ? shortcut (Shift+/) requires cypress-real-events for reliable testing
|
|
// These tests verify the help modal can be accessed and used once open
|
|
|
|
it('help modal can be closed with Close button', () => {
|
|
cy.visit('/');
|
|
cy.wait('@getStatus');
|
|
|
|
// Manually trigger help modal by calling the context (simulating the shortcut)
|
|
// For now, we test via the context API in unit tests
|
|
// This E2E test verifies the modal UI works when opened
|
|
|
|
// Since we can't reliably trigger ?, we'll test that Ctrl+K search modal works
|
|
// and trust unit tests for the help modal context functionality
|
|
cy.get('body').type('{ctrl}k');
|
|
cy.get('[role="dialog"]').should('be.visible');
|
|
});
|
|
});
|
|
|
|
describe('Search Input Behavior', () => {
|
|
it('typing in search shows placeholder', () => {
|
|
cy.visit('/');
|
|
cy.wait('@getStatus');
|
|
|
|
// Open search modal
|
|
cy.get('[aria-label="Search"]').click();
|
|
|
|
// Check placeholder text
|
|
cy.get('[role="dialog"] input').should('have.attr', 'placeholder').and('include', 'Search');
|
|
});
|
|
|
|
it('can type search query', () => {
|
|
cy.visit('/');
|
|
cy.wait('@getStatus');
|
|
|
|
// Open search modal
|
|
cy.get('[aria-label="Search"]').click();
|
|
|
|
/*
|
|
* `force` because Cypress's actionability check misjudges this field: it sits in
|
|
* a `position: fixed` modal with a sticky header and Cypress reports it covered.
|
|
* Verified by hand at this exact viewport (1000x660) that the input is the
|
|
* topmost element at its own centre, unobscured, and focused on open.
|
|
*/
|
|
cy.get('[role="dialog"] input').type('test query', {force: true});
|
|
|
|
// Input should have the value
|
|
cy.get('[role="dialog"] input').should('have.value', 'test query');
|
|
});
|
|
});
|
|
|
|
describe('Keyboard Shortcuts Integration', () => {
|
|
// These tests verify the keyboard shortcuts don't interfere with normal typing
|
|
|
|
it('Ctrl+K works even when another input exists on page', () => {
|
|
cy.intercept('GET', '/api/collections?kind=domain', {
|
|
statusCode: 200,
|
|
body: {
|
|
collections: [],
|
|
totals: {collections: 0},
|
|
metadata: {kind: 'domain', columns: []}
|
|
}
|
|
}).as('getDomains');
|
|
|
|
cy.visit('/archives/domains');
|
|
cy.wait('@getDomains');
|
|
|
|
// Should have a filter input on page
|
|
cy.get('input[placeholder="Domain filter..."]').should('exist');
|
|
|
|
// Ctrl+K should still open search modal
|
|
cy.get('body').type('{ctrl}k');
|
|
cy.get('[role="dialog"]').should('be.visible');
|
|
});
|
|
|
|
it('Ctrl+K works while typing in input', () => {
|
|
cy.intercept('GET', '/api/collections?kind=domain', {
|
|
statusCode: 200,
|
|
body: {
|
|
collections: [],
|
|
totals: {collections: 0},
|
|
metadata: {kind: 'domain', columns: []}
|
|
}
|
|
}).as('getDomains');
|
|
|
|
cy.visit('/archives/domains');
|
|
cy.wait('@getDomains');
|
|
|
|
// Focus on filter input
|
|
cy.get('input[placeholder="Domain filter..."]').focus().type('test');
|
|
|
|
// Ctrl+K should still open search modal (even when in input)
|
|
cy.get('input[placeholder="Domain filter..."]').type('{ctrl}k');
|
|
cy.get('[role="dialog"]').should('be.visible');
|
|
});
|
|
});
|
|
});
|