Skip to content

Commit

Permalink
refactor: pr feedback changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rshen91 committed Dec 9, 2020
1 parent 02a06fe commit a5acd93
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 89 deletions.
76 changes: 0 additions & 76 deletions .storybook/style_test.scss

This file was deleted.

33 changes: 22 additions & 11 deletions integration/page_objects/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ interface ElementBBox {
}

interface KeyboardKey {
actionLabel: string;
key: string;
count: number;
}

Expand Down Expand Up @@ -128,7 +128,7 @@ type ScreenshotElementAtUrlOptions = ScreenshotDOMElementOptions & {
/**
* any desired action to be performed after loading url, prior to screenshot
*/
action?: () => void | Promise<void> | Iterable<unknown>;
action?: () => void | Promise<void>;
/**
* Selector used to wait on DOM element
*/
Expand Down Expand Up @@ -218,6 +218,15 @@ class CommonPage {
return buffer;
}

/**
* Move mouse
* @param mousePosition
* @param selector
*/
async moveMouse(x: number, y: number) {
await page.mouse.move(x, y);
}

/**
* Move mouse relative to element
*
Expand All @@ -227,7 +236,7 @@ class CommonPage {
async moveMouseRelativeToDOMElement(mousePosition: MousePosition, selector: string) {
const element = await this.getBoundingClientRect(selector);
const { x, y } = getCursorPosition(mousePosition, element);
await page.mouse.move(x, y);
await this.moveMouse(x, y);
}

/**
Expand All @@ -252,10 +261,10 @@ class CommonPage {
const element = await this.getBoundingClientRect(selector);
const { x: x0, y: y0 } = getCursorPosition(start, element);
const { x: x1, y: y1 } = getCursorPosition(end, element);
await page.mouse.move(x0, y0);
await this.moveMouse(x0, y0);
await page.mouse.down();
await page.waitFor(DRAG_DETECTION_TIMEOUT);
await page.mouse.move(x1, y1);
await this.moveMouse(x1, y1);
}

/**
Expand All @@ -271,19 +280,19 @@ class CommonPage {
/**
* Press keyboard keys
* @param count
* @param actionLabel
* @param key
*/
// eslint-disable-next-line class-methods-use-this
async pressKey(actionLabel: string, count: number) {
if (actionLabel === 'tab') {
async pressKey(key: string, count: number) {
if (key === 'tab') {
let i = 0;
while (i < count) {
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable no-await-in-loop */
await page.keyboard.press('Tab');
i++;
}
} else if (actionLabel === 'enter') {
} else if (key === 'enter') {
let i = 0;
while (i < count) {
await page.keyboard.press('Enter');
Expand Down Expand Up @@ -385,11 +394,13 @@ class CommonPage {
) {
const action = async () => {
await this.disableAnimations();
await this.clickMouseRelativeToDOMElement({ top: 242, left: 910 }, this.chartSelector);
// click to focus within the chart
await this.clickMouseRelativeToDOMElement({ top: 0, left: 0 }, this.chartSelector);
// eslint-disable-next-line no-restricted-syntax
for (const actions of keyboardEvents) {
await this.pressKey(actions.actionLabel, actions.count);
await this.pressKey(actions.key, actions.count);
}
await this.moveMouseRelativeToDOMElement({ top: 0, left: 0 }, this.chartSelector);
};

await this.expectChartAtUrlToMatchScreenshot(url, {
Expand Down
Binary file not shown.
6 changes: 4 additions & 2 deletions integration/tests/legend_stories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,17 @@ describe('Legend stories', () => {
describe('keyboard navigation', () => {
// eslint-disable-next-line jest/expect-expect
it('should navigate to legend item with tab', async () => {
// puts mouse to the bottom left
await common.moveMouse(0, 0);
await common.expectChartWithKeyboardEventsAtUrlToMatchScreenshot(
'http://localhost:9001/?path=/story/legend--right',
[
{
actionLabel: 'tab',
key: 'tab',
count: 2,
},
{
actionLabel: 'enter',
key: 'enter',
count: 1,
},
],
Expand Down

0 comments on commit a5acd93

Please sign in to comment.