Search the library in the import section
The search shows the matches from a story site that Bindery does not track yet. The button that lists every such book stays.
This commit is contained in:
+46
-2
@@ -233,11 +233,11 @@ test('dropping a file on a closed epub import card opens it and fills the file f
|
||||
test('library import sends only selected books and handles an empty candidate list', async () => {
|
||||
await mountStories();
|
||||
api.on('GET', 'library/candidates', []);
|
||||
await click(main, 'Find stories in the library');
|
||||
await click(main, 'Show all stories in the library');
|
||||
assert.match(main.textContent, /tracked already/);
|
||||
const books = [{ id: 8, uuid: 'a', title: 'A', authors: ['W'] }, { id: 9, uuid: 'b', title: 'B', authors: [] }];
|
||||
api.on('GET', 'library/candidates', books);
|
||||
await click(main, 'Find stories in the library');
|
||||
await click(main, 'Show all stories in the library');
|
||||
change(field(main, 'Select all'), false);
|
||||
await click(main, 'Import selected');
|
||||
assert.equal(writes().length, 0);
|
||||
@@ -252,6 +252,50 @@ test('library import sends only selected books and handles an empty candidate li
|
||||
assert.deepEqual(api.sent('POST', 'library/import')[0].body, { books: [{ id: 8, uuid: 'a', title: 'A' }], check: false });
|
||||
});
|
||||
|
||||
test('library import search trims the query, selects no book at first and imports the ticked books', async () => {
|
||||
await mountStories();
|
||||
const card = section(main, 'Import from the library');
|
||||
const form = nodes(card).find((el) => el.tagName === 'form');
|
||||
assert.equal(form.className, 'library-search');
|
||||
assert.equal(find(form, 'button', 'Search').attributes.type, 'submit');
|
||||
emit(form, 'submit');
|
||||
field(card, 'Search the library').value = ' ';
|
||||
emit(form, 'submit');
|
||||
await settle();
|
||||
assert.equal(api.requests.some((r) => r.path.startsWith('library/candidates')), false);
|
||||
field(card, 'Search the library').value = ' A & B ';
|
||||
api.on('GET', 'library/candidates?q=A%20%26%20B', []);
|
||||
emit(form, 'submit');
|
||||
await settle();
|
||||
assert.match(card.textContent, /No library books from a story site match/);
|
||||
assert.equal(find(card, 'button', 'Import selected'), undefined);
|
||||
const books = [{ id: 8, uuid: 'a', title: 'A', authors: ['W'] }, { id: 9, uuid: 'b', title: 'B', authors: [] }];
|
||||
api.on('GET', 'library/candidates?q=A%20%26%20B', books);
|
||||
emit(form, 'submit');
|
||||
await settle();
|
||||
assert.deepEqual(['Select all', 'A', 'B'].map((label) => field(card, label).checked), [false, false, false]);
|
||||
await click(card, 'Import selected');
|
||||
assert.equal(writes().length, 0);
|
||||
change(field(card, 'B'), true);
|
||||
api.on('POST', 'library/import', [{ id: 'job' }]);
|
||||
await click(card, 'Import selected');
|
||||
assert.deepEqual(api.sent('POST', 'library/import')[0].body, { books: [{ id: 9, uuid: 'b', title: 'B' }], check: true });
|
||||
// The full list still selects each book.
|
||||
api.on('GET', 'library/candidates', books);
|
||||
await click(card, 'Show all stories in the library');
|
||||
assert.deepEqual(['Select all', 'A', 'B'].map((label) => field(card, label).checked), [true, true, true]);
|
||||
});
|
||||
|
||||
test('a failed library import search shows the error', async () => {
|
||||
await mountStories();
|
||||
const card = section(main, 'Import from the library');
|
||||
field(card, 'Search the library').value = 'A';
|
||||
api.on('GET', 'library/candidates?q=A', { error: 'CWA is offline' }, 502);
|
||||
emit(nodes(card).find((el) => el.tagName === 'form'), 'submit');
|
||||
await settle();
|
||||
assert.equal(find(card, 'button', 'Import selected'), undefined);
|
||||
});
|
||||
|
||||
test('rules edits, moves, removal and paragraph choices are saved in order', async () => {
|
||||
api.on('GET', 'stories/1/rules', { ...emptyRules, rules: [rule, { ...rule, pattern: 'second' }] });
|
||||
const editor = rulesEditor('stories/1/rules');
|
||||
|
||||
Reference in New Issue
Block a user