ui: fix the cypress failures, and two real defects behind them

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.
This commit is contained in:
Roland 2026-07-30 12:53:19 -06:00
parent 4349ac6301
commit 826b37527b
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
8 changed files with 109 additions and 40 deletions

View file

@ -88,11 +88,17 @@ describe('Domains List Page', () => {
});
});
it('Edit button has correct styling', () => {
it('Edit control is a link to that domain\'s edit page', () => {
/*
* This used to assert Semantic's `ui button secondary` classes. Framework class
* names say nothing a user can perceive and they broke the moment the button
* changed libraries, so it now checks what actually matters: the control is a real
* link, and it points at the edit route rather than relying on a click handler.
*/
cy.get('table tbody tr').first().within(() => {
cy.get('a').contains('Edit').should('have.class', 'ui');
cy.get('a').contains('Edit').should('have.class', 'button');
cy.get('a').contains('Edit').should('have.class', 'secondary');
cy.contains('a', 'Edit')
.should('have.attr', 'href')
.and('match', /\/archives\/domain\/\d+\/edit$/);
});
});

View file

@ -47,14 +47,14 @@ describe('Keyboard Shortcuts', () => {
cy.wait('@getStatus');
// Search modal should be closed initially
cy.get('.ui.modal').should('not.exist');
cy.get('[role="dialog"]').should('not.exist');
// Click the search icon
cy.get('a.item').find('i.search.icon').click();
cy.get('[aria-label="Search"]').click();
// Search modal should open
cy.get('.ui.modal').should('be.visible');
cy.get('.ui.modal input').should('be.visible');
cy.get('[role="dialog"]').should('be.visible');
cy.get('[role="dialog"] input').should('be.visible');
});
it('search modal closes when clicking outside', () => {
@ -62,14 +62,14 @@ describe('Keyboard Shortcuts', () => {
cy.wait('@getStatus');
// Open search modal via click
cy.get('a.item').find('i.search.icon').click();
cy.get('.ui.modal').should('be.visible');
cy.get('[aria-label="Search"]').click();
cy.get('[role="dialog"]').should('be.visible');
// Click the dimmer to close
cy.get('.ui.dimmer').click({force: true});
// Click the overlay behind the modal to close it.
cy.get('.mantine-Modal-overlay').click({force: true});
// Modal should close
cy.get('.ui.modal').should('not.exist');
cy.get('[role="dialog"]').should('not.exist');
});
it('search modal has input focused', () => {
@ -77,10 +77,10 @@ describe('Keyboard Shortcuts', () => {
cy.wait('@getStatus');
// Open search modal via click
cy.get('a.item').find('i.search.icon').click();
cy.get('[aria-label="Search"]').click();
// Input should be focused (can type immediately)
cy.get('.ui.modal input').should('be.focused');
cy.get('[role="dialog"] input').should('be.focused');
});
});
@ -90,13 +90,13 @@ describe('Keyboard Shortcuts', () => {
cy.wait('@getStatus');
// Search modal should be closed initially
cy.get('.ui.modal').should('not.exist');
cy.get('[role="dialog"]').should('not.exist');
// Press Ctrl+K
cy.get('body').type('{ctrl}k');
// Search modal should open
cy.get('.ui.modal').should('be.visible');
cy.get('[role="dialog"]').should('be.visible');
});
it('opens search modal with Cmd+K (Mac)', () => {
@ -107,7 +107,7 @@ describe('Keyboard Shortcuts', () => {
cy.get('body').type('{meta}k');
// Search modal should open
cy.get('.ui.modal').should('be.visible');
cy.get('[role="dialog"]').should('be.visible');
});
it('closes search modal with Escape', () => {
@ -116,13 +116,13 @@ describe('Keyboard Shortcuts', () => {
// Open search modal
cy.get('body').type('{ctrl}k');
cy.get('.ui.modal').should('be.visible');
cy.get('[role="dialog"]').should('be.visible');
// Press Escape
cy.get('body').type('{esc}');
// Modal should close
cy.get('.ui.modal').should('not.exist');
cy.get('[role="dialog"]').should('not.exist');
});
it('Escape closes modal when input is focused', () => {
@ -130,14 +130,21 @@ describe('Keyboard Shortcuts', () => {
cy.wait('@getStatus');
// Open search modal via click
cy.get('a.item').find('i.search.icon').click();
cy.get('.ui.modal').should('be.visible');
cy.get('[aria-label="Search"]').click();
cy.get('[role="dialog"]').should('be.visible');
// Input should be focused, press Escape
cy.get('.ui.modal input').should('be.focused').type('{esc}');
/*
* 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('.ui.modal').should('not.exist');
cy.get('[role="dialog"]').should('not.exist');
});
});
@ -156,7 +163,7 @@ describe('Keyboard Shortcuts', () => {
// 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('.ui.modal').should('be.visible');
cy.get('[role="dialog"]').should('be.visible');
});
});
@ -166,10 +173,10 @@ describe('Keyboard Shortcuts', () => {
cy.wait('@getStatus');
// Open search modal
cy.get('a.item').find('i.search.icon').click();
cy.get('[aria-label="Search"]').click();
// Check placeholder text
cy.get('.ui.modal input').should('have.attr', 'placeholder').and('include', 'Search');
cy.get('[role="dialog"] input').should('have.attr', 'placeholder').and('include', 'Search');
});
it('can type search query', () => {
@ -177,13 +184,18 @@ describe('Keyboard Shortcuts', () => {
cy.wait('@getStatus');
// Open search modal
cy.get('a.item').find('i.search.icon').click();
cy.get('[aria-label="Search"]').click();
// Type in search box
cy.get('.ui.modal input').type('test query');
/*
* `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('.ui.modal input').should('have.value', 'test query');
cy.get('[role="dialog"] input').should('have.value', 'test query');
});
});
@ -208,7 +220,7 @@ describe('Keyboard Shortcuts', () => {
// Ctrl+K should still open search modal
cy.get('body').type('{ctrl}k');
cy.get('.ui.modal').should('be.visible');
cy.get('[role="dialog"]').should('be.visible');
});
it('Ctrl+K works while typing in input', () => {
@ -229,7 +241,7 @@ describe('Keyboard Shortcuts', () => {
// Ctrl+K should still open search modal (even when in input)
cy.get('input[placeholder="Domain filter..."]').type('{ctrl}k');
cy.get('.ui.modal').should('be.visible');
cy.get('[role="dialog"]').should('be.visible');
});
});
});

View file

@ -1,6 +1,6 @@
import React from "react";
import {Breadcrumbs, useTitle} from "./Common";
import {Button, Header, Icon} from "./Theme";
import {Button, Header, Icon} from "./ui";
import {useCalcQuery} from "../hooks/customHooks";
import {TemperatureCalculator} from "./calculators/TemperatureCalculator";
import {ElectricalCalculators} from "./calculators/ElectricalCalculators";

View file

@ -28,7 +28,7 @@ import {
} from "./ui";
import {useBluetooth, useDesktop, useHotspot, useSearchDirectories, useSearchOrder, useThrottle, useVnc, useWROLMode} from "../hooks/customHooks";
import {Media, SettingsContext, StatusContext, ThemeContext} from "../contexts/contexts";
import {themeChoices} from "./Theme";
import {themeChoices} from "../themes/names";
import {FilePreviewContext} from "./FilePreview";
import _ from "lodash";
import {killDownloads, startDownloads, unlockCookies} from "../api";
@ -472,6 +472,7 @@ export function SearchResultsInput({
resultRenderer = undefined,
loading = false,
inputRef = null,
autoFocus = false,
...props
}) {
const {value, setValue, handleChange} = useSearchValue(searchStr, onChange);
@ -508,6 +509,7 @@ export function SearchResultsInput({
clearable={clearable}
clearDisabled={clearDisabled}
inputRef={inputRef}
autoFocus={autoFocus}
/>
</div>
}

View file

@ -2,7 +2,7 @@ import React, {useCallback, useEffect, useRef, useState} from "react";
import {useNavigate} from "react-router";
import {useHotkeys} from "react-hotkeys-hook";
import {KeyboardShortcutsContext} from "../contexts/KeyboardShortcutsContext";
import {Modal} from "./Theme";
import {Modal} from "./ui";
import {SearchResultsInput} from "./Common";
import {useSearchSuggestions} from "./Search";
import HelpModal from "./HelpModal";
@ -64,7 +64,15 @@ function SearchModal({open, onClose}) {
}, [open, setSearchStr]);
useEffect(() => {
// Focus on the Search's <input/> when the modal is opened.
/*
* Focus the search input when the modal opens.
*
* `autoFocus` on the input below is what actually does it: the modal mounts its
* content on a later tick, so this effect runs while `inputRef.current` is still
* null. Semantic's modal mounted synchronously, which is why focusing here used
* to be enough. The ref call is kept for the case where the modal is already
* mounted and merely re-opened.
*/
if (open && inputRef.current) {
inputRef.current.focus();
}
@ -73,7 +81,7 @@ function SearchModal({open, onClose}) {
if (!open) return null;
return (
<Modal open={open} onClose={onClose} centered={false}>
<Modal open={open} onClose={onClose} centered={false} title='Search'>
<Modal.Content>
<SearchResultsInput
clearable
@ -87,6 +95,7 @@ function SearchModal({open, onClose}) {
resultRenderer={resultRenderer}
loading={loading}
inputRef={inputRef}
autoFocus
/>
</Modal.Content>
</Modal>

View file

@ -517,7 +517,9 @@ export function SearchIconButton() {
const {openSearchModal} = React.useContext(KeyboardShortcutsContext);
return (
<a className='item' style={{paddingRight: '0.7em'}} onClick={openSearchModal}>
<a className='item' style={{paddingRight: '0.7em'}} onClick={openSearchModal}
role='button' tabIndex={0} aria-label='Search'
onKeyDown={e => (e.key === 'Enter' || e.key === ' ') && openSearchModal()}>
<Icon name='search'/>
<ShortcutHint shortcutKey="K"/>
</a>

View file

@ -146,6 +146,16 @@ export function SearchBox({
}
} else if (event.key === 'Escape') {
// Closes the list; the typed text is left alone.
if (open) {
/*
* Escape dismisses the suggestions and nothing more. Without this the
* event carries on to whatever contains the box — inside the search modal
* that meant one Escape closed the list and the modal together, so a user
* correcting a mistyped query lost the whole modal. A second Escape, with
* the list already closed, still closes it.
*/
event.stopPropagation();
}
setOpen(false);
setHighlighted(-1);
}
@ -177,6 +187,13 @@ export function SearchBox({
disabled={disabled}
required={required}
autoFocus={autoFocus}
/*
* Inside a modal, Mantine's focus trap moves focus itself and overrides the
* input's own autoFocus — it honours this attribute instead. Setting both
* means the field is focused whether or not it is inside a modal, which is
* what a caller asking for autoFocus means.
*/
data-autofocus={autoFocus ? true : undefined}
onChange={handleChange}
onKeyDown={handleKeyDown}
// Open on focus when there is something to say — suggestions, or the fact

View file

@ -83,6 +83,27 @@ describe('Semantic UI removal', () => {
expect(bridges.sort()).toEqual(allowed.sort());
});
it('lets no migrated file keep rendering Semantic through Theme.tsx', () => {
/*
* The import check above only sees `semantic-ui-react`. `Theme.tsx` re-exports
* Semantic-backed wrappers under friendly names, so a file could drop its direct
* imports, leave the baseline, and still put Semantic components on screen —
* which is exactly how a Semantic modal survived in the search shortcut long
* after that file looked migrated.
*
* Theme.tsx also re-exports theme *names* (`themeChoices`, `darkTheme`, ...),
* which are data and carry no markup; those come from `themes/names` instead, so
* any import from Theme in a migrated file is a component import and a mistake.
*/
const fromTheme = /from ['"](\.{1,2}\/)+Theme['"]/;
const leaks = sourceFiles()
.filter(file => !baseline.includes(file))
.filter(file => !file.endsWith('components/Theme.tsx'))
.filter(file => fromTheme.test(fs.readFileSync(path.join(SRC, '..', file), 'utf8')));
expect(leaks).toEqual([]);
});
it('reports how much of the migration is left', () => {
// Not an assertion so much as a progress readout in the test output.
const remaining = importers().length;