Skip to content

Commit

Permalink
add test for right-click within a selection
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Feb 14, 2025
1 parent ffd3de3 commit 531eda1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ test.describe('history selections', () => {
test('selects one item at a time', async ({ page }, workerInfo) => {
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
await hp.openPage({});
await hp.selectsRow(0);
await hp.selectsRow(1);
await hp.selectsRow(2);
await hp.selectsRowIndex(0);
await hp.selectsRowIndex(1);
await hp.selectsRowIndex(2);
});
test('resets selection with new query', async ({ page }, workerInfo) => {
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
await hp.openPage({});
await hp.selectsRow(0);
await hp.selectsRowIndex(0);
await hp.types('example.com');
await hp.rowIsNotSelected(0);
});
test('adds to selection', async ({ page }, workerInfo) => {
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
await hp.openPage({});

await hp.selectsRow(0);
await hp.selectsRowIndex(0);
await hp.selectsRowWithCtrl(1);

await hp.rowIsSelected(0);
Expand All @@ -30,7 +30,7 @@ test.describe('history selections', () => {
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
await hp.openPage({});

await hp.selectsRow(0);
await hp.selectsRowIndex(0);
await hp.selectsRowWithCtrl(1);
await hp.selectsRowWithCtrl(1);
await hp.rowIsSelected(0);
Expand All @@ -39,8 +39,8 @@ test.describe('history selections', () => {
test('Expands a select with shift+click', async ({ page }, workerInfo) => {
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
await hp.openPage({});
await hp.selectsRow(0);
await hp.selectsRowWithShift(4);
await hp.selectsRowIndex(0);
await hp.selectsRowIndexWithShift(4);
await hp.rowIsSelected(0);
await hp.rowIsSelected(1);
await hp.rowIsSelected(2);
Expand All @@ -53,13 +53,13 @@ test.describe('history selections', () => {
test('Anchors a selection with shift+click', async ({ page }, workerInfo) => {
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
await hp.openPage({});
await hp.selectsRow(4);
await hp.selectsRowWithShift(6);
await hp.selectsRowIndex(4);
await hp.selectsRowIndexWithShift(6);
await hp.rowIsSelected(4);
await hp.rowIsSelected(5);
await hp.rowIsSelected(6);

await hp.selectsRowWithShift(0);
await hp.selectsRowIndexWithShift(0);
await hp.rowIsSelected(0);
await hp.rowIsSelected(1);
await hp.rowIsSelected(2);
Expand All @@ -73,13 +73,16 @@ test.describe('history selections', () => {
test('removes all selections when any item is deleted', async ({ page }, workerInfo) => {
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
await hp.openPage({});
await hp.selectsRow(0);
await hp.selectsRowIndex(0);
await hp.deletesFromHistoryEntry(1, { action: 'delete' });
await hp.rowIsNotSelected(0);
});
test.skip('issues context menu for selected group', async ({ page }, workerInfo) => {
test('issues context menu for selected group', async ({ page }, workerInfo) => {
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
await hp.openPage({});
await hp.selectsRowIndex(0);
await hp.selectsRowIndexWithShift(2);
await hp.rightClicksWithinSelection(0, hp.ids(3));
});
test.skip('when multiple selected, issues context menu for a single row, when a non-selected item is the target', async ({
page,
Expand Down
27 changes: 25 additions & 2 deletions special-pages/pages/history/integration-tests/history.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export class HistoryTestPage {
/**
* @param {number} nth
*/
async selectsRow(nth) {
async selectsRowIndex(nth) {
const { page } = this;
const rows = page.locator('main').locator('[aria-selected]');
const selected = page.locator('main').locator('[aria-selected="true"]');
Expand Down Expand Up @@ -374,9 +374,32 @@ export class HistoryTestPage {
/**
* @param {number} nth
*/
async selectsRowWithShift(nth) {
async selectsRowIndexWithShift(nth) {
const { page } = this;
const rows = page.locator('main').locator('[aria-selected]');
await rows.nth(nth).click({ modifiers: ['Shift'] });
}

/**
* @param {number} count
*/
ids(count) {
return generateSampleData({ count: this.entries, offset: 0 })
.slice(0, count)
.map((x) => x.id);
}

/**
* @param {number} nth
* @param {string[]} expectedIds
*/
async rightClicksWithinSelection(nth, expectedIds) {
const { page } = this;
const rows = page.locator('main').locator('[aria-selected]');
const selectedRow = rows.nth(nth);
await selectedRow.click({ button: 'right' });
const calls = await this.mocks.waitForCallCount({ method: 'entries_menu', count: 1 });

expect(calls[0].payload.params).toStrictEqual({ ids: expectedIds });
}
}

0 comments on commit 531eda1

Please sign in to comment.