2025-12-02 15:33:46 -07:00
|
|
|
import React from 'react';
|
2025-12-06 14:49:46 -07:00
|
|
|
import {createMockDomains, render, screen} from '../../test-utils';
|
2025-12-02 15:33:46 -07:00
|
|
|
import {CollectionTable} from './CollectionTable';
|
|
|
|
|
|
|
|
|
|
// Mock the TagsContext
|
|
|
|
|
jest.mock('../../Tags', () => ({
|
|
|
|
|
TagsContext: {
|
|
|
|
|
_currentValue: {
|
|
|
|
|
SingleTag: ({name}) => <span data-testid="single-tag">{name}</span>
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// Mock the Media component to test both mobile and desktop views
|
|
|
|
|
jest.mock('../../contexts/contexts', () => ({
|
|
|
|
|
...jest.requireActual('../../contexts/contexts'),
|
|
|
|
|
Media: ({children, at, greaterThanOrEqual}) => {
|
|
|
|
|
// Default to desktop view for most tests
|
|
|
|
|
if (greaterThanOrEqual === 'tablet') {
|
|
|
|
|
return <div data-testid="desktop-view">{children}</div>;
|
|
|
|
|
}
|
|
|
|
|
if (at === 'mobile') {
|
|
|
|
|
return <div data-testid="mobile-view">{children}</div>;
|
|
|
|
|
}
|
|
|
|
|
return children;
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
ui: thirty-five files off Semantic, leaving fifteen
Phase 2, part 4. Baseline 50 -> 15.
Migrated: all eight calculators, the rest of inventory and collections, the
Map/Zim/Docs cluster, Videos, Files, Search, Archive, DashboardPage,
DatesSelector, HelpModal, Events, Tags, Flasher's neighbours, admin Settings
and Status, Download, and App.
Also the three shared modules everything imports: api.js and customHooks.js
swap the Semantic toast library for the library's shim (same call shape), and
useForm.js renders the library's Message. useForm accepts both the old
`{content, header, positive|negative}` shape and the new `{kind, title}`,
because the pages building those objects migrate separately.
Two library gaps closed, both found by call sites needing them:
ActionInput is a forwardRef now. Its ref reaches the input rather than the
wrapper, because callers use it to focus or select the field -- a ref to the
surrounding div would do neither, which is why one call site had resorted to
hand-copying the component's markup.
Header takes a `color` token name. Three separate call sites had reached for
an inline style to colour a heading that carries meaning ("3 items to add"
against "2 to remove"), which is how a hex ends up in markup.
Two files needed repair after being interrupted mid-edit: MapViewer had a
Segment left in its error branch, and VideoPlayer had lost the useContext
import its own code still used. Neither jest nor tsc noticed; only
`npm run build` did, which is the whole reason that check exists.
Fifteen files remain: Archive, BulkTagModal, Channels, Docs, FileBrowser,
FilePreview, Flasher, Nav, Playlists, Theme.tsx, Upload, VideoPlayer, Zim,
ControllerPage, admin/Downloads. Theme.tsx is deliberately last -- the
unmigrated files still import its Semantic-backed wrappers, so it can only go
once they have.
2026-07-30 12:21:30 -06:00
|
|
|
// Mock SortableTable to simplify testing. Uses the real `Table` compound
|
|
|
|
|
// components (rather than raw <table>/<tr>/<td>) because `rowFunc` returns
|
|
|
|
|
// `Table.Row`/`Table.Cell` elements that read Mantine's table context.
|
|
|
|
|
jest.mock('../SortableTable', () => {
|
|
|
|
|
const {Table} = jest.requireActual('../ui');
|
|
|
|
|
return {
|
|
|
|
|
SortableTable: ({data, rowFunc, tableHeaders}) => (
|
|
|
|
|
<Table data-testid="sortable-table">
|
|
|
|
|
<Table.Header>
|
|
|
|
|
<Table.Row>
|
|
|
|
|
{tableHeaders.map(h => (
|
|
|
|
|
<Table.HeaderCell key={h.key} data-width={h.width}>{h.text}</Table.HeaderCell>
|
|
|
|
|
))}
|
|
|
|
|
</Table.Row>
|
|
|
|
|
</Table.Header>
|
|
|
|
|
<Table.Body>
|
|
|
|
|
{data.map(item => rowFunc(item))}
|
|
|
|
|
</Table.Body>
|
|
|
|
|
</Table>
|
|
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
});
|
2025-12-02 15:33:46 -07:00
|
|
|
|
2025-12-05 17:12:21 -07:00
|
|
|
// Test column and routes configurations
|
|
|
|
|
const DOMAIN_COLUMNS = [
|
|
|
|
|
{key: 'domain', label: 'Domain', sortable: true, width: 7},
|
|
|
|
|
{key: 'archive_count', label: 'Archives', sortable: true, align: 'right', width: 2},
|
|
|
|
|
{key: 'size', label: 'Size', sortable: true, align: 'right', format: 'bytes', width: 2, hideOnMobile: true},
|
|
|
|
|
{key: 'tag_name', label: 'Tag', sortable: true, width: 2},
|
|
|
|
|
{key: 'actions', label: 'Manage', sortable: false, type: 'actions', width: 1}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const DOMAIN_ROUTES = {
|
2026-03-20 15:38:32 -06:00
|
|
|
list: '/archives/domains',
|
|
|
|
|
edit: '/archives/domain/:id/edit',
|
|
|
|
|
search: '/archives',
|
2025-12-05 17:12:21 -07:00
|
|
|
searchParam: 'domain'
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-02 15:33:46 -07:00
|
|
|
describe('CollectionTable', () => {
|
|
|
|
|
const mockCollections = createMockDomains(3);
|
|
|
|
|
|
repos: add the Repos UI
* Repos table (CollectionTable), New Repo and Edit pages (frequency,
mode, branch, description, tag, delete with an optional "also delete
its files").
* A GitHub-like repo page: upstream, branch, latest commit, a status
message when not yet downloaded or the last update failed, the file
tree (directories through ?path=, files in the file preview), and each
directory's README.
* Global search: a Repos section under Other with escaped README
headlines, Repos in the suggestions, and the search text sent to the
Other estimate.
* Settings: the Repos Directory field.
* CollectionTable columns may `render` their cell.
* Theme gallery: the repo summary, tree, and status icons.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 13:24:37 -06:00
|
|
|
describe('Column render', () => {
|
|
|
|
|
it('displays what a column renders, in the desktop and mobile rows', () => {
|
|
|
|
|
const columns = [
|
|
|
|
|
{key: 'name', label: 'Name', render: (c) => <em data-testid='rendered-name'>{c.name}!</em>},
|
|
|
|
|
{key: 'branch', label: 'Branch', render: (c) => c.branch || c.default_branch},
|
|
|
|
|
];
|
|
|
|
|
render(<CollectionTable
|
|
|
|
|
collections={[{id: 1, name: 'kiwix-tools', branch: null, default_branch: 'main'}]}
|
|
|
|
|
columns={columns}
|
|
|
|
|
routes={{search: '/repos/:id', id_field: 'id'}}
|
|
|
|
|
/>);
|
|
|
|
|
|
|
|
|
|
// Desktop: the rendered name is still the link to the collection.
|
|
|
|
|
expect(screen.getByTestId('rendered-name')).toHaveTextContent('kiwix-tools!');
|
|
|
|
|
expect(screen.getByTestId('rendered-name').closest('a')).toHaveAttribute('href', '/repos/1');
|
|
|
|
|
expect(screen.getByText('main')).toBeInTheDocument();
|
|
|
|
|
// Mobile lists the other columns by label.
|
|
|
|
|
expect(screen.getByText('Branch: main')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-02 15:33:46 -07:00
|
|
|
describe('Loading and Error States', () => {
|
|
|
|
|
it('renders loading placeholder when collections is null', () => {
|
|
|
|
|
const {container} = render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={null}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
ui: thirty-five files off Semantic, leaving fifteen
Phase 2, part 4. Baseline 50 -> 15.
Migrated: all eight calculators, the rest of inventory and collections, the
Map/Zim/Docs cluster, Videos, Files, Search, Archive, DashboardPage,
DatesSelector, HelpModal, Events, Tags, Flasher's neighbours, admin Settings
and Status, Download, and App.
Also the three shared modules everything imports: api.js and customHooks.js
swap the Semantic toast library for the library's shim (same call shape), and
useForm.js renders the library's Message. useForm accepts both the old
`{content, header, positive|negative}` shape and the new `{kind, title}`,
because the pages building those objects migrate separately.
Two library gaps closed, both found by call sites needing them:
ActionInput is a forwardRef now. Its ref reaches the input rather than the
wrapper, because callers use it to focus or select the field -- a ref to the
surrounding div would do neither, which is why one call site had resorted to
hand-copying the component's markup.
Header takes a `color` token name. Three separate call sites had reached for
an inline style to colour a heading that carries meaning ("3 items to add"
against "2 to remove"), which is how a hex ends up in markup.
Two files needed repair after being interrupted mid-edit: MapViewer had a
Segment left in its error branch, and VideoPlayer had lost the useContext
import its own code still used. Neither jest nor tsc noticed; only
`npm run build` did, which is the whole reason that check exists.
Fifteen files remain: Archive, BulkTagModal, Channels, Docs, FileBrowser,
FilePreview, Flasher, Nav, Playlists, Theme.tsx, Upload, VideoPlayer, Zim,
ControllerPage, admin/Downloads. Theme.tsx is deliberately last -- the
unmigrated files still import its Semantic-backed wrappers, so it can only go
once they have.
2026-07-30 12:21:30 -06:00
|
|
|
expect(container.querySelector('.mantine-Skeleton-root')).toBeInTheDocument();
|
2025-12-02 15:33:46 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders error message when collections is undefined', () => {
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={undefined}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText(/could not fetch collections/i)).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders empty message when collections is empty array', () => {
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={[]}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText(/no items yet/i)).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders custom empty message', () => {
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={[]}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
emptyMessage="No domains found"
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText(/no domains found/i)).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-05 17:12:21 -07:00
|
|
|
it('renders warning when columns is null', () => {
|
2025-12-02 15:33:46 -07:00
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={mockCollections}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={null}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
2025-12-05 17:12:21 -07:00
|
|
|
expect(screen.getByText(/no columns configured/i)).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders warning when columns is empty', () => {
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={mockCollections}
|
|
|
|
|
columns={[]}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText(/no columns configured/i)).toBeInTheDocument();
|
2025-12-02 15:33:46 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('Table Rendering', () => {
|
|
|
|
|
it('renders table with collection data', () => {
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={mockCollections}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Should render the sortable table
|
|
|
|
|
expect(screen.getAllByTestId('sortable-table')).toHaveLength(2); // mobile + desktop
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders correct number of rows', () => {
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={mockCollections}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Each collection should have a row in desktop view
|
|
|
|
|
const desktopView = screen.getByTestId('desktop-view');
|
|
|
|
|
const rows = desktopView.querySelectorAll('tbody tr');
|
|
|
|
|
expect(rows).toHaveLength(mockCollections.length);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders Edit links for each collection', () => {
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={mockCollections}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const editLinks = screen.getAllByText('Edit');
|
|
|
|
|
// Should have edit links for both mobile and desktop views
|
|
|
|
|
expect(editLinks.length).toBeGreaterThan(0);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('Search Filtering', () => {
|
|
|
|
|
it('filters collections by search string', () => {
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={mockCollections}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
searchStr="example1"
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const desktopView = screen.getByTestId('desktop-view');
|
|
|
|
|
const rows = desktopView.querySelectorAll('tbody tr');
|
|
|
|
|
// Should only show matching collection
|
|
|
|
|
expect(rows).toHaveLength(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows all collections when search string is empty', () => {
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={mockCollections}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
searchStr=""
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const desktopView = screen.getByTestId('desktop-view');
|
|
|
|
|
const rows = desktopView.querySelectorAll('tbody tr');
|
|
|
|
|
expect(rows).toHaveLength(mockCollections.length);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('handles case-insensitive search', () => {
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={mockCollections}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
searchStr="EXAMPLE1"
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const desktopView = screen.getByTestId('desktop-view');
|
|
|
|
|
const rows = desktopView.querySelectorAll('tbody tr');
|
|
|
|
|
expect(rows).toHaveLength(1);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-05 17:12:21 -07:00
|
|
|
describe('Column Widths', () => {
|
|
|
|
|
it('uses explicit widths from column config', () => {
|
2025-12-02 15:33:46 -07:00
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={mockCollections}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const desktopView = screen.getByTestId('desktop-view');
|
|
|
|
|
const headers = desktopView.querySelectorAll('th');
|
|
|
|
|
|
2025-12-05 17:12:21 -07:00
|
|
|
// DOMAIN_COLUMNS has explicit widths: domain=7, archive_count=2, size=2, tag_name=2, actions=1
|
|
|
|
|
expect(headers[0]).toHaveAttribute('data-width', '7');
|
|
|
|
|
expect(headers[1]).toHaveAttribute('data-width', '2');
|
|
|
|
|
expect(headers[2]).toHaveAttribute('data-width', '2');
|
|
|
|
|
expect(headers[3]).toHaveAttribute('data-width', '2');
|
|
|
|
|
expect(headers[4]).toHaveAttribute('data-width', '1');
|
2025-12-02 15:33:46 -07:00
|
|
|
});
|
|
|
|
|
|
2025-12-05 17:12:21 -07:00
|
|
|
it('uses widths from 4-column config', () => {
|
|
|
|
|
const fourColumns = [
|
|
|
|
|
{key: 'name', label: 'Name', sortable: true, width: 9},
|
|
|
|
|
{key: 'count', label: 'Count', sortable: true, align: 'right', width: 2},
|
|
|
|
|
{key: 'size', label: 'Size', sortable: true, format: 'bytes', width: 2},
|
|
|
|
|
{key: 'actions', label: 'Manage', type: 'actions', width: 1},
|
|
|
|
|
];
|
2025-12-02 15:33:46 -07:00
|
|
|
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={mockCollections}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={fourColumns}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const desktopView = screen.getByTestId('desktop-view');
|
|
|
|
|
const headers = desktopView.querySelectorAll('th');
|
|
|
|
|
|
2025-12-05 17:12:21 -07:00
|
|
|
expect(headers[0]).toHaveAttribute('data-width', '9');
|
|
|
|
|
expect(headers[1]).toHaveAttribute('data-width', '2');
|
|
|
|
|
expect(headers[2]).toHaveAttribute('data-width', '2');
|
|
|
|
|
expect(headers[3]).toHaveAttribute('data-width', '1');
|
2025-12-02 15:33:46 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('Row Click Handler', () => {
|
|
|
|
|
it('calls onRowClick when row is clicked', () => {
|
|
|
|
|
const mockOnRowClick = jest.fn();
|
|
|
|
|
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={mockCollections}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
onRowClick={mockOnRowClick}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const desktopView = screen.getByTestId('desktop-view');
|
|
|
|
|
const firstRow = desktopView.querySelector('tbody tr');
|
|
|
|
|
firstRow.click();
|
|
|
|
|
|
|
|
|
|
expect(mockOnRowClick).toHaveBeenCalledWith(mockCollections[0]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('adds clickable class when onRowClick is provided', () => {
|
|
|
|
|
const mockOnRowClick = jest.fn();
|
|
|
|
|
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={mockCollections}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
onRowClick={mockOnRowClick}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const desktopView = screen.getByTestId('desktop-view');
|
|
|
|
|
const firstRow = desktopView.querySelector('tbody tr');
|
|
|
|
|
expect(firstRow).toHaveClass('clickable');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not add clickable class when onRowClick is not provided', () => {
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={mockCollections}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const desktopView = screen.getByTestId('desktop-view');
|
|
|
|
|
const firstRow = desktopView.querySelector('tbody tr');
|
|
|
|
|
expect(firstRow).not.toHaveClass('clickable');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('Value Formatting', () => {
|
|
|
|
|
it('formats bytes values using humanFileSize', () => {
|
|
|
|
|
const collectionsWithSize = [{
|
|
|
|
|
id: 1,
|
|
|
|
|
domain: 'test.com',
|
|
|
|
|
size: 1048576, // 1 MB
|
|
|
|
|
archive_count: 5,
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={collectionsWithSize}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// humanFileSize(1048576) should return "1.0 MB"
|
|
|
|
|
// Multiple elements found (mobile + desktop), use getAllByText
|
|
|
|
|
const sizeElements = screen.getAllByText(/1\.0 MB/i);
|
|
|
|
|
expect(sizeElements.length).toBeGreaterThan(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders SingleTag for tag_name column', () => {
|
|
|
|
|
const collectionsWithTag = [{
|
|
|
|
|
id: 1,
|
|
|
|
|
domain: 'test.com',
|
|
|
|
|
tag_name: 'News',
|
|
|
|
|
size: 1000,
|
|
|
|
|
archive_count: 5,
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={collectionsWithTag}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getAllByTestId('single-tag')[0]).toHaveTextContent('News');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-05 17:12:21 -07:00
|
|
|
describe('Mobile View', () => {
|
|
|
|
|
it('hides columns with hideOnMobile in mobile view', () => {
|
|
|
|
|
const collectionsWithData = [{
|
|
|
|
|
id: 1,
|
|
|
|
|
domain: 'test.com',
|
|
|
|
|
archive_count: 5,
|
|
|
|
|
size: 1048576,
|
|
|
|
|
tag_name: 'News',
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={collectionsWithData}
|
|
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const mobileView = screen.getByTestId('mobile-view');
|
|
|
|
|
const mobileHeaders = mobileView.querySelectorAll('th');
|
|
|
|
|
|
|
|
|
|
// Mobile uses simplified 2-column layout: primary column + Manage
|
|
|
|
|
expect(mobileHeaders).toHaveLength(2);
|
|
|
|
|
expect(mobileHeaders[0]).toHaveTextContent('Domain');
|
|
|
|
|
expect(mobileHeaders[1]).toHaveTextContent('Manage');
|
|
|
|
|
|
|
|
|
|
// Archives should be visible in row content (no hideOnMobile)
|
|
|
|
|
expect(mobileView).toHaveTextContent('Archives:');
|
|
|
|
|
|
|
|
|
|
// Size should be hidden in row content (hideOnMobile: true)
|
|
|
|
|
expect(mobileView).not.toHaveTextContent('Size:');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-02 15:33:46 -07:00
|
|
|
describe('Links', () => {
|
|
|
|
|
it('renders search link on primary column when searchParam is configured', () => {
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={mockCollections}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Domain column should link to search with domain parameter
|
|
|
|
|
const desktopView = screen.getByTestId('desktop-view');
|
|
|
|
|
const domainLink = desktopView.querySelector('a[href*="domain="]');
|
|
|
|
|
expect(domainLink).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders edit link in actions column', () => {
|
|
|
|
|
render(
|
|
|
|
|
<CollectionTable
|
|
|
|
|
collections={mockCollections}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={DOMAIN_COLUMNS}
|
|
|
|
|
routes={DOMAIN_ROUTES}
|
2025-12-02 15:33:46 -07:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const editLinks = screen.getAllByRole('link', {name: /edit/i});
|
|
|
|
|
expect(editLinks.length).toBeGreaterThan(0);
|
|
|
|
|
expect(editLinks[0]).toHaveAttribute('href', expect.stringContaining('/edit'));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|