Skip to content

Commit 6c57d1c

Browse files
committed
only allow delete button with term+selection
1 parent 5a37c56 commit 6c57d1c

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

special-pages/pages/history/app/components/Header.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,21 @@ function Controls({ term, range }) {
4242
/**
4343
* Aria labels + title text is derived from the current result set.
4444
*/
45-
const ariaDisabled = useComputed(() => (results.value.items.length === 0 ? 'true' : 'false'));
45+
const ariaDisabled = useComputed(() => {
46+
const hasResults = results.value.items.length > 0;
47+
const hasTerm = term.value !== null && term.value.trim() !== '';
48+
const hasSelections = selected.value.size > 0;
49+
50+
// always disabled when there are no results
51+
if (!hasResults) return true;
52+
53+
// disabled if a search term is there, but no selections where made
54+
if (hasTerm && !hasSelections) return true;
55+
56+
// otherwise, it's not disabled
57+
return false;
58+
});
59+
4660
const title = useComputed(() => (results.value.items.length === 0 ? t('delete_none') : ''));
4761

4862
/**

special-pages/pages/history/integration-tests/history-selections.spec.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,21 @@ test.describe('history selections', () => {
142142
await hp.clicksDeleteInHeader({ action: 'delete' });
143143
await hp.didDeleteSelection([0]);
144144
});
145-
test('`deleteAll` button text changes when a query is present', async ({ page }, workerInfo) => {
145+
test('`delete` in header respects selection after search', async ({ page }, workerInfo) => {
146+
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
147+
await hp.openPage({});
148+
await hp.types('2');
149+
await hp.waitForRowCount(2);
150+
await hp.selectsRowIndex(0);
151+
await hp.selectsRowIndexWithShift(1);
152+
await hp.clicksDeleteInHeader({ action: 'delete' });
153+
await hp.didDeleteSelection([0, 1]);
154+
});
155+
test('`delete` in header is disabled for searches (no selections)', async ({ page }, workerInfo) => {
146156
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
147157
await hp.openPage({});
148158
await hp.types('example.com');
149-
await hp.deleteAllButtonReflectsSelection();
159+
await hp.deleteButtonIsDisabled();
150160
});
151161
test('removes all selections with ESC key', async ({ page }, workerInfo) => {
152162
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);

special-pages/pages/history/integration-tests/history.page.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,11 @@ export class HistoryTestPage {
434434
await page.locator('header').getByRole('button', { name: 'Delete', exact: true }).click();
435435
}
436436

437+
async deleteButtonIsDisabled() {
438+
const { page } = this;
439+
await expect(page.locator('header').getByRole('button', { name: 'Delete', exact: true })).toHaveAttribute('aria-disabled', 'true');
440+
}
441+
437442
async pressesEscape() {
438443
const { page } = this;
439444
const main = page.locator('body');
@@ -501,6 +506,14 @@ export class HistoryTestPage {
501506
expect(rowCount).toBe(count);
502507
}
503508

509+
/**
510+
* @param {number} count
511+
*/
512+
async waitForRowCount(count) {
513+
const { page } = this;
514+
await page.waitForFunction((count) => document.querySelector('main')?.querySelectorAll('[aria-selected]').length === count, count);
515+
}
516+
504517
sidebar() {
505518
return this.page.locator('aside');
506519
}

0 commit comments

Comments
 (0)