release / web (push) Failing after 1m28s
release / go (push) Successful in 1m53s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 4m16s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 2m13s
release / android (push) Canceled after 2m59s
Reports offers "Remove the file" ahead of "Remove from library": the bad file goes and the track waits in Needs a file, with its likes and plays, for a good copy. Suspect sources gets "Remove this file", and the Duplicates wrong-slot action and its route are named for what they do (remove-files). Their toasts and copy name Needs a file. Missing files becomes Needs a file in the rail, the Collection header and the Overview counts. Each track says why it waits and who removed it, and can be forgotten one at a time or by folder; the list exports as a CSV or copies to the clipboard. The empty state says how a track gets there and how it leaves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
162 lines
5.8 KiB
TypeScript
162 lines
5.8 KiB
TypeScript
import { afterEach, describe, expect, test, vi } from 'vitest';
|
|
import { fireEvent, render, screen } from '@testing-library/svelte';
|
|
import { readable } from 'svelte/store';
|
|
import type { AdminSuspectResponse, AdminSuspectTrack } from '#lib/api/types.js';
|
|
|
|
vi.mock('#lib/api/admin.js', () => ({
|
|
createSuspectSourcesQuery: vi.fn(),
|
|
setSuspectVerdict: vi.fn(async () => {}),
|
|
removeSuspectFile: vi.fn(async () => {})
|
|
}));
|
|
|
|
import SuspectSourcesPage from './+page.svelte';
|
|
import { createSuspectSourcesQuery, removeSuspectFile, setSuspectVerdict } from '#lib/api/admin.js';
|
|
|
|
const mocked = createSuspectSourcesQuery as ReturnType<typeof vi.fn>;
|
|
|
|
const HUMANZ = '/music/Gorillaz/Humanz (2017)';
|
|
|
|
function track(title: string, file: string, markers: string[], disc: number | null = 15): AdminSuspectTrack {
|
|
return {
|
|
track_id: `t-${title}`,
|
|
title,
|
|
artist_id: 'ar-1',
|
|
artist_name: 'Gorillaz',
|
|
album_id: 'al-1',
|
|
album_title: 'Humanz',
|
|
file_path: `${HUMANZ}/${file}`,
|
|
duration_sec: 180,
|
|
disc_number: disc,
|
|
track_number: 4,
|
|
markers,
|
|
verdict: 'suspect',
|
|
verdict_at: new Date(Date.now() - 3_600_000).toISOString(),
|
|
};
|
|
}
|
|
|
|
function page(offset: number, total: number, groups: AdminSuspectResponse['groups']): AdminSuspectResponse {
|
|
return { total, limit: 50, offset, groups };
|
|
}
|
|
|
|
// The page reads only these fields of the infinite query.
|
|
function infinite(pages: AdminSuspectResponse[], opts: { hasNextPage?: boolean; isPending?: boolean } = {}) {
|
|
return readable({
|
|
data: { pages },
|
|
isPending: opts.isPending ?? false,
|
|
isError: false,
|
|
hasNextPage: opts.hasNextPage ?? false,
|
|
isFetchingNextPage: false,
|
|
fetchNextPage: () => {},
|
|
refetch: () => {}
|
|
});
|
|
}
|
|
|
|
afterEach(() => vi.clearAllMocks());
|
|
|
|
describe('Suspect sources page', () => {
|
|
test('shows each flagged track with its file name and markers', () => {
|
|
mocked.mockReturnValue(
|
|
infinite([
|
|
page(0, 2, [
|
|
{
|
|
directory: HUMANZ,
|
|
tracks: [
|
|
track('Strobelite', 'Gorillaz - Strobelite (Official Video).mp3', ['music video']),
|
|
track('Andromeda', 'Gorillaz - Andromeda [Audio] [HQ].mp3', ['[Audio]', '[HD]'])
|
|
]
|
|
}
|
|
])
|
|
])
|
|
);
|
|
render(SuspectSourcesPage);
|
|
|
|
expect(screen.getByTestId('suspect-count-pill')).toHaveTextContent('2');
|
|
expect(screen.getByText(HUMANZ)).toBeInTheDocument();
|
|
expect(screen.getByText('Gorillaz - Strobelite (Official Video).mp3')).toBeInTheDocument();
|
|
expect(screen.getAllByTestId('suspect-marker').map((m) => m.textContent)).toEqual([
|
|
'music video',
|
|
'[Audio]',
|
|
'[HD]'
|
|
]);
|
|
expect(screen.getAllByText(/disc 15, track 4/)).toHaveLength(2);
|
|
});
|
|
|
|
// A folder split across two pages is still one folder on screen.
|
|
test('joins a folder that straddles a page boundary', () => {
|
|
mocked.mockReturnValue(
|
|
infinite([
|
|
page(0, 3, [{ directory: HUMANZ, tracks: [track('Strobelite', 'a (Official Video).mp3', ['music video'])] }]),
|
|
page(1, 3, [
|
|
{ directory: HUMANZ, tracks: [track('Momentz', 'b (Visualizer).mp3', ['visualiser'])] },
|
|
{ directory: '/music/Daft Punk/RAM', tracks: [track('Doin It Right', 'c (Music Video).mp3', ['music video'])] }
|
|
])
|
|
])
|
|
);
|
|
render(SuspectSourcesPage);
|
|
|
|
expect(screen.getAllByText(HUMANZ)).toHaveLength(1);
|
|
expect(screen.getAllByText('2 tracks')).toHaveLength(1);
|
|
expect(screen.getAllByTestId('suspect-track-row')).toHaveLength(3);
|
|
});
|
|
|
|
test('empty library explains what would land here', () => {
|
|
mocked.mockReturnValue(infinite([page(0, 0, [])]));
|
|
render(SuspectSourcesPage);
|
|
expect(screen.getByText(/no file names look like video rips/i)).toBeInTheDocument();
|
|
});
|
|
|
|
test('loads more as you scroll, with no button', () => {
|
|
mocked.mockReturnValue(
|
|
infinite([page(0, 80, [{ directory: HUMANZ, tracks: [track('Strobelite', 'a (Official Video).mp3', ['music video'])] }])], {
|
|
hasNextPage: true
|
|
})
|
|
);
|
|
const { container } = render(SuspectSourcesPage);
|
|
expect(container.querySelector('div[aria-hidden="true"].h-px')).not.toBeNull();
|
|
expect(screen.queryByRole('button', { name: /more/i })).not.toBeInTheDocument();
|
|
});
|
|
|
|
// A flagged track is held back from radio and the mixes, and the
|
|
// operator can let it back.
|
|
test('This one is fine lets a held-back track back in', async () => {
|
|
mocked.mockReturnValue(
|
|
infinite([
|
|
page(0, 1, [
|
|
{
|
|
directory: HUMANZ,
|
|
tracks: [track('Strobelite', 'Gorillaz - Strobelite (Official Video).mp3', ['music video'])]
|
|
}
|
|
])
|
|
])
|
|
);
|
|
render(SuspectSourcesPage);
|
|
expect(screen.getByTestId('suspect-verdict')).toHaveTextContent(/Held back/);
|
|
|
|
await fireEvent.click(screen.getByRole('button', { name: 'This one is fine' }));
|
|
expect(setSuspectVerdict).toHaveBeenCalledWith('t-Strobelite', 'fine');
|
|
expect(await screen.findByText('Marked fine')).toBeInTheDocument();
|
|
expect(screen.getByRole('button', { name: 'Hold back again' })).toBeInTheDocument();
|
|
});
|
|
|
|
// A rip that is not fine has its file removed, on a second click; the track
|
|
// waits for a clean copy.
|
|
test('Remove this file asks once more, then removes the rip', async () => {
|
|
mocked.mockReturnValue(
|
|
infinite([
|
|
page(0, 1, [
|
|
{
|
|
directory: HUMANZ,
|
|
tracks: [track('Strobelite', 'Gorillaz - Strobelite (Official Video).mp3', ['music video'])]
|
|
}
|
|
])
|
|
])
|
|
);
|
|
render(SuspectSourcesPage);
|
|
|
|
await fireEvent.click(screen.getByRole('button', { name: 'Remove the file of Strobelite' }));
|
|
expect(removeSuspectFile).not.toHaveBeenCalled();
|
|
await fireEvent.click(screen.getByRole('button', { name: 'Confirm remove the file of Strobelite' }));
|
|
expect(removeSuspectFile).toHaveBeenCalledWith('t-Strobelite');
|
|
});
|
|
});
|