Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(listbox): keyboard navigation rendering tests #1220

Merged
merged 18 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
649d55f
refactor: compensate for checkboxes in item width
johanlahti Mar 16, 2023
adf9df0
Merge remote-tracking branch 'origin/master'
johanlahti Mar 17, 2023
acf4930
Merge branch 'master' of https://github.com/qlik-oss/nebula.js
johanlahti Mar 17, 2023
4ca0308
Merge branch 'master' of https://github.com/qlik-oss/nebula.js
johanlahti Mar 20, 2023
bcc15a4
Merge branch 'master' of https://github.com/qlik-oss/nebula.js
johanlahti Mar 31, 2023
d1edcd2
Merge branch 'master' of https://github.com/qlik-oss/nebula.js
johanlahti Apr 3, 2023
8ac3cb6
Merge branch 'master' of https://github.com/qlik-oss/nebula.js
johanlahti Apr 3, 2023
df2f26a
Merge branch 'master' of https://github.com/qlik-oss/nebula.js
johanlahti Apr 4, 2023
cdae979
Merge branch 'master' of https://github.com/qlik-oss/nebula.js
johanlahti Apr 11, 2023
db27968
Merge branch 'master' of https://github.com/qlik-oss/nebula.js
johanlahti Apr 12, 2023
f9baaf1
test: render keyboard navigation
johanlahti Apr 13, 2023
110f8db
Merge remote-tracking branch 'origin/master' into test/render-key-nav
johanlahti Apr 13, 2023
b5a533f
fix: revert mashup change
johanlahti Apr 13, 2023
8071601
Merge remote-tracking branch 'origin/master' into test/render-key-nav
johanlahti Apr 14, 2023
4b81504
test: upload img
johanlahti Apr 14, 2023
86b9f6d
fix: rm unncessary headless
johanlahti Apr 14, 2023
9e73771
test: update snapshot
johanlahti Apr 14, 2023
ec2ad2d
Merge remote-tracking branch 'origin/master' into test/render-key-nav
johanlahti Apr 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions test/rendering/listbox/listbox-keyboard-nav.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* eslint-disable no-undef */
import { test, expect } from '@playwright/test';

const getPage = require('../setup');
const startServer = require('../server');

test.describe('keyboard navigation', () => {
const filePrefix = 'listbox-focus';
const object = '[data-type="listbox"]';
const listboxSelector = `${object} .listbox-container`;

let page;

let destroyServer;
let destroyBrowser;
let url;

test.use({ viewport: { width: 300, height: 500 } });

test.beforeEach(async () => {
({ url, destroy: destroyServer } = await startServer(8050));
({ page, destroy: destroyBrowser } = await getPage());
});

test.afterEach(async () => {
await Promise.all([destroyServer(), destroyBrowser()]);
});

test('hovering and pressing arrow down should scroll listbox', async () => {
const FILE_NAME = 'listbox_key_scroll.png';

await page.goto(`${url}/listbox/listbox.html?scenario=standard`, { waitUntil: 'networkidle' });
const selector = await page.waitForSelector(listboxSelector, { visible: true });

await page.hover(listboxSelector);
await page.press(listboxSelector, 'ArrowDown');

const image = await selector.screenshot({ caret: 'hide' });
return expect(image).toMatchSnapshot(FILE_NAME);
});

test('simple list move down up and select C', async () => {
await page.goto(`${url}/listbox/listbox.html?scenario=standard`, { waitUntil: 'networkidle' });
const selector = await page.waitForSelector(listboxSelector, { visible: true });

// Move focus from A to C.
const firstRow = await page.waitForSelector('[data-testid="listbox.item"]:first-child .value');
await firstRow.focus();
await page.keyboard.press('ArrowDown'); // At B
await page.keyboard.press('ArrowDown'); // At C
const focusCImage = await selector.screenshot({ caret: 'hide' });
expect(focusCImage).toMatchSnapshot(`${filePrefix}-C.png`);

// Select and move focus up one step.
await page.keyboard.press('Space'); // Select C
await page.keyboard.press('ArrowUp'); // At B
const focusBAndSelectedCImage = await selector.screenshot({ caret: 'hide' });
expect(focusBAndSelectedCImage).toMatchSnapshot(`${filePrefix}-B-select-C.png`);

// Tab to confirm button.
await page.keyboard.press('Tab'); // At confirm button
const focusConfirm = await selector.screenshot({ caret: 'hide' });
expect(focusConfirm).toMatchSnapshot(`${filePrefix}-confirm.png`);

// Tab into search field.
await page.keyboard.press('Tab'); // At confirm button
const focusSearch = await selector.screenshot({ caret: 'hide' });
expect(focusSearch).toMatchSnapshot(`${filePrefix}-search.png`);

// Tab back into last focused row.
await page.keyboard.press('Tab'); // At a row again
const focusRow = await selector.screenshot({ caret: 'hide' });
expect(focusRow).toMatchSnapshot(`${filePrefix}-row-again.png`);

// Press Enter to confirm selections.
await page.keyboard.press('Enter');
const stillFocusingRow = await selector.screenshot({ caret: 'hide' });
expect(stillFocusingRow).toMatchSnapshot(`${filePrefix}-row-after-confirm.png`);
});
});
33 changes: 0 additions & 33 deletions test/rendering/listbox/listbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,6 @@ test.describe('listbox mashup rendering test', () => {
return expect(image).toMatchSnapshot(FILE_NAME);
});

// This test doesn't work correctly due to the setup.
// The checkbox never gets checked because the preselect won't work
// and the actual select isn't mocked.
test.skip('should render checkboxes and check A and I', async () => {
const FILE_NAME = 'listbox_checkboxes_select_AI.png';

await page.goto(`${url}/listbox/listbox.html?scenario=checkboxes`, { waitUntil: 'networkidle' });
const selector = await page.waitForSelector(listboxSelector, { visible: true });

const selectNumbers = [0, 8];
const action = async (nbr) => {
const rowSelector = `${listboxSelector} input[data-n="${nbr}"]`;
await page.locator(rowSelector).check();
};
await execSequence(selectNumbers, action);

const image = await selector.screenshot({ caret: 'hide' });
return expect(image).toMatchSnapshot(FILE_NAME);
});

test('listbox search', async () => {
const FILE_NAME = 'listbox_search_B.png';
const searchSelector = '.search input';
Expand Down Expand Up @@ -103,19 +83,6 @@ test.describe('listbox mashup rendering test', () => {
return expect(image).toMatchSnapshot(FILE_NAME);
});

test('hovering and pressing arrow down should scroll listbox', async () => {
const FILE_NAME = 'listbox_key_scroll.png';

await page.goto(`${url}/listbox/listbox.html?scenario=standard`, { waitUntil: 'networkidle' });
const selector = await page.waitForSelector(listboxSelector, { visible: true });

await page.hover(listboxSelector);
await page.press(listboxSelector, 'ArrowDown');

const image = await selector.screenshot({ caret: 'hide' });
return expect(image).toMatchSnapshot(FILE_NAME);
});

test('long title should detach toolbar', async () => {
const FILE_NAME = 'listbox_detached_toolbar.png';

Expand Down
2 changes: 1 addition & 1 deletion test/rendering/setup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { chromium } = require('@playwright/test');

async function getPage() {
const browser = await chromium.launch();
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage();
page.setDefaultNavigationTimeout(30000);
page.setDefaultTimeout(30000);
Expand Down