mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-05 14:19:56 -05:00
* e2e: exercise the FileBrowser footer buttons against real files Sixteen Cypress tests covering Rename, Move, Delete (including the tagged-file force-delete flow), Ignore/Unignore, Upload, and scoped Refresh, with no API mocking: fb:* tasks seed a cypress-fb/ sandbox inside the media directory, the UI mutates it through the real API, and assertions check the disk as well as the table. Skipped in CI, which runs only the React dev server. Background jobs (move, refresh) only queue work and worker_status reads idle while jobs wait, so cy.refreshFiles / cy.waitForEvent poll the events feed for completion events newer than the server's clock, and fail loudly when one never arrives. Every suite cleans up unconditionally: sandbox files, DB rows via a final refresh, test tags and their tags/ directories, and any leaked ignored-directory config. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * e2e: act on review — drain stragglers, teardown that cannot be skipped Events carry no job id, so waitForEvent cannot prove WHICH job finished. The rename tests now drain the parent-directory refresh their rename queues before ending, so the next test's refresh wait cannot be satisfied by a straggler while the DB still reflects the old tree; move waits match the destination in the completion message. Teardown must always reach the disk wipe: a failed command aborts the rest of its hook, so the tag cleanup and the DB-purge refresh are now best-effort (failOnStatusCode: false, no assertions), and the unignore runs after every test instead of once per spec. History and forward-looking product notes trimmed from comments. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
140 lines
5.2 KiB
JavaScript
140 lines
5.2 KiB
JavaScript
/*
|
|
* The Ignore, Upload, and Refresh buttons in the FileBrowser's sticky footer, against the
|
|
* live stack. Ignore/Upload only make sense with a single directory selected, so this spec
|
|
* also carries their enable-state rules.
|
|
*/
|
|
import {
|
|
assertWROLModeOff,
|
|
deselectRow,
|
|
dialog,
|
|
footerButton,
|
|
row,
|
|
selectRow,
|
|
setupFileBrowser,
|
|
teardownFileBrowser,
|
|
} from '../../support/file-browser';
|
|
|
|
// Requires the full stack (API + real media directory); CI runs only the React dev server.
|
|
(Cypress.env('CI') ? describe.skip : describe)('FileBrowser footer: Ignore, Upload, Refresh', () => {
|
|
|
|
const seedFiles = {
|
|
'fb-notes.txt': 'a file',
|
|
'fb-beta/fb-inside.txt': 'inside the directory',
|
|
};
|
|
|
|
const IGNORED_DIR = 'cypress-fb/fb-beta';
|
|
|
|
before(assertWROLModeOff);
|
|
|
|
beforeEach(() => setupFileBrowser(seedFiles, 'fb-notes.txt'));
|
|
|
|
// Un-ignore after EVERY test: a failure mid-ignore must not leave the sandbox in the
|
|
// ignored_directories config for the spec's later tests (or the user's stack).
|
|
afterEach(() => {
|
|
cy.request({
|
|
method: 'POST',
|
|
url: '/api/files/unignore_directory',
|
|
body: {path: `/media/wrolpi/${IGNORED_DIR}`},
|
|
failOnStatusCode: false,
|
|
});
|
|
});
|
|
|
|
after(teardownFileBrowser);
|
|
|
|
// cy.task has no built-in retry; background work (uploads) lands on disk asynchronously.
|
|
const waitForDisk = (relativePath, timeout = 30000) => {
|
|
const deadline = Date.now() + timeout;
|
|
const poll = () => {
|
|
cy.task('fb:exists', relativePath).then((exists) => {
|
|
if (exists) return;
|
|
expect(Date.now(), `${relativePath} did not appear on disk within ${timeout}ms`)
|
|
.to.be.lessThan(deadline);
|
|
cy.wait(500);
|
|
poll();
|
|
});
|
|
};
|
|
poll();
|
|
};
|
|
|
|
it('Upload and Ignore require a single directory selection', () => {
|
|
// Nothing selected: Upload targets the media directory, Ignore has no directory.
|
|
footerButton('Upload').should('be.enabled');
|
|
footerButton('Ignore').should('be.disabled');
|
|
|
|
selectRow('fb-notes.txt');
|
|
footerButton('Upload').should('be.disabled');
|
|
footerButton('Ignore').should('be.disabled');
|
|
deselectRow('fb-notes.txt');
|
|
|
|
selectRow('fb-beta');
|
|
footerButton('Upload').should('be.enabled');
|
|
footerButton('Ignore').should('be.enabled');
|
|
|
|
selectRow('fb-notes.txt');
|
|
footerButton('Upload').should('be.disabled');
|
|
footerButton('Ignore').should('be.disabled');
|
|
});
|
|
|
|
it('ignores and un-ignores a directory through the config', () => {
|
|
selectRow('fb-beta');
|
|
footerButton('Ignore').click();
|
|
|
|
dialog().should('contain.text', 'Ignore Directory')
|
|
.should('contain.text', `/media/wrolpi/${IGNORED_DIR}`);
|
|
dialog().contains('button', 'Ignore').click();
|
|
|
|
// The directory lands in the settings config.
|
|
cy.request('/api/settings').its('body.ignored_directories')
|
|
.should('include', IGNORED_DIR);
|
|
|
|
// With the settings reloaded the same button now offers the reverse action.
|
|
footerButton('Unignore').should('be.enabled').click();
|
|
dialog().should('contain.text', 'Remove Ignore Directory');
|
|
dialog().contains('button', 'Un-ignore').click();
|
|
|
|
cy.request('/api/settings').its('body.ignored_directories')
|
|
.should('not.include', IGNORED_DIR);
|
|
footerButton('Ignore').should('be.enabled');
|
|
});
|
|
|
|
it('uploads a file into the selected directory', () => {
|
|
selectRow('fb-beta');
|
|
footerButton('Upload').click();
|
|
|
|
dialog().should('contain.text', `Upload to: /media/wrolpi/${IGNORED_DIR}`);
|
|
dialog().find('input[type="file"]').selectFile({
|
|
contents: Cypress.Buffer.from('uploaded by cypress'),
|
|
fileName: 'fb-uploaded.txt',
|
|
}, {force: true});
|
|
|
|
waitForDisk('fb-beta/fb-uploaded.txt');
|
|
dialog().contains('button', 'Close').click();
|
|
dialog().should('not.exist');
|
|
|
|
// The upload landed exactly where the selection pointed.
|
|
cy.task('fb:readdir', 'fb-beta').should('deep.equal', ['fb-inside.txt', 'fb-uploaded.txt']);
|
|
});
|
|
|
|
it('Refresh with a selection runs a scoped refresh end-to-end', () => {
|
|
// Drop a file behind the UI's back; only a refresh makes the backend index it.
|
|
cy.task('fb:seed', {files: {'fb-sneaky.txt': 'added behind the UI'}});
|
|
|
|
selectRow('cypress-fb');
|
|
cy.serverNow().then((since) => {
|
|
footerButton('Refresh').click();
|
|
// The button's refresh is scoped to the selection -- the completion event
|
|
// names the sandbox, a global refresh would say 'Global refresh completed'.
|
|
cy.waitForEvent({
|
|
since,
|
|
event: 'directory_refresh',
|
|
message: 'Refreshed: cypress-fb',
|
|
timeout: 30000,
|
|
});
|
|
});
|
|
|
|
// The browse table does not refetch after a refresh, so reload to see the result.
|
|
// The open folders live in the ?folders= query, so the sandbox stays open.
|
|
cy.reload();
|
|
row('fb-sneaky.txt').should('be.visible');
|
|
});
|
|
});
|