mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-03 21:29:59 -05:00
ui: Common.js and thirteen more files off Semantic
Phase 2, part 3. Baseline 63 -> 50.
Common.js is the one that mattered: 51 files import it, so its Semantic usage
was propping up the rest of the migration. Everything in it now comes from the
library -- Paginator, the two search inputs, DirectorySearch, TabLinks, the
toggles, the messages, APIButton, Breadcrumbs, SimpleAccordion, IframeViewer,
CardPoster, FileIcon, LoadStatistic, the theme menu, and the hotspot icons.
Also migrated: Placeholder, Apps, ArchivePreview, CbzViewer, AddToPlaylist,
TaggedDeleteConfirmModal, the collection edit/tag forms, and four inventory
components.
New in the library, all in the gallery and tested:
SearchBox Semantic's `<Search category>` with its grouped results shape
kept, because four call sites already build it. A real
combobox rather than a div that listens for clicks.
Pagination Semantic's prop names; onPageChange gets the page number.
TabBar the strip only -- routing stays with the caller.
IconStack Semantic's IconGroup, named once for assistive technology.
Table.HeaderCell sorted/onSort -- a real button carrying aria-sort.
Button/IconButton translate Semantic's size names.
That last one is defensive: unmigrated callers still pass size='tiny', and
Mantine drops a size it does not recognise without a word, so the button
quietly renders at the wrong size. Mapping here keeps the mixed state honest.
Three real bugs found and fixed on the way, none of them cosmetic:
* `fileSuffixIconName` returned fourteen icon names the map did not have, so
opening a folder with a PDF, a Word document or an archive in it logged an
error and drew a fallback glyph. All fourteen mapped, with a test that
walks the mapper's own return values, and another asserting every mapped
name resolves to a Tabler component that exists.
* `Statistic` relied on Semantic's `Statistic.Group` for its spacing, so on
the dashboard the load averages ran together into "1 MIN. LOAD5 MIN.
LOAD15 MIN. LOAD". It carries its own spacing now.
* Semantic's inverted stylesheet colors every descendant of an inverted
segment, so Toggle labels inherited #dddddd -- white pixels in night mode,
on the Settings page, which is exactly where someone adjusts their WROLPi
in the dark. Restated from tokens.
The baseline ratchet gained a third assertion: a migrated file may still lean
on Semantic's CSS classes without importing the library, which the import check
cannot see and which would collapse silently when Phase 4 deletes the
stylesheet. There is one such bridge today and it is now declared.
This commit is contained in:
parent
d359eea2d3
commit
6ea9d3645f
35 changed files with 978 additions and 1095 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import React from 'react';
|
||||
import {act, render, screen, waitFor} from '@testing-library/react';
|
||||
import {act, render, screen, waitFor} from '../test-utils';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import {DirectorySearch} from './Common';
|
||||
|
||||
|
|
@ -123,13 +123,14 @@ describe('DirectorySearch', () => {
|
|||
});
|
||||
|
||||
it('displays with required indicator', () => {
|
||||
const {container} = render(
|
||||
render(
|
||||
<DirectorySearch onSelect={mockOnSelect} value="" required/>
|
||||
);
|
||||
|
||||
// Semantic UI doesn't add required attribute to Search input,
|
||||
// but we verify the prop is passed
|
||||
expect(container.querySelector('.ui.search')).toBeInTheDocument();
|
||||
// Unlike Semantic UI's Search, the SearchBox forwards `required` straight
|
||||
// onto the input.
|
||||
const input = screen.getByPlaceholderText(/search directory names/i);
|
||||
expect(input).toBeRequired();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -153,11 +154,10 @@ describe('DirectorySearch', () => {
|
|||
loading: true,
|
||||
});
|
||||
|
||||
render(<DirectorySearch onSelect={mockOnSelect} value=""/>);
|
||||
const {container} = render(<DirectorySearch onSelect={mockOnSelect} value=""/>);
|
||||
|
||||
const searchContainer = screen.getByPlaceholderText(/search directory names/i)
|
||||
.closest('.ui.search');
|
||||
expect(searchContainer).toHaveClass('loading');
|
||||
// SearchBox renders a Loader alongside the input while `loading` is true.
|
||||
expect(container.querySelector('.wrolpi-searchbox-loading')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('hides loading indicator when loading state is false', () => {
|
||||
|
|
@ -166,11 +166,9 @@ describe('DirectorySearch', () => {
|
|||
loading: false,
|
||||
});
|
||||
|
||||
render(<DirectorySearch onSelect={mockOnSelect} value=""/>);
|
||||
const {container} = render(<DirectorySearch onSelect={mockOnSelect} value=""/>);
|
||||
|
||||
const searchContainer = screen.getByPlaceholderText(/search directory names/i)
|
||||
.closest('.ui.search');
|
||||
expect(searchContainer).not.toHaveClass('loading');
|
||||
expect(container.querySelector('.wrolpi-searchbox-loading')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('displays categorized results', async () => {
|
||||
|
|
@ -265,16 +263,16 @@ describe('DirectorySearch', () => {
|
|||
});
|
||||
|
||||
// Render with empty value prop (different from directoryName)
|
||||
const {container} = render(<DirectorySearch onSelect={mockOnSelect} value=""/>);
|
||||
render(<DirectorySearch onSelect={mockOnSelect} value=""/>);
|
||||
|
||||
// Find the Search component container and trigger blur on it
|
||||
const searchComponent = container.querySelector('.ui.search');
|
||||
// The SearchBox wires `onBlur` straight to the input (there is no longer a
|
||||
// wrapping Search component to blur instead).
|
||||
const input = screen.getByPlaceholderText(/search directory names/i);
|
||||
|
||||
// Blur the Search component - should trigger onBlur which calls onSelect
|
||||
// Blur the input - should trigger onBlur which calls onSelect
|
||||
await act(async () => {
|
||||
// Use fireEvent.blur which better simulates the Semantic UI Search blur behavior
|
||||
const {fireEvent} = require('@testing-library/react');
|
||||
fireEvent.blur(searchComponent);
|
||||
const {fireEvent} = require('../test-utils');
|
||||
fireEvent.blur(input);
|
||||
});
|
||||
|
||||
// Should call onSelect with directoryName from hook state
|
||||
|
|
@ -319,8 +317,16 @@ describe('DirectorySearch', () => {
|
|||
expect(screen.getByText('videos/nature')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// Click multiple results in succession
|
||||
// Click multiple results in succession. Choosing a result closes the
|
||||
// dropdown (as any combobox would) without moving focus off the input
|
||||
// (the option is chosen on mousedown, with the default prevented), so
|
||||
// pressing a key that reopens the list -- same as a real user -- is
|
||||
// needed before the next selection.
|
||||
await userEvent.click(screen.getByText('videos/nature'));
|
||||
await userEvent.keyboard('{ArrowDown}');
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('videos/tech')).toBeInTheDocument();
|
||||
});
|
||||
await userEvent.click(screen.getByText('videos/tech'));
|
||||
|
||||
// Should call onSelect for each selection
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue