mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 09:26:17 -05:00
Add a Repos module that mirrors git repositories (#783)
Repos keeps local mirrors of git repositories, cloned over https and kept up to date on a schedule. - A Repo is a Collection (kind='repo') plus a `repository` row. The new `git` downloader clones it, then updates it (weekly by default, or Never: the clone is kept as it is and only updated on request). - Repos are saved in `repos/<tag>/<name>` (the Repos Directory, ignored by default) or a directory the user chooses. An existing clone can be imported where it is. repos.yaml is the source of truth. - A GitHub-like page shows each repo's README, files, and history, with a ZIP download. READMEs are searchable under the global search's Other tab. - git is hardened against hostile repos and configs: https only, pinned addresses with no private addresses (for the repo and its submodules), sanitized configs, no hooks or links, and only clones WROLPi made or imported are updated. - Tagging a Repo moves its clone as one directory. Repo changes wait for repos.yaml to be imported at startup. - The file mover groups unindexed files with no primary file as one FileGroup, and never replaces a file at the destination. A failed tag move restores the Collection's tag. A Collection's directory cannot leave the media directory. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1ded249fc7
commit
93d878952c
60 changed files with 7405 additions and 92 deletions
|
|
@ -1121,7 +1121,7 @@ describe('a row of buttons', () => {
|
|||
* the two had been inline before.
|
||||
*
|
||||
* A row fixes it without touching the stack: the row is the stretched child, and it lays
|
||||
* its buttons out at their own width. Nine sites, so this scan rather than nine
|
||||
* its buttons out at their own width. Thirteen sites, so this scan rather than thirteen
|
||||
* assertions -- and a scan because a stretched button is still a working button.
|
||||
*/
|
||||
const offenders = [];
|
||||
|
|
@ -1140,8 +1140,8 @@ describe('a row of buttons', () => {
|
|||
}
|
||||
}
|
||||
|
||||
// Nine renders. Common.js declares it, and a declaration is not a `<BackButton`.
|
||||
expect(found).toBe(9);
|
||||
// Thirteen renders. Common.js declares it, and a declaration is not a `<BackButton`.
|
||||
expect(found).toBe(13);
|
||||
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ const allLinks = [
|
|||
{text: 'Files', to: '/files', key: 'files'},
|
||||
{text: 'Playlists', to: '/playlists', key: 'playlists'},
|
||||
{text: 'Zim', to: '/zim', key: 'zim'},
|
||||
{text: 'Repos', to: '/repos', key: 'repos'},
|
||||
{text: 'Inventory', to: '/inventory', key: 'inventory'},
|
||||
// No `end` on these two: a tab stays current for the pages beneath it, and `end` would
|
||||
// drop the mark the moment either grows a sub-page.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import React from 'react';
|
||||
import {act, render, screen} from '../test-utils';
|
||||
import {OtherSearchView} from './Search';
|
||||
import {searchChannels} from '../api';
|
||||
import {searchChannels, searchRepos} from '../api';
|
||||
|
||||
// What the search page's Other tab shows for each state of useSearchChannels. "No Channels"
|
||||
// must only appear once the server has confirmed there are none.
|
||||
|
|
@ -9,11 +9,16 @@ import {searchChannels} from '../api';
|
|||
jest.mock('../api', () => ({
|
||||
...jest.requireActual('../api'),
|
||||
searchChannels: jest.fn(),
|
||||
searchRepos: jest.fn(),
|
||||
}));
|
||||
|
||||
const NO_CHANNELS = /No Channels/;
|
||||
|
||||
beforeEach(() => searchChannels.mockReset());
|
||||
beforeEach(() => {
|
||||
searchChannels.mockReset();
|
||||
searchRepos.mockReset();
|
||||
searchRepos.mockResolvedValue({repos: [], total: 0});
|
||||
});
|
||||
|
||||
test('pending: shows a loader, not "No Channels"', () => {
|
||||
searchChannels.mockReturnValue(new Promise(() => {
|
||||
|
|
@ -54,3 +59,61 @@ test('loaded: lists the channels', async () => {
|
|||
expect(screen.getByText('Cooking')).toBeInTheDocument();
|
||||
expect(screen.queryByText(NO_CHANNELS)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe('Repos', () => {
|
||||
test('pending: the Repos section loads while Channels are shown', async () => {
|
||||
searchChannels.mockResolvedValue({channels: []});
|
||||
searchRepos.mockReturnValue(new Promise(() => {
|
||||
}));
|
||||
const {container} = render(<OtherSearchView loading={false}/>);
|
||||
await act(async () => {
|
||||
});
|
||||
expect(screen.getByText(NO_CHANNELS)).toBeInTheDocument();
|
||||
expect(container.querySelector('.wrolpi-loading')).toBeInTheDocument();
|
||||
expect(screen.queryByText('No Repos')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('empty: shows "No Repos"', async () => {
|
||||
searchChannels.mockResolvedValue({channels: []});
|
||||
render(<OtherSearchView loading={false}/>);
|
||||
await act(async () => {
|
||||
});
|
||||
expect(screen.getByText('No Repos')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('failed: shows an error only in the Repos section', async () => {
|
||||
searchChannels.mockResolvedValue({channels: [{id: 1, name: 'Cooking'}]});
|
||||
searchRepos.mockRejectedValue(new Error('boom'));
|
||||
const spy = jest.spyOn(console, 'error').mockImplementation(() => {
|
||||
});
|
||||
try {
|
||||
render(<OtherSearchView loading={false}/>);
|
||||
await act(async () => {
|
||||
});
|
||||
expect(screen.getByText('Cooking')).toBeInTheDocument();
|
||||
expect(screen.getByText(/Could not fetch the repos/)).toBeInTheDocument();
|
||||
} finally {
|
||||
spy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
test('loaded: lists repos by the search, with their README headline', async () => {
|
||||
searchChannels.mockResolvedValue({channels: []});
|
||||
searchRepos.mockResolvedValue({
|
||||
total: 1, repos: [{
|
||||
id: 7, name: 'kiwix-tools', tag_name: null,
|
||||
// The server escapes the README; only the highlight is markup.
|
||||
readme_headline: 'Serve <b>Zim</b> files <script>',
|
||||
}],
|
||||
});
|
||||
const searchParams = new URLSearchParams('q=zim&tag=Software');
|
||||
const {container} = render(<OtherSearchView loading={false}/>, {query: {searchParams}});
|
||||
await act(async () => {
|
||||
});
|
||||
expect(searchRepos).toHaveBeenCalledWith('zim', ['Software']);
|
||||
expect(screen.getByText('kiwix-tools').closest('a')).toHaveAttribute('href', '/repos/7');
|
||||
expect(container.querySelector('u').textContent).toBe('Zim');
|
||||
expect(container.querySelector('script')).toBeNull();
|
||||
expect(screen.getByText(/files <script>/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
1062
app/src/components/Repos.js
Normal file
1062
app/src/components/Repos.js
Normal file
File diff suppressed because it is too large
Load diff
394
app/src/components/Repos.test.js
Normal file
394
app/src/components/Repos.test.js
Normal file
|
|
@ -0,0 +1,394 @@
|
|||
import React from 'react';
|
||||
import {Route, Routes} from 'react-router';
|
||||
import {act, fireEvent, render, screen, waitFor, within} from '../test-utils';
|
||||
import {
|
||||
RepoEditPage,
|
||||
RepoImportPage,
|
||||
repoNameFromURL,
|
||||
RepoNewPage,
|
||||
ReposPage,
|
||||
RepoViewPage,
|
||||
safeRepoHref,
|
||||
} from './Repos';
|
||||
import {
|
||||
createRepo, deleteRepo, fetchRepos, getFile, getRepo, getRepoLog, getRepoTree, importRepo, inspectRepoImport,
|
||||
updateRepo,
|
||||
} from '../api';
|
||||
import {FilePreviewContext} from './FilePreview';
|
||||
|
||||
jest.mock('../api', () => ({
|
||||
...jest.requireActual('../api'),
|
||||
createRepo: jest.fn(),
|
||||
deleteRepo: jest.fn(),
|
||||
fetchRepos: jest.fn(),
|
||||
getFile: jest.fn(),
|
||||
getRepo: jest.fn(),
|
||||
getRepoLog: jest.fn(),
|
||||
getRepoTree: jest.fn(),
|
||||
importRepo: jest.fn(),
|
||||
inspectRepoImport: jest.fn(),
|
||||
updateRepo: jest.fn(),
|
||||
}));
|
||||
|
||||
// The directory picker searches the server; picking a directory is all these specs need.
|
||||
jest.mock('./Common', () => ({
|
||||
...jest.requireActual('./Common'),
|
||||
DirectorySearch: ({onSelect}) => <button type='button' onClick={() => onSelect('code/kiwix-tools')}>
|
||||
Pick directory
|
||||
</button>,
|
||||
}));
|
||||
|
||||
// The README is fetched from the media server; its rendering is MarkdownPreview's own spec.
|
||||
jest.mock('./MarkdownPreview', () => ({
|
||||
...jest.requireActual('./MarkdownPreview'),
|
||||
MarkdownPreview: ({url}) => <div data-testid='markdown-preview'>{url}</div>,
|
||||
}));
|
||||
|
||||
const repoFixture = (overrides = {}) => ({
|
||||
id: 1, collection_id: 10, name: 'kiwix-tools', tag_name: null, description: null,
|
||||
url: 'https://github.com/kiwix/kiwix-tools', mode: 'full', branch: null, default_branch: 'main',
|
||||
head_sha: '3f9c2a1e7b', head_message: 'Fix the mimetype', head_date: '2026-09-30T14:02:00Z',
|
||||
size: 1000, directory: 'repos/kiwix-tools', frequency: 604800, download_error: null,
|
||||
...overrides,
|
||||
});
|
||||
|
||||
const treeFixture = {
|
||||
path: '',
|
||||
readme_path: 'README.md',
|
||||
entries: [
|
||||
{name: 'src', path: 'src', is_dir: true, size: null},
|
||||
{name: 'README.md', path: 'README.md', is_dir: false, size: 120},
|
||||
],
|
||||
};
|
||||
|
||||
const flush = () => act(async () => {
|
||||
});
|
||||
|
||||
beforeEach(() => jest.clearAllMocks());
|
||||
|
||||
describe('safeRepoHref', () => {
|
||||
it('only links https URLs', () => {
|
||||
expect(safeRepoHref('https://github.com/a/b')).toBe('https://github.com/a/b');
|
||||
expect(safeRepoHref('javascript:alert(1)')).toBeNull();
|
||||
expect(safeRepoHref('http://github.com/a/b')).toBeNull();
|
||||
expect(safeRepoHref('file:///etc/passwd')).toBeNull();
|
||||
expect(safeRepoHref('not a url')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('repoNameFromURL', () => {
|
||||
it('is the last path segment, without .git or a branch', () => {
|
||||
expect(repoNameFromURL('https://github.com/kiwix/kiwix-tools.git')).toBe('kiwix-tools');
|
||||
expect(repoNameFromURL('https://github.com/kiwix/kiwix-tools/tree/dev')).toBe('kiwix-tools');
|
||||
expect(repoNameFromURL('https://gitlab.com/group/sub/project/')).toBe('project');
|
||||
expect(repoNameFromURL('nope')).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ReposPage', () => {
|
||||
it('lists repos, linking each to its page', async () => {
|
||||
fetchRepos.mockResolvedValue([
|
||||
repoFixture(),
|
||||
repoFixture({id: 2, name: 'gone', download_error: 'git ls-remote failed', head_sha: null}),
|
||||
]);
|
||||
render(<ReposPage/>, {route: '/repos'});
|
||||
await flush();
|
||||
expect(screen.getAllByText('kiwix-tools')[0].closest('a')).toHaveAttribute('href', '/repos/1');
|
||||
expect(screen.getAllByText('gone')[0].closest('a')).toHaveAttribute('href', '/repos/2');
|
||||
expect(screen.getByText('New Repo').closest('a')).toHaveAttribute('href', '/repos/new');
|
||||
});
|
||||
|
||||
it('shows a repo which is never updated', async () => {
|
||||
fetchRepos.mockResolvedValue([repoFixture({frequency: 0})]);
|
||||
render(<ReposPage/>, {route: '/repos'});
|
||||
await flush();
|
||||
expect(screen.getAllByText('Never').length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('explains an empty list', async () => {
|
||||
fetchRepos.mockResolvedValue([]);
|
||||
render(<ReposPage/>, {route: '/repos'});
|
||||
await flush();
|
||||
expect(screen.getByText(/No repos yet/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
function renderViewPage({repo, tree = treeFixture, query = {}, setPreviewFile = jest.fn()} = {}) {
|
||||
getRepo.mockResolvedValue(repo);
|
||||
getRepoTree.mockResolvedValue(tree);
|
||||
return render(<Routes><Route path='/repos/:repoId' element={<RepoViewPage/>}/></Routes>, {
|
||||
route: '/repos/1',
|
||||
query,
|
||||
contexts: [[FilePreviewContext, {setPreviewFile}]],
|
||||
});
|
||||
}
|
||||
|
||||
describe('RepoViewPage', () => {
|
||||
it('shows the latest commit, the files, and the README', async () => {
|
||||
renderViewPage({repo: repoFixture()});
|
||||
await flush();
|
||||
expect(getRepoTree).toHaveBeenCalledWith('1', '');
|
||||
expect(screen.getByText('3f9c2a1')).toBeInTheDocument();
|
||||
expect(screen.getByText('Fix the mimetype')).toBeInTheDocument();
|
||||
expect(screen.getByText('main')).toBeInTheDocument();
|
||||
expect(screen.getByText('(default)')).toBeInTheDocument();
|
||||
expect(screen.getByText('https://github.com/kiwix/kiwix-tools').closest('a'))
|
||||
.toHaveAttribute('href', 'https://github.com/kiwix/kiwix-tools');
|
||||
expect(screen.getByText('src')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('markdown-preview')).toHaveTextContent('/media/repos/kiwix-tools/README.md');
|
||||
});
|
||||
|
||||
it('opens a directory through the URL, and a file in the preview', async () => {
|
||||
const updateQuery = jest.fn();
|
||||
const setPreviewFile = jest.fn();
|
||||
const file = {path: 'repos/kiwix-tools/README.md', mimetype: 'text/markdown', size: 120};
|
||||
getFile.mockResolvedValue(file);
|
||||
renderViewPage({repo: repoFixture(), query: {updateQuery}, setPreviewFile});
|
||||
await flush();
|
||||
|
||||
fireEvent.click(screen.getByText('src'));
|
||||
expect(updateQuery).toHaveBeenCalledWith({path: 'src'}, false);
|
||||
|
||||
fireEvent.click(screen.getAllByText('README.md')[0]);
|
||||
await flush();
|
||||
expect(getFile).toHaveBeenCalledWith('repos/kiwix-tools/README.md', true);
|
||||
expect(setPreviewFile).toHaveBeenCalledWith(file);
|
||||
});
|
||||
|
||||
it('lists the directory in the URL, with a way back up', async () => {
|
||||
const tree = {path: 'src/lib', readme_path: null, entries: [{name: 'a.c', path: 'src/lib/a.c', is_dir: false}]};
|
||||
const updateQuery = jest.fn();
|
||||
renderViewPage({repo: repoFixture(), tree, query: {searchParams: new URLSearchParams('path=src/lib'), updateQuery}});
|
||||
await flush();
|
||||
expect(getRepoTree).toHaveBeenCalledWith('1', 'src/lib');
|
||||
expect(screen.queryByTestId('markdown-preview')).not.toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByText('..'));
|
||||
expect(updateQuery).toHaveBeenCalledWith({path: 'src'}, false);
|
||||
// The breadcrumb's root.
|
||||
fireEvent.click(screen.getAllByText('kiwix-tools').find(i => i.tagName === 'BUTTON'));
|
||||
expect(updateQuery).toHaveBeenCalledWith({path: ''}, false);
|
||||
});
|
||||
|
||||
it('offers a ZIP of the files', async () => {
|
||||
renderViewPage({repo: repoFixture()});
|
||||
await flush();
|
||||
const link = screen.getByText('Download ZIP').closest('a');
|
||||
expect(link).toHaveAttribute('href', expect.stringMatching(/\/api\/repos\/1\/archive\.zip$/));
|
||||
expect(link).toHaveAttribute('download');
|
||||
});
|
||||
|
||||
it('shows the history instead of the files', async () => {
|
||||
getRepoLog.mockResolvedValue({
|
||||
total: 51,
|
||||
commits: [{sha: 'abcdef1234', author: 'Ada', date: '2026-09-30T14:02:00Z', message: 'Fix the mimetype'}],
|
||||
});
|
||||
const updateQuery = jest.fn();
|
||||
renderViewPage({repo: repoFixture(), query: {searchParams: new URLSearchParams('view=history'), updateQuery}});
|
||||
await flush();
|
||||
|
||||
expect(getRepoLog).toHaveBeenCalledWith(1, 0, 50);
|
||||
expect(getRepoTree).not.toHaveBeenCalled();
|
||||
expect(screen.getByText('51 commits')).toBeInTheDocument();
|
||||
expect(screen.getByText('abcdef1')).toBeInTheDocument();
|
||||
expect(screen.getByText('Ada')).toBeInTheDocument();
|
||||
|
||||
// The next page is appended.
|
||||
getRepoLog.mockResolvedValue({
|
||||
total: 51,
|
||||
commits: [{sha: '0123456789', author: 'Ben', date: '2026-09-01T00:00:00Z', message: 'Older'}],
|
||||
});
|
||||
fireEvent.click(screen.getByText('Load more'));
|
||||
await flush();
|
||||
expect(getRepoLog).toHaveBeenLastCalledWith(1, 1, 50);
|
||||
expect(screen.getByText('abcdef1')).toBeInTheDocument();
|
||||
expect(screen.getByText('0123456')).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByText('Files'));
|
||||
expect(updateQuery).toHaveBeenCalledWith({view: null}, false);
|
||||
});
|
||||
|
||||
it('explains a repo that is not downloaded yet', async () => {
|
||||
renderViewPage({repo: repoFixture({head_sha: null, head_message: null, head_date: null})});
|
||||
await flush();
|
||||
expect(screen.getByText('Not downloaded yet')).toBeInTheDocument();
|
||||
expect(getRepoTree).not.toHaveBeenCalled();
|
||||
expect(screen.queryByText('Download ZIP')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('History')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('keeps showing the files when the last update failed', async () => {
|
||||
renderViewPage({repo: repoFixture({download_error: 'Traceback...\nDownloadError: git ls-remote failed (128)'})});
|
||||
await flush();
|
||||
expect(screen.getByText('The last update failed')).toBeInTheDocument();
|
||||
expect(screen.getByText(/git ls-remote failed/)).toBeInTheDocument();
|
||||
expect(screen.getByText('src')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('says a repo which is never updated is only updated on request', async () => {
|
||||
renderViewPage({repo: repoFixture({frequency: 0, download_error: 'git ls-remote failed (128)'})});
|
||||
await flush();
|
||||
expect(screen.getByText('The last update failed')).toBeInTheDocument();
|
||||
expect(screen.getByText(/never updated automatically/)).toBeInTheDocument();
|
||||
expect(screen.queryByText(/will be tried again/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('never links an upstream that is not https', async () => {
|
||||
renderViewPage({repo: repoFixture({url: 'javascript:alert(1)'})});
|
||||
await flush();
|
||||
expect(screen.queryByText('javascript:alert(1)')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('RepoNewPage', () => {
|
||||
it('adds a repo, then opens it', async () => {
|
||||
createRepo.mockResolvedValue(repoFixture({id: 5}));
|
||||
render(<Routes>
|
||||
<Route path='/repos/new' element={<RepoNewPage/>}/>
|
||||
<Route path='/repos/:repoId' element={<div>repo page</div>}/>
|
||||
</Routes>, {route: '/repos/new'});
|
||||
|
||||
const add = screen.getByText('Add Repo').closest('button');
|
||||
expect(add).toBeDisabled();
|
||||
fireEvent.change(screen.getByLabelText(/URL/), {target: {value: 'git@github.com:a/b'}});
|
||||
expect(add).toBeDisabled();
|
||||
expect(screen.getByText('Must be an https:// URL')).toBeInTheDocument();
|
||||
|
||||
fireEvent.change(screen.getByLabelText(/URL/), {target: {value: 'https://github.com/kiwix/kiwix-tools'}});
|
||||
expect(screen.getByPlaceholderText('kiwix-tools')).toBeInTheDocument();
|
||||
fireEvent.change(screen.getByLabelText('Branch'), {target: {value: ' dev '}});
|
||||
fireEvent.click(screen.getByText('Pick directory'));
|
||||
fireEvent.click(add);
|
||||
await flush();
|
||||
|
||||
expect(createRepo).toHaveBeenCalledWith({
|
||||
url: 'https://github.com/kiwix/kiwix-tools', name: null, tag_name: null, frequency: 604800,
|
||||
mode: 'full', branch: 'dev', submodules: false, description: null, directory: 'code/kiwix-tools',
|
||||
});
|
||||
expect(screen.getByText('repo page')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('RepoEditPage', () => {
|
||||
function renderEditPage(repo) {
|
||||
getRepo.mockResolvedValue(repo);
|
||||
return render(<Routes>
|
||||
<Route path='/repos/:repoId/edit' element={<RepoEditPage/>}/>
|
||||
<Route path='/repos' element={<div>repos page</div>}/>
|
||||
</Routes>, {route: '/repos/1/edit'});
|
||||
}
|
||||
|
||||
it('saves the settings', async () => {
|
||||
updateRepo.mockResolvedValue(repoFixture());
|
||||
renderEditPage(repoFixture({branch: 'dev', description: 'Tools'}));
|
||||
await flush();
|
||||
expect(screen.getByLabelText('Branch')).toHaveValue('dev');
|
||||
|
||||
expect(screen.getByLabelText('Include submodules')).not.toBeChecked();
|
||||
|
||||
fireEvent.change(screen.getByLabelText('Branch'), {target: {value: ''}});
|
||||
fireEvent.click(screen.getByLabelText('Include submodules'));
|
||||
fireEvent.click(screen.getByText('Save'));
|
||||
await flush();
|
||||
expect(updateRepo).toHaveBeenCalledWith('1', {
|
||||
description: 'Tools', frequency: 604800, mode: 'full', branch: '', submodules: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps a repo which is never updated', async () => {
|
||||
updateRepo.mockResolvedValue(repoFixture({frequency: 0}));
|
||||
renderEditPage(repoFixture({frequency: 0}));
|
||||
await flush();
|
||||
expect(screen.getByDisplayValue('Never')).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByText('Save'));
|
||||
await flush();
|
||||
expect(updateRepo).toHaveBeenCalledWith('1', expect.objectContaining({frequency: 0}));
|
||||
});
|
||||
|
||||
it('deletes the repo, and its files only when asked', async () => {
|
||||
deleteRepo.mockResolvedValue(undefined);
|
||||
renderEditPage(repoFixture());
|
||||
await flush();
|
||||
|
||||
fireEvent.click(screen.getByText('Delete'));
|
||||
const dialog = await screen.findByRole('dialog');
|
||||
fireEvent.click(within(dialog).getByLabelText(/Also delete its files/));
|
||||
fireEvent.click(within(dialog).getByText('Delete'));
|
||||
await flush();
|
||||
expect(deleteRepo).toHaveBeenCalledWith('1', true);
|
||||
expect(screen.getByText('repos page')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('RepoImportPage', () => {
|
||||
const inspection = (overrides = {}) => ({
|
||||
directory: 'code/kiwix-tools', origin: 'git@github.com:kiwix/kiwix-tools.git',
|
||||
url: 'https://github.com/kiwix/kiwix-tools', name: 'kiwix-tools', branch: 'main',
|
||||
head_sha: 'abcdef1234', head_message: 'Local work', head_date: '2026-09-30T14:02:00Z', local_commits: 2,
|
||||
shallow: false, ignored: false,
|
||||
...overrides,
|
||||
});
|
||||
|
||||
function renderImportPage() {
|
||||
return render(<Routes>
|
||||
<Route path='/repos/import' element={<RepoImportPage/>}/>
|
||||
<Route path='/repos/:repoId' element={<div>repo page</div>}/>
|
||||
</Routes>, {route: '/repos/import'});
|
||||
}
|
||||
|
||||
it('inspects the directory, warns about local commits, and imports once confirmed', async () => {
|
||||
inspectRepoImport.mockResolvedValue({inspection: inspection()});
|
||||
importRepo.mockResolvedValue(repoFixture({id: 9}));
|
||||
renderImportPage();
|
||||
|
||||
fireEvent.click(screen.getByText('Pick directory'));
|
||||
expect(await screen.findByText('2 commits are not on the remote')).toBeInTheDocument();
|
||||
expect(inspectRepoImport).toHaveBeenCalledWith('code/kiwix-tools', '', null, '');
|
||||
// Inspected again with the URL the import will use.
|
||||
await waitFor(() => expect(inspectRepoImport).toHaveBeenCalledWith('code/kiwix-tools', '', null,
|
||||
'https://github.com/kiwix/kiwix-tools'));
|
||||
expect(screen.getByText('git@github.com:kiwix/kiwix-tools.git')).toBeInTheDocument();
|
||||
expect(screen.getByText(/Its files are indexed/)).toBeInTheDocument();
|
||||
// The URL comes from the origin.
|
||||
expect(screen.getByLabelText(/^URL/)).toHaveValue('https://github.com/kiwix/kiwix-tools');
|
||||
|
||||
const button = screen.getByText('Import').closest('button');
|
||||
expect(button).toBeDisabled();
|
||||
fireEvent.click(screen.getByLabelText(/I understand/));
|
||||
expect(button).toBeEnabled();
|
||||
fireEvent.click(button);
|
||||
await flush();
|
||||
|
||||
expect(importRepo).toHaveBeenCalledWith({
|
||||
directory: 'code/kiwix-tools', confirm: true, url: 'https://github.com/kiwix/kiwix-tools', name: null,
|
||||
tag_name: null, frequency: 604800, mode: 'full', branch: null, submodules: false,
|
||||
});
|
||||
expect(screen.getByText('repo page')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('asks for the URL when the clone has no https origin', async () => {
|
||||
inspectRepoImport.mockResolvedValue({inspection: inspection({origin: null, url: null, local_commits: 0})});
|
||||
renderImportPage();
|
||||
fireEvent.click(screen.getByText('Pick directory'));
|
||||
expect(await screen.findByText(/no https:\/\/ origin/)).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByLabelText(/I understand/));
|
||||
expect(screen.getByText('Import').closest('button')).toBeDisabled();
|
||||
fireEvent.change(screen.getByLabelText(/^URL/), {target: {value: 'https://github.com/kiwix/kiwix-tools'}});
|
||||
expect(screen.getByText('Import').closest('button')).toBeEnabled();
|
||||
});
|
||||
|
||||
it('explains a directory which cannot be imported', async () => {
|
||||
inspectRepoImport.mockResolvedValue({error: 'code/kiwix-tools is not a git clone'});
|
||||
renderImportPage();
|
||||
fireEvent.click(screen.getByText('Pick directory'));
|
||||
expect(await screen.findByText('code/kiwix-tools is not a git clone')).toBeInTheDocument();
|
||||
expect(screen.queryByText('Import')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('says when the files are not indexed', async () => {
|
||||
inspectRepoImport.mockResolvedValue({inspection: inspection({ignored: true})});
|
||||
renderImportPage();
|
||||
fireEvent.click(screen.getByText('Pick directory'));
|
||||
expect(await screen.findByText(/Its files are not indexed/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
@ -1,7 +1,15 @@
|
|||
import React, {useState} from "react";
|
||||
import {Link, Route, Routes, useLocation, useNavigate} from "react-router";
|
||||
import {FilesSearchView, SearchViewButton} from "./Files";
|
||||
import {useLatestRequest, usePages, useSearchChannels, useSearchDate, useSearchDeep, useSearchFilter} from "../hooks/customHooks";
|
||||
import {
|
||||
useLatestRequest,
|
||||
usePages,
|
||||
useSearchChannels,
|
||||
useSearchDate,
|
||||
useSearchDeep,
|
||||
useSearchFilter,
|
||||
useSearchRepos,
|
||||
} from "../hooks/customHooks";
|
||||
import {ShortcutHint} from "./ShortcutHint";
|
||||
import {ZimSearchView} from "./Zim";
|
||||
import {MapSearchView} from "./MapSearchView";
|
||||
|
|
@ -12,6 +20,7 @@ import {TagsContext} from "../Tags";
|
|||
import {Accordion, Header, Icon, Label, Loading, Panel, Stack} from "./ui";
|
||||
import {QueryContext} from "../contexts/contexts";
|
||||
import {KeyboardShortcutsContext} from "../contexts/KeyboardShortcutsContext";
|
||||
import {HeadlineText} from "./Headline";
|
||||
|
||||
const SUGGESTED_APPS = [
|
||||
{location: '/admin', title: 'Downloads', description: 'View and control your downloads'},
|
||||
|
|
@ -139,6 +148,7 @@ export function useSuggestions(searchStr, tagNames, filter, anyTag) {
|
|||
domains: null,
|
||||
authors: null,
|
||||
subjects: null,
|
||||
repos: null,
|
||||
zimsEstimates: [],
|
||||
}
|
||||
const [suggestions, setSuggestions] = React.useState(defaultSuggestions);
|
||||
|
|
@ -163,7 +173,7 @@ export function useSuggestions(searchStr, tagNames, filter, anyTag) {
|
|||
// The files estimate always uses deep search server-side, so users know results are possible.
|
||||
sendFilesRequest(async () => await searchEstimateFiles(searchStr, tagNames, mimetypes, months, dateRange, anyTag));
|
||||
sendZimRequest(async () => await searchEstimateZims(searchStr, tagNames));
|
||||
sendOtherRequest(async () => await searchEstimateOthers(tagNames));
|
||||
sendOtherRequest(async () => await searchEstimateOthers(tagNames, searchStr));
|
||||
}
|
||||
}, [
|
||||
searchStr,
|
||||
|
|
@ -185,6 +195,7 @@ export function useSuggestions(searchStr, tagNames, filter, anyTag) {
|
|||
domains: generalData.domains,
|
||||
authors: generalData.authors,
|
||||
subjects: generalData.subjects,
|
||||
repos: generalData.repos,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -312,6 +323,13 @@ export function useSearchSuggestions(defaultSearchStr, defaultTagNames, anyTag)
|
|||
})
|
||||
}
|
||||
}
|
||||
if (newSuggestions.repos && newSuggestions.repos.length > 0) {
|
||||
results.repos = {
|
||||
name: 'Repos', results: newSuggestions.repos.map(i => {
|
||||
return {type: 'repo', title: i.name, id: i.id, location: `/repos/${i.id}`}
|
||||
})
|
||||
}
|
||||
}
|
||||
if (newSuggestions.authors && newSuggestions.authors.length > 0) {
|
||||
results.authors = {
|
||||
name: 'Authors', results: newSuggestions.authors.map(i => {
|
||||
|
|
@ -407,6 +425,7 @@ export function useSearchSuggestions(defaultSearchStr, defaultTagNames, anyTag)
|
|||
domains: newSuggestions.domains?.length,
|
||||
authors: newSuggestions.authors?.length,
|
||||
subjects: newSuggestions.subjects?.length,
|
||||
repos: newSuggestions.repos?.length,
|
||||
tags: matchingTags?.length,
|
||||
apps: matchingApps?.length,
|
||||
});
|
||||
|
|
@ -543,12 +562,47 @@ function SearchChannelPreview({channel}) {
|
|||
</div>
|
||||
}
|
||||
|
||||
// `channels` follows useSearchChannels: null = pending, undefined = fetch failed, [] = none.
|
||||
function SearchRepoPreview({repo}) {
|
||||
const {SingleTag} = React.useContext(TagsContext);
|
||||
return <div>
|
||||
<span style={{display: 'inline-flex', alignItems: 'center', gap: 8, flexWrap: 'wrap'}}>
|
||||
<Link to={`/repos/${repo.id}`}>{repo.name}</Link>
|
||||
{repo.tag_name && <SingleTag name={repo.tag_name}/>}
|
||||
</span>
|
||||
{/* The server escapes the README; only its <b> highlights are markup. */}
|
||||
{repo.readme_headline && <div><small><HeadlineText headline={repo.readme_headline}/></small></div>}
|
||||
</div>
|
||||
}
|
||||
|
||||
function OtherSearchSection({value, title, items, preview, emptyText, errorText}) {
|
||||
let body;
|
||||
if (items === null) {
|
||||
body = <Loading/>;
|
||||
} else if (items === undefined) {
|
||||
body = <ErrorMessage>{errorText}</ErrorMessage>;
|
||||
} else {
|
||||
body = <Stack gap='xs'>{!_.isEmpty(items) ? items.map(preview) : emptyText}</Stack>;
|
||||
}
|
||||
return <Accordion.Item value={value}>
|
||||
<Accordion.Control>
|
||||
<span style={{display: 'inline-flex', alignItems: 'center', gap: 8}}>
|
||||
<Header as='h3' style={{margin: 0}}>{title}</Header>
|
||||
{Array.isArray(items) && <Label>{normalizeEstimate(items.length)}</Label>}
|
||||
</span>
|
||||
</Accordion.Control>
|
||||
<Accordion.Panel>{body}</Accordion.Panel>
|
||||
</Accordion.Item>
|
||||
}
|
||||
|
||||
// `channels` follows useSearchChannels and `repos` follows useSearchRepos: null = pending,
|
||||
// undefined = fetch failed, [] = none.
|
||||
export function OtherSearchView({loading}) {
|
||||
const {searchParams} = React.useContext(QueryContext);
|
||||
const [activeValue, setActiveValue] = React.useState('channels');
|
||||
const [activeValues, setActiveValues] = React.useState(['channels', 'repos']);
|
||||
const activeTags = searchParams.getAll('tag');
|
||||
const searchStr = searchParams.get('q') || '';
|
||||
const {channels, loading: channelsLoading} = useSearchChannels(activeTags);
|
||||
const {repos} = useSearchRepos(searchStr, activeTags);
|
||||
|
||||
if (loading || channelsLoading || channels === null) {
|
||||
return <Panel><Loading/></Panel>
|
||||
|
|
@ -556,21 +610,22 @@ export function OtherSearchView({loading}) {
|
|||
return <Panel><ErrorMessage>Could not fetch the channels.</ErrorMessage></Panel>
|
||||
}
|
||||
|
||||
return <Accordion value={activeValue} onChange={setActiveValue}>
|
||||
<Accordion.Item value='channels'>
|
||||
<Accordion.Control>
|
||||
<span style={{display: 'inline-flex', alignItems: 'center', gap: 8}}>
|
||||
<Header as='h3' style={{margin: 0}}>Channels</Header>
|
||||
<Label>{normalizeEstimate(channels.length)}</Label>
|
||||
</span>
|
||||
</Accordion.Control>
|
||||
<Accordion.Panel>
|
||||
<Stack gap='xs'>
|
||||
{!_.isEmpty(channels) ?
|
||||
channels.map(i => <SearchChannelPreview key={i.id} channel={i}/>)
|
||||
: 'No Channels'}
|
||||
</Stack>
|
||||
</Accordion.Panel>
|
||||
</Accordion.Item>
|
||||
return <Accordion multiple value={activeValues} onChange={setActiveValues}>
|
||||
<OtherSearchSection
|
||||
value='channels'
|
||||
title='Channels'
|
||||
items={channels}
|
||||
preview={i => <SearchChannelPreview key={i.id} channel={i}/>}
|
||||
emptyText='No Channels'
|
||||
errorText='Could not fetch the channels.'
|
||||
/>
|
||||
<OtherSearchSection
|
||||
value='repos'
|
||||
title='Repos'
|
||||
items={repos}
|
||||
preview={i => <SearchRepoPreview key={i.id} repo={i}/>}
|
||||
emptyText='No Repos'
|
||||
errorText='Could not fetch the repos.'
|
||||
/>
|
||||
</Accordion>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,3 +103,37 @@ test('Channels rows once the server found some', async () => {
|
|||
});
|
||||
expect(results().channels.results.map(i => i.title)).toEqual(['Food']);
|
||||
});
|
||||
|
||||
test('Repos rows link to each repo, and the Other estimate gets the search', async () => {
|
||||
let resolve;
|
||||
searchSuggestions.mockReturnValue(new Promise(res => resolve = res));
|
||||
renderProbe();
|
||||
act(() => {
|
||||
hook.setSearchStr('kiwix');
|
||||
});
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(DEBOUNCE);
|
||||
});
|
||||
await act(async () => {
|
||||
resolve({channels: [], domains: [], authors: [], subjects: [], repos: [{id: 4, name: 'kiwix-tools'}]});
|
||||
});
|
||||
expect(results().repos.results).toEqual([{type: 'repo', title: 'kiwix-tools', id: 4, location: '/repos/4'}]);
|
||||
// Repos count toward the Other tab by their name and README, not only by tag.
|
||||
expect(searchEstimateOthers).toHaveBeenCalledWith([], 'kiwix');
|
||||
});
|
||||
|
||||
test('no Repos group when none match', async () => {
|
||||
let resolve;
|
||||
searchSuggestions.mockReturnValue(new Promise(res => resolve = res));
|
||||
renderProbe();
|
||||
act(() => {
|
||||
hook.setSearchStr('foo');
|
||||
});
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(DEBOUNCE);
|
||||
});
|
||||
await act(async () => {
|
||||
resolve({channels: [], domains: [], authors: [], subjects: [], repos: []});
|
||||
});
|
||||
expect(results().repos).toBeUndefined();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ import {contrastingColor} from './Common';
|
|||
import {navBarStyle, navColorNames, useNavColors} from '../themes/navColors';
|
||||
import {IconMenu2} from '@tabler/icons-react';
|
||||
import {BookmarkAddForms, BookmarkMenuItems, BookmarkTable} from './Bookmarks';
|
||||
import {
|
||||
RepoBreadcrumb, RepoHistoryTable, RepoImportSummary, RepoStatusIcon, RepoSummary, RepoTreeTable,
|
||||
} from './Repos';
|
||||
|
||||
/*
|
||||
* A gallery of every component in the library, in the current theme.
|
||||
|
|
@ -170,6 +173,28 @@ const sampleBookmarks = [
|
|||
];
|
||||
const noBookmarkActions = {edit: () => null, move: () => null, remove: () => null};
|
||||
|
||||
const sampleRepo = {
|
||||
id: 1, name: 'kiwix-tools', tag_name: null, url: 'https://github.com/kiwix/kiwix-tools',
|
||||
description: 'Command line tools for Kiwix and Zim files.', mode: 'full', branch: null, default_branch: 'main',
|
||||
head_sha: '3f9c2a1e7b', head_message: 'Serve Zim files with the correct mimetype', head_date: '2026-09-30T14:02:00Z',
|
||||
size: 18_400_000, directory: 'repos/kiwix-tools', download_error: null,
|
||||
};
|
||||
const sampleFailedRepo = {
|
||||
...sampleRepo, name: 'gone-upstream', branch: 'release', mode: 'snapshot',
|
||||
download_error: "git ls-remote failed (128): remote: Repository not found.\nfatal: repository " +
|
||||
"'https://github.com/example/gone-upstream/' not found",
|
||||
};
|
||||
const sampleRepoCommits = [
|
||||
{sha: '3f9c2a1e7b', author: 'Ada Example', date: '2026-09-30T14:02:00Z',
|
||||
message: 'Serve Zim files with the correct mimetype'},
|
||||
{sha: '91b0d44c02', author: 'Ben Example', date: '2026-09-12T09:15:00Z', message: 'Merge pull request #42'},
|
||||
];
|
||||
const sampleRepoEntries = [
|
||||
{name: 'docs', path: 'src/docs', is_dir: true, size: null},
|
||||
{name: 'kiwix-serve.cpp', path: 'src/kiwix-serve.cpp', is_dir: false, size: 48_210},
|
||||
{name: 'README.md', path: 'src/README.md', is_dir: false, size: 2_104},
|
||||
];
|
||||
|
||||
export function ThemeSamplePage() {
|
||||
const {theme, mediaFilterEnabled} = useContext(ThemeContext);
|
||||
const [confirmOpen, setConfirmOpen] = useState(false);
|
||||
|
|
@ -1127,6 +1152,36 @@ export function ThemeSamplePage() {
|
|||
</Panel>
|
||||
</Section>
|
||||
|
||||
<Section label='Repos'>
|
||||
<Panel>
|
||||
<p style={{fontSize: '0.75rem', color: 'var(--muted)', marginTop: 0}}>
|
||||
A git repo's page: its summary, then its files. A repo whose last update failed keeps
|
||||
its files and explains why. The status icons appear beside a repo's name in the Repos
|
||||
table: <RepoStatusIcon repo={sampleFailedRepo}/> failed,{' '}
|
||||
<RepoStatusIcon repo={{...sampleRepo, head_sha: null}}/> not downloaded yet.
|
||||
</p>
|
||||
<RepoSummary repo={sampleRepo}/>
|
||||
<div style={{marginTop: 12}}>
|
||||
<RepoBreadcrumb name={sampleRepo.name} path='src' onNavigate={() => null}/>
|
||||
<RepoTreeTable path='src' entries={sampleRepoEntries} onOpenDirectory={() => null}
|
||||
onOpenFile={() => null}/>
|
||||
</div>
|
||||
<div style={{marginTop: 12}}>
|
||||
<RepoHistoryTable commits={sampleRepoCommits}/>
|
||||
</div>
|
||||
<div style={{marginTop: 12}}>
|
||||
<RepoImportSummary inspection={{
|
||||
origin: 'git@github.com:kiwix/kiwix-tools.git', branch: 'main', head_sha: '3f9c2a1e7b',
|
||||
head_message: 'Local work', head_date: '2026-09-30T14:02:00Z', local_commits: 2,
|
||||
shallow: true, directory: 'code/kiwix-tools', ignored: false,
|
||||
}}/>
|
||||
</div>
|
||||
<div style={{marginTop: 12}}>
|
||||
<RepoSummary repo={sampleFailedRepo}/>
|
||||
</div>
|
||||
</Panel>
|
||||
</Section>
|
||||
|
||||
<Section label='Danger zone'>
|
||||
<Panel danger>
|
||||
<h2 style={{color: 'var(--danger)', fontSize: '0.875rem', margin: '0 0 4px'}}>Danger zone</h2>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ export const VIDEOS_API = `${API_URI}/videos`;
|
|||
export const ARCHIVES_API = `${API_URI}/archive`;
|
||||
export const COLLECTIONS_API = `${API_URI}/collections`;
|
||||
export const ZIM_API = `${API_URI}/zim`;
|
||||
export const REPOS_API = `${API_URI}/repos`;
|
||||
export const DEFAULT_LIMIT = 20;
|
||||
export const NAME = process.env && process.env.REACT_APP_NAME ? process.env.REACT_APP_NAME : null;
|
||||
|
||||
|
|
|
|||
|
|
@ -499,6 +499,7 @@ export function SettingsPage() {
|
|||
videos_destination: settings.videos_destination,
|
||||
zims_destination: settings.zims_destination,
|
||||
playlists_destination: settings.playlists_destination,
|
||||
repos_destination: settings.repos_destination,
|
||||
save_ffprobe_json: settings.save_ffprobe_json,
|
||||
});
|
||||
}, [JSON.stringify(settings), settingsLoaded, settingsFailed]);
|
||||
|
|
@ -849,6 +850,32 @@ export function SettingsPage() {
|
|||
onChange={e => handleInputChange('playlists_destination', e.currentTarget.value)}
|
||||
/>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={{base: 12, sm: 6}}>
|
||||
<PathInput
|
||||
label={<>
|
||||
Repos Directory
|
||||
<InfoPopup
|
||||
content={<>
|
||||
<p>Variables:</p>
|
||||
<ul>
|
||||
<li><code>%(repo_name)s</code> - Repo name</li>
|
||||
<li><code>%(repo_tag)s</code> - Tag name for the repo (empty if no tag)
|
||||
</li>
|
||||
<li><code>%(repo_owner)s</code> - Owner from the repo URL</li>
|
||||
<li><code>%(repo_host)s</code> - Host from the repo URL</li>
|
||||
</ul>
|
||||
<p>Must start with a fixed directory (like <code>repos/</code>), which
|
||||
is never indexed, and contain <code>%(repo_name)s</code>.</p>
|
||||
</>}
|
||||
position='top'
|
||||
/>
|
||||
</>}
|
||||
prefix={mediaDirectoryLabel}
|
||||
value={state.repos_destination}
|
||||
disabled={!editSpecialDirectories}
|
||||
onChange={e => handleInputChange('repos_destination', e.currentTarget.value)}
|
||||
/>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={12}>
|
||||
<Toggle
|
||||
label='Edit Directories'
|
||||
|
|
|
|||
|
|
@ -77,7 +77,9 @@ function renderRow(collection, columns, routes, SingleTag, onRowClick) {
|
|||
}
|
||||
|
||||
// Format the value based on column configuration
|
||||
if (col.format === 'bytes') {
|
||||
if (col.render) {
|
||||
value = col.render(collection);
|
||||
} else if (col.format === 'bytes') {
|
||||
value = humanFileSize(value);
|
||||
} else if (col.format === 'frequency') {
|
||||
value = formatFrequency(value);
|
||||
|
|
@ -134,7 +136,9 @@ function MobileCollectionRow({collection, mobileColumns, routes}) {
|
|||
.filter(col => col.type !== 'actions' && col.key !== primaryColumn.key && col.key !== 'tag_name')
|
||||
.map(col => {
|
||||
let value = collection[col.key];
|
||||
if (col.format === 'bytes') {
|
||||
if (col.render) {
|
||||
value = col.render(collection);
|
||||
} else if (col.format === 'bytes') {
|
||||
value = humanFileSize(value);
|
||||
} else if (col.format === 'frequency') {
|
||||
value = formatFrequency(value);
|
||||
|
|
@ -157,7 +161,8 @@ function MobileCollectionRow({collection, mobileColumns, routes}) {
|
|||
* Reusable table component for displaying collections (Domains, Channels, etc).
|
||||
*
|
||||
* @param {Array} collections - Array of collection objects
|
||||
* @param {Array} columns - Column configurations for the table
|
||||
* @param {Array} columns - Column configurations for the table. A column's optional `render(collection)` displays
|
||||
* the cell; the column still sorts by `collection[key]`.
|
||||
* @param {Object} routes - Routes configuration for navigation (edit, search, etc.)
|
||||
* @param {String} searchStr - Search filter string (managed by parent)
|
||||
* @param {Function} onRowClick - Optional callback when a row is clicked
|
||||
|
|
|
|||
|
|
@ -68,6 +68,27 @@ const DOMAIN_ROUTES = {
|
|||
describe('CollectionTable', () => {
|
||||
const mockCollections = createMockDomains(3);
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Loading and Error States', () => {
|
||||
it('renders loading placeholder when collections is null', () => {
|
||||
const {container} = render(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue