diff --git a/.gitignore b/.gitignore index 211fa67..cfc1f81 100644 --- a/.gitignore +++ b/.gitignore @@ -26,5 +26,6 @@ yarn-error.log* /test-results/ /playwright-report/ /playwright/.cache/ +/tests/extension.spec.ts-snapshots/*darwin* .env* diff --git a/src/components/viewer/CadDiff.tsx b/src/components/viewer/CadDiff.tsx index 5cecd69..511b06b 100644 --- a/src/components/viewer/CadDiff.tsx +++ b/src/components/viewer/CadDiff.tsx @@ -252,6 +252,7 @@ export function CadDiff({ before, after }: FileDiff): React.ReactElement { 2-up setShowCombined(true)} sx={{ cursor: 'pointer' }} diff --git a/tests/extension.spec.ts b/tests/extension.spec.ts index bd382bd..74df147 100644 --- a/tests/extension.spec.ts +++ b/tests/extension.spec.ts @@ -1,4 +1,4 @@ -import { Page } from '@playwright/test' +import { ElementHandle, Page } from '@playwright/test' import { test, expect } from './fixtures' test('popup page', async ({ page, extensionId }) => { @@ -18,11 +18,7 @@ test('authorized popup page', async ({ await expect(page.locator('button')).toHaveCount(2) }) -async function getFirstDiffScreenshot( - page: Page, - url: string, - extension: string -) { +async function getFirstDiffElement(page: Page, url: string, extension: string) { page.on('console', msg => console.log(msg.text())) await page.goto(url) @@ -36,10 +32,16 @@ async function getFirstDiffScreenshot( `.js-file[data-file-type=".${extension}"]` ) await page.waitForTimeout(1000) // making sure the element fully settled in - return await element.screenshot() + return element } -async function getBlobPreviewScreenshot(page: Page, url: string) { +async function enableCombined(page: Page, element: ElementHandle) { + const button = await element.$('.kittycad-combined-button') + await button.click() + await page.waitForTimeout(1000) +} + +async function getBlobPreviewElement(page: Page, url: string) { page.on('console', msg => console.log(msg.text())) await page.goto(url) @@ -49,45 +51,62 @@ async function getBlobPreviewScreenshot(page: Page, url: string) { // screenshot the file diff with its toolbar const element = await page.waitForSelector('.kittycad-injected-file') await page.waitForTimeout(1000) // making sure the element fully settled in - return await element.screenshot() + return element } -test('pull request diff with an .obj file', async ({ +test('pull request diff with a modified .obj file', async ({ page, authorizedBackground, }) => { const url = 'https://github.com/KittyCAD/diff-samples/pull/2/files' - const screenshot = await getFirstDiffScreenshot(page, url, 'obj') + const element = await getFirstDiffElement(page, url, 'obj') + const screenshot = await element.screenshot() expect(screenshot).toMatchSnapshot() + + await enableCombined(page, element) + const screenshot2 = await element.screenshot() + expect(screenshot2).toMatchSnapshot() }) -test('pull request diff with a .step file', async ({ +test('pull request diff with a modified .step file', async ({ page, authorizedBackground, }) => { const url = 'https://github.com/KittyCAD/diff-samples/pull/2/files' - const screenshot = await getFirstDiffScreenshot(page, url, 'step') + const element = await getFirstDiffElement(page, url, 'step') + const screenshot = await element.screenshot() expect(screenshot).toMatchSnapshot() + + // TODO: understand why this one makes the CI fail (guess: page crashes, low resources?) + // await enableCombined(page, element) + // const screenshot2 = await element.screenshot() + // expect(screenshot2).toMatchSnapshot() }) -test('commit diff with a .step file', async ({ +test('commit diff with an added .step file', async ({ page, authorizedBackground, }) => { const url = 'https://github.com/KittyCAD/diff-samples/commit/fd9eec79f0464833686ea6b5b34ea07145e32734' - const screenshot = await getFirstDiffScreenshot(page, url, 'step') + const element = await getFirstDiffElement(page, url, 'step') + const screenshot = await element.screenshot() expect(screenshot).toMatchSnapshot() }) -test('commit diff with a .dae file as LFS', async ({ +test('commit diff with a modified .dae file as LFS', async ({ page, authorizedBackground, }) => { const url = 'https://github.com/KittyCAD/diff-samples/commit/b009cfd6dd1eb2d0c3ec0d31a21360766ad084e4' - const screenshot = await getFirstDiffScreenshot(page, url, 'dae') + const element = await getFirstDiffElement(page, url, 'dae') + const screenshot = await element.screenshot() expect(screenshot).toMatchSnapshot() + + await enableCombined(page, element) + const screenshot2 = await element.screenshot() + expect(screenshot2).toMatchSnapshot() }) test('blob preview with an .obj file', async ({ @@ -96,7 +115,8 @@ test('blob preview with an .obj file', async ({ }) => { const url = 'https://github.com/KittyCAD/diff-samples/blob/fd9eec79f0464833686ea6b5b34ea07145e32734/models/box.obj' - const screenshot = await getBlobPreviewScreenshot(page, url) + const element = await getBlobPreviewElement(page, url) + const screenshot = await element.screenshot() expect(screenshot).toMatchSnapshot() }) diff --git a/tests/extension.spec.ts-snapshots/blob-preview-with-an-obj-file-1-chromium-darwin.png b/tests/extension.spec.ts-snapshots/blob-preview-with-an-obj-file-1-chromium-darwin.png deleted file mode 100644 index d8c6814..0000000 Binary files a/tests/extension.spec.ts-snapshots/blob-preview-with-an-obj-file-1-chromium-darwin.png and /dev/null differ diff --git a/tests/extension.spec.ts-snapshots/commit-diff-with-a-dae-file-as-LFS-1-chromium-darwin.png b/tests/extension.spec.ts-snapshots/commit-diff-with-a-dae-file-as-LFS-1-chromium-darwin.png deleted file mode 100644 index 5962303..0000000 Binary files a/tests/extension.spec.ts-snapshots/commit-diff-with-a-dae-file-as-LFS-1-chromium-darwin.png and /dev/null differ diff --git a/tests/extension.spec.ts-snapshots/commit-diff-with-a-dae-file-as-LFS-1-chromium-linux.png b/tests/extension.spec.ts-snapshots/commit-diff-with-a-modified-dae-file-as-LFS-1-chromium-linux.png similarity index 100% rename from tests/extension.spec.ts-snapshots/commit-diff-with-a-dae-file-as-LFS-1-chromium-linux.png rename to tests/extension.spec.ts-snapshots/commit-diff-with-a-modified-dae-file-as-LFS-1-chromium-linux.png diff --git a/tests/extension.spec.ts-snapshots/commit-diff-with-a-modified-dae-file-as-LFS-2-chromium-linux.png b/tests/extension.spec.ts-snapshots/commit-diff-with-a-modified-dae-file-as-LFS-2-chromium-linux.png new file mode 100644 index 0000000..5dce112 Binary files /dev/null and b/tests/extension.spec.ts-snapshots/commit-diff-with-a-modified-dae-file-as-LFS-2-chromium-linux.png differ diff --git a/tests/extension.spec.ts-snapshots/commit-diff-with-a-step-file-1-chromium-darwin.png b/tests/extension.spec.ts-snapshots/commit-diff-with-a-step-file-1-chromium-darwin.png deleted file mode 100644 index 58f7fca..0000000 Binary files a/tests/extension.spec.ts-snapshots/commit-diff-with-a-step-file-1-chromium-darwin.png and /dev/null differ diff --git a/tests/extension.spec.ts-snapshots/commit-diff-with-a-step-file-1-chromium-linux.png b/tests/extension.spec.ts-snapshots/commit-diff-with-an-added-step-file-1-chromium-linux.png similarity index 100% rename from tests/extension.spec.ts-snapshots/commit-diff-with-a-step-file-1-chromium-linux.png rename to tests/extension.spec.ts-snapshots/commit-diff-with-an-added-step-file-1-chromium-linux.png diff --git a/tests/extension.spec.ts-snapshots/pull-request-diff-with-a-modified-obj-file-1-chromium-linux.png b/tests/extension.spec.ts-snapshots/pull-request-diff-with-a-modified-obj-file-1-chromium-linux.png new file mode 100644 index 0000000..a9df880 Binary files /dev/null and b/tests/extension.spec.ts-snapshots/pull-request-diff-with-a-modified-obj-file-1-chromium-linux.png differ diff --git a/tests/extension.spec.ts-snapshots/pull-request-diff-with-a-modified-obj-file-2-chromium-linux.png b/tests/extension.spec.ts-snapshots/pull-request-diff-with-a-modified-obj-file-2-chromium-linux.png new file mode 100644 index 0000000..01150da Binary files /dev/null and b/tests/extension.spec.ts-snapshots/pull-request-diff-with-a-modified-obj-file-2-chromium-linux.png differ diff --git a/tests/extension.spec.ts-snapshots/pull-request-diff-with-a-modified-step-file-1-chromium-linux.png b/tests/extension.spec.ts-snapshots/pull-request-diff-with-a-modified-step-file-1-chromium-linux.png new file mode 100644 index 0000000..f38b49b Binary files /dev/null and b/tests/extension.spec.ts-snapshots/pull-request-diff-with-a-modified-step-file-1-chromium-linux.png differ diff --git a/tests/extension.spec.ts-snapshots/pull-request-diff-with-a-step-file-1-chromium-darwin.png b/tests/extension.spec.ts-snapshots/pull-request-diff-with-a-step-file-1-chromium-darwin.png deleted file mode 100644 index 1554291..0000000 Binary files a/tests/extension.spec.ts-snapshots/pull-request-diff-with-a-step-file-1-chromium-darwin.png and /dev/null differ diff --git a/tests/extension.spec.ts-snapshots/pull-request-diff-with-a-step-file-1-chromium-linux.png b/tests/extension.spec.ts-snapshots/pull-request-diff-with-a-step-file-1-chromium-linux.png deleted file mode 100644 index 2fceee3..0000000 Binary files a/tests/extension.spec.ts-snapshots/pull-request-diff-with-a-step-file-1-chromium-linux.png and /dev/null differ diff --git a/tests/extension.spec.ts-snapshots/pull-request-diff-with-an-obj-file-1-chromium-darwin.png b/tests/extension.spec.ts-snapshots/pull-request-diff-with-an-obj-file-1-chromium-darwin.png deleted file mode 100644 index b3825b6..0000000 Binary files a/tests/extension.spec.ts-snapshots/pull-request-diff-with-an-obj-file-1-chromium-darwin.png and /dev/null differ diff --git a/tests/extension.spec.ts-snapshots/pull-request-diff-with-an-obj-file-1-chromium-linux.png b/tests/extension.spec.ts-snapshots/pull-request-diff-with-an-obj-file-1-chromium-linux.png deleted file mode 100644 index 1742880..0000000 Binary files a/tests/extension.spec.ts-snapshots/pull-request-diff-with-an-obj-file-1-chromium-linux.png and /dev/null differ