Skip to content

Commit

Permalink
tests: snapshot SVGs
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Sep 29, 2024
1 parent c644fb5 commit 0077d4a
Show file tree
Hide file tree
Showing 14 changed files with 68,765 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/components/GraphViewport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export default class GraphViewport extends Component<
})}
>
<Box
role="img"
aria-label="Visual representation of the GraphQL schema"
ref={this._containerRef}
sx={{
height: '100%',
Expand Down
13 changes: 12 additions & 1 deletion tests/PageObjectModel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Locator, type Page } from '@playwright/test';
import { format } from 'prettier';

interface VoyagerURLParams {
path?: string;
Expand Down Expand Up @@ -40,6 +41,7 @@ export async function gotoVoyagerPage(
class PlaywrightVoyagerPage {
readonly page: Page;
readonly graphLoadingAnimation: Locator;
readonly svgContainer: Locator;

readonly changeSchemaDialog: PlaywrightChangeSchemaDialog;

Expand All @@ -49,6 +51,9 @@ class PlaywrightVoyagerPage {
this.graphLoadingAnimation = page
.getByRole('status')
.getByText('Transmitting...');
this.svgContainer = this.page.getByRole('img', {
name: 'Visual representation of the GraphQL schema',
});

this.changeSchemaDialog = new PlaywrightChangeSchemaDialog(page);

Expand Down Expand Up @@ -87,10 +92,16 @@ class PlaywrightVoyagerPage {
});
}

async waitForGraphToBeLoaded() {
async waitForGraphToBeLoaded(): Promise<void> {
await this.svgContainer.waitFor({ state: 'visible' });
await this.graphLoadingAnimation.waitFor({ state: 'hidden' });
}

async getGraphSVG(): Promise<string> {
const svg = await this.svgContainer.innerHTML();
return format(svg, { parser: 'html' });
}

async submitSDL(sdl: string) {
const { changeSchemaDialog } = this;
const { sdlTab } = changeSchemaDialog;
Expand Down
22 changes: 22 additions & 0 deletions tests/demo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ test('open demo', async ({ page }) => {
const voyagerPage = await gotoVoyagerPage(page);

await voyagerPage.waitForGraphToBeLoaded();
expect
.soft(await voyagerPage.getGraphSVG())
.toMatchSnapshot('demo-graph.svg');
await expect(voyagerPage.page).toHaveScreenshot('loaded-demo.png');
});

Expand All @@ -16,9 +19,15 @@ test('resize screen', async ({ page }) => {
const voyagerPage = await gotoVoyagerPage(page);

await voyagerPage.waitForGraphToBeLoaded();
expect
.soft(await voyagerPage.getGraphSVG())
.toMatchSnapshot('graph-before-resize.svg');
await expect(voyagerPage.page).toHaveScreenshot('demo-before-resize.png');

await page.setViewportSize({ width: 1024, height: 768 });
expect
.soft(await voyagerPage.getGraphSVG())
.toMatchSnapshot('graph-after-resize.svg');
await expect(voyagerPage.page).toHaveScreenshot('demo-after-resize.png');
});

Expand Down Expand Up @@ -47,6 +56,9 @@ for (const name of SchemaPresets) {
// eslint-disable-next-line playwright/no-wait-for-timeout
await page.waitForTimeout(200); // FIXME
await voyagerPage.waitForGraphToBeLoaded();
expect
.soft(await voyagerPage.getGraphSVG())
.toMatchSnapshot(`${slug}-graph.svg`);
await expect(voyagerPage.page).toHaveScreenshot(`show-${slug}-preset.png`);
});
}
Expand Down Expand Up @@ -86,13 +98,19 @@ test('use custom SDL', async ({ page }) => {

await changeSchemaDialog.displayButton.click();
await voyagerPage.waitForGraphToBeLoaded();
expect
.soft(await voyagerPage.getGraphSVG())
.toMatchSnapshot('custom-sdl-graph.svg');
await expect(voyagerPage.page).toHaveScreenshot('display-sdl.png');
});

test('use custom SDL with custom directives', async ({ page }) => {
const voyagerPage = await gotoVoyagerPage(page);
await voyagerPage.submitSDL('type Query @foo { bar: String @baz }');

expect
.soft(await voyagerPage.getGraphSVG())
.toMatchSnapshot('custom-sdl-with-unknown-directives-graph.svg');
await expect(voyagerPage.page).toHaveScreenshot(
'display-sdl-with-unknown-directives.png',
);
Expand Down Expand Up @@ -131,6 +149,9 @@ test('use custom introspection', async ({ page }) => {

await changeSchemaDialog.displayButton.click();
await voyagerPage.waitForGraphToBeLoaded();
expect
.soft(await voyagerPage.getGraphSVG())
.toMatchSnapshot('custom-introspection-graph.svg');
await expect(voyagerPage.page).toHaveScreenshot('display-introspection.png');
});

Expand All @@ -147,6 +168,7 @@ test('use search params to pass url', async ({ page }) => {
const voyagerPage = await gotoVoyagerPage(page, { url });
await voyagerPage.waitForGraphToBeLoaded();

expect.soft(await voyagerPage.getGraphSVG()).toMatchSnapshot('schema-from-url-graph.svg');
await expect(voyagerPage.page).toHaveScreenshot(
'display-schema-from-url.png',
);
Expand Down
109 changes: 109 additions & 0 deletions tests/demo.spec.ts-snapshots/custom-introspection-graph-Demo-linux.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 109 additions & 0 deletions tests/demo.spec.ts-snapshots/custom-sdl-graph-Demo-linux.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0077d4a

Please sign in to comment.