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

Add some visual regression tests #1959

Merged
merged 24 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
00324d8
Add some visual regression tests
Janpot May 2, 2023
2eff22d
Delete toolpad_main.js
Janpot May 2, 2023
adfec91
prettier
Janpot May 2, 2023
643ee85
wip
Janpot May 3, 2023
02970ee
update
Janpot May 3, 2023
137fc13
Merge branch 'master' into visual-regression-testing
Janpot May 5, 2023
cdebf0a
Merge branch 'master' into visual-regression-testing
Janpot May 9, 2023
b0f3a3a
Merge branch 'master' into visual-regression-testing
Janpot May 16, 2023
de140c9
Merge branch 'master' into visual-regression-testing
Janpot May 17, 2023
4613fcf
Merge branch 'master' into visual-regression-testing
Janpot May 23, 2023
338ad1f
Merge branch 'master' into visual-regression-testing
Janpot May 26, 2023
f086521
Merge branch 'master' into visual-regression-testing
Janpot Jun 6, 2023
5438371
Merge branch 'master' into visual-regression-testing
Janpot Jun 7, 2023
8013604
Merge branch 'master' into visual-regression-testing
Janpot Jun 8, 2023
2ca0d8a
Merge branch 'master' into visual-regression-testing
Janpot Jun 15, 2023
9b455fd
Merge branch 'master' into visual-regression-testing
Janpot Jun 20, 2023
4fac3e6
Merge branch 'master' into visual-regression-testing
Janpot Jun 30, 2023
f4e2e4a
Merge remote-tracking branch 'upstream/master' into visual-regression…
Janpot Jul 13, 2023
ac887a7
Use Argos
Janpot Jul 13, 2023
508564d
frefger
Janpot Jul 13, 2023
e2a90f3
Merge branch 'master' into visual-regression-testing
Janpot Jul 13, 2023
bb38bbc
ewgw
Janpot Jul 13, 2023
1305b77
Update CONTRIBUTING.md
Janpot Jul 13, 2023
eb313e5
remove docker
Janpot Jul 13, 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
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
**/node_modules
**/.next
.git
.yarn-playwright-cache
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/examples/*/toolpad.yml

/test/integration/*/fixture*/
/test/visual/*/fixture*/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ examples/*/yarn.lock

test-results
.toolpad-generated

.yarn-playwright-cache
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,20 @@ yarn install

- Use the `--ui` flag to run the tests interactively

## Visual regression tests

- You can find debugging information and diffs in the `test-results` folder. These are also stored in CI in the circleci artifacts.

- You can update the screenshots if necessary. You must have [docker](https://www.docker.com/products/docker-desktop/) installed.

```sh
docker compose run --rm playwright
yarn && yarn release:build
yarn test:integration --project visual --update-snapshots
```

_Tip: Configure docker for mac to use VirtioFS for improved performance (Docker desktop settings > General > Choose file sharing implementation for your containers)_

## Sending a pull request

Please have a look at our general [guidelines](https://github.com/mui/material-ui/blob/master/CONTRIBUTING.md#sending-a-pull-request) for sending pull requests.
Expand Down
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
playwright:
build:
context: .
dockerfile: ./playwright.Dockerfile
volumes:
- ./:/work/
- ./.yarn-playwright-cache:/.yarn-cache
working_dir: /work/
environment:
YARN_CACHE_FOLDER: /.yarn-cache
6 changes: 6 additions & 0 deletions playwright.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM mcr.microsoft.com/playwright:v1.33.0-focal

RUN apt-get update && apt-get install -y build-essential

CMD [ "bash" ]

1 change: 1 addition & 0 deletions test/visual/components/fixture/toolpad/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.generated
20 changes: 20 additions & 0 deletions test/visual/components/fixture/toolpad/components/MyComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
import { Typography } from '@mui/material';
import { createComponent } from '@mui/toolpad/browser';

export interface MyComponentProps {
msg: string;
}

function myComponent({ msg }: MyComponentProps) {
return <Typography>custom component {msg}</Typography>;
}

export default createComponent(myComponent, {
argTypes: {
msg: {
typeDef: { type: 'string' },
defaultValue: '',
},
},
});
79 changes: 79 additions & 0 deletions test/visual/components/fixture/toolpad/pages/components/page.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
apiVersion: v1
kind: page
spec:
id: f703ps3
title: components
content:
- component: PageRow
name: pageRow3
children:
- component: Button
name: button
props:
content: foo button
- component: PageRow
name: pageRow4
children:
- component: Image
name: image
props:
alt: foo image
- component: PageRow
name: pageRow
children:
- component: codeComponent.MyComponent
name: codeComponent_eb03t9a
props:
msg: "1"
- component: PageRow
name: pageRow5
children:
- component: DataGrid
name: dataGrid
props:
rows:
- id: 1
foo datagrid column: bar
columns:
- type: number
field: id
- type: string
field: foo datagrid column
- component: PageRow
name: pageRow6
children:
- component: TextField
name: textField
props:
label: foo textfield
- component: PageRow
name: pageRow7
children:
- component: Text
name: typography1
props:
value: foo typography
- component: PageRow
name: pageRow8
children:
- component: Select
name: select
props:
label: foo select
- component: PageRow
name: pageRow9
children:
- component: List
name: list
props:
renderItem:
$$template:
- component: PageRow
name: pageRow2
children:
- component: Button
name: button1
props:
content:
$$jsExpression: |
`List Button ${i + 1}`
33 changes: 33 additions & 0 deletions test/visual/components/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as path from 'path';
import { ToolpadEditor } from '../../models/ToolpadEditor';
import { ToolpadRuntime } from '../../models/ToolpadRuntime';
import { test, expect } from '../../playwright/localTest';
import clickCenter from '../../utils/clickCenter';

test.use({
localAppConfig: {
template: path.resolve(__dirname, './fixture'),
cmd: 'dev',
},
});

test('rendering components in the app runtime', async ({ page }) => {
const runtimeModel = new ToolpadRuntime(page);
await runtimeModel.gotoPage('components');

await expect(page).toHaveScreenshot({ fullPage: true });
});

test('rendering components in the app editor', async ({ page }) => {
const editorModel = new ToolpadEditor(page);
await editorModel.goto();

await editorModel.waitForOverlay();

await expect(page).toHaveScreenshot('no-selection.png');

const image = editorModel.appCanvas.locator('img').first();

await clickCenter(page, image);
await expect(page).toHaveScreenshot('with-selection.png');
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.