Skip to content

Commit

Permalink
Add param in tests for skipping screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
natdurlik committed Nov 26, 2024
1 parent 50ce1ba commit 4aa83c3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
14 changes: 10 additions & 4 deletions ui-tests/__test__/flows/file-tree/collapse-file-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import testIds from '../../../../src/helper/test-ids';
import { showFileTree } from './show-file-tree';
import { getSelector, waitForAnimationEnd } from '../../helpers';

export const collapseExpandFileTree = async (page: Page): Promise<void> => {
export const collapseExpandFileTree = async (page: Page, skipScreenshots?: boolean): Promise<void> => {
await showFileTree(page, true);

const fileWrapperLocator = page.locator(getSelector(testIds.chatItem.fileTree.wrapper));
Expand All @@ -17,19 +17,25 @@ export const collapseExpandFileTree = async (page: Page): Promise<void> => {
await page.mouse.move(0, 0);
await waitForAnimationEnd(page);

expect(await fileWrapperLocator.screenshot()).toMatchImageSnapshot();
if (skipScreenshots !== true) {
expect(await fileWrapperLocator.screenshot()).toMatchImageSnapshot();
}

// Collapse the outermost folder
await folderLocator.nth(0).click();
await page.mouse.move(0, 0);
await waitForAnimationEnd(page);

expect(await fileWrapperLocator.screenshot()).toMatchImageSnapshot();
if (skipScreenshots !== true) {
expect(await fileWrapperLocator.screenshot()).toMatchImageSnapshot();
}

// Expand the outermost folder
await folderLocator.nth(0).click();
await page.mouse.move(0, 0);
await waitForAnimationEnd(page);

expect(await fileWrapperLocator.screenshot()).toMatchImageSnapshot();
if (skipScreenshots !== true) {
expect(await fileWrapperLocator.screenshot()).toMatchImageSnapshot();
}
};
6 changes: 4 additions & 2 deletions ui-tests/__test__/flows/file-tree/render-file-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { openNewTab } from '../open-new-tab';
import { getSelector, waitForAnimationEnd } from '../../helpers';
import testIds from '../../../../src/helper/test-ids';

export const renderFileDetails = async (page: Page): Promise<void> => {
export const renderFileDetails = async (page: Page, skipScreenshots?: boolean): Promise<void> => {
await closeTab(page, false, true);
await openNewTab(page, false, true);

Expand Down Expand Up @@ -47,5 +47,7 @@ export const renderFileDetails = async (page: Page): Promise<void> => {
const fileWrapperLocator = page.locator(getSelector(testIds.chatItem.fileTree.wrapper));

expect(await fileWrapperLocator.count()).toEqual(1);
expect(await fileWrapperLocator.screenshot()).toMatchImageSnapshot();
if (skipScreenshots !== true) {
expect(await fileWrapperLocator.screenshot()).toMatchImageSnapshot();
}
};
10 changes: 7 additions & 3 deletions ui-tests/__test__/flows/file-tree/show-file-tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import testIds from '../../../../src/helper/test-ids';
import { showFileTree } from './show-file-tree';
import { getSelector, waitForAnimationEnd } from '../../helpers';

export const showFileTooltip = async (page: Page): Promise<void> => {
export const showFileTooltip = async (page: Page, skipScreenshots?: boolean): Promise<void> => {
await showFileTree(page, true);

const fileLocator = page.locator(getSelector(testIds.chatItem.fileTree.file));
Expand All @@ -17,12 +17,16 @@ export const showFileTooltip = async (page: Page): Promise<void> => {
await waitForAnimationEnd(page);

expect(await tooltipLocator.count()).toEqual(1);
expect(await page.screenshot()).toMatchImageSnapshot();
if (skipScreenshots !== true) {
expect(await page.screenshot()).toMatchImageSnapshot();
}

// Stop hovering over a file to hide description
await page.mouse.move(0, 0);
await waitForAnimationEnd(page);

expect(await tooltipLocator.count()).toEqual(0);
expect(await page.screenshot()).toMatchImageSnapshot();
if (skipScreenshots !== true) {
expect(await page.screenshot()).toMatchImageSnapshot();
}
};
14 changes: 10 additions & 4 deletions ui-tests/__test__/flows/file-tree/trigger-file-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import testIds from '../../../../src/helper/test-ids';
import { showFileTree } from './show-file-tree';
import { getSelector, waitForAnimationEnd } from '../../helpers';

export const triggerFileActions = async (page: Page): Promise<void> => {
export const triggerFileActions = async (page: Page, skipScreenshots?: boolean): Promise<void> => {
await showFileTree(page, true);

// Click on a file to trigger default action
Expand All @@ -14,20 +14,26 @@ export const triggerFileActions = async (page: Page): Promise<void> => {
await page.mouse.move(0, 0);
await waitForAnimationEnd(page);

expect(await page.screenshot()).toMatchImageSnapshot();
if (skipScreenshots !== true) {
expect(await page.screenshot()).toMatchImageSnapshot();
}

// Hover over a file to show sub actions
await fileLocator.nth(1).hover();
const fileActionLocator = page.locator(getSelector(testIds.chatItem.fileTree.fileAction));
expect(await fileActionLocator.count()).toEqual(2);
await waitForAnimationEnd(page);

expect(await page.screenshot()).toMatchImageSnapshot();
if (skipScreenshots !== true) {
expect(await page.screenshot()).toMatchImageSnapshot();
}

// Click on a file action button to trigger sub action
await fileActionLocator.nth(1).click();
await page.mouse.move(0, 0);
await waitForAnimationEnd(page);

expect(await page.screenshot()).toMatchImageSnapshot();
if (skipScreenshots !== true) {
expect(await page.screenshot()).toMatchImageSnapshot();
}
};
14 changes: 10 additions & 4 deletions ui-tests/__test__/flows/link-hover-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import testIds from '../../../src/helper/test-ids';
import { closeTab } from './close-tab';
import { openNewTab } from './open-new-tab';

export const hoverOverLink = async (page: Page): Promise<void> => {
export const hoverOverLink = async (page: Page, skipScreenshots?: boolean): Promise<void> => {
await closeTab(page, false, true);
await openNewTab(page, false, true);

Expand Down Expand Up @@ -39,20 +39,26 @@ clamato nescisse.`,
}, mockSource);
await waitForAnimationEnd(page);

expect(await page.screenshot()).toMatchImageSnapshot();
if (skipScreenshots !== true) {
expect(await page.screenshot()).toMatchImageSnapshot();
}

const linkWrapperLocator = page.locator(getSelector(testIds.chatItem.relatedLinks.linkWrapper));
await linkWrapperLocator.hover();
await waitForAnimationEnd(page);

expect(await page.screenshot()).toMatchImageSnapshot();
if (skipScreenshots !== true) {
expect(await page.screenshot()).toMatchImageSnapshot();
}
expect(await page.locator(getSelector(testIds.chatItem.relatedLinks.linkPreviewOverlay)).count()).toEqual(1);
expect(await page.locator(getSelector(testIds.chatItem.relatedLinks.linkPreviewOverlayCard)).count()).toEqual(1);

page.mouse.move(0, 0);
await waitForAnimationEnd(page);

expect(await page.screenshot()).toMatchImageSnapshot();
if (skipScreenshots !== true) {
expect(await page.screenshot()).toMatchImageSnapshot();
}
expect(await page.locator(getSelector(testIds.chatItem.relatedLinks.linkPreviewOverlay)).count()).toEqual(0);
expect(await page.locator(getSelector(testIds.chatItem.relatedLinks.linkPreviewOverlayCard)).count()).toEqual(0);
};

0 comments on commit 4aa83c3

Please sign in to comment.