|
| 1 | +# 1. Setup |
| 2 | + |
| 3 | +## 1.a. get the boilerplate |
| 4 | + |
| 5 | +```sh |
| 6 | +git checkout ut-15-visual-regression-testing-boilerplate |
| 7 | + |
| 8 | +yarn |
| 9 | +``` |
| 10 | + |
| 11 | +## 1.b. or if you like adventures |
| 12 | + |
| 13 | +1. Create library with storybook. |
| 14 | + |
| 15 | +```sh |
| 16 | +# Create a library. |
| 17 | +yarn nx g @nrwl/angular:library animal-ui |
| 18 | + |
| 19 | +# Install Nx Storybook plugin. |
| 20 | +yarn add -D @nrwl/storybook |
| 21 | + |
| 22 | +# Setup storybook & cypress. |
| 23 | +yarn nx g storybook-configuration animal-ui --configure-cypress --no-generate-stories --no-generate-cypress-specs |
| 24 | +``` |
| 25 | + |
| 26 | +2. Setup `cypress-image-snapshot` _(Cf. https://github.com/palmerhq/cypress-image-snapshot#installation)_ |
| 27 | + |
| 28 | +3. Set image snapshots folder in `support/commands.ts`. |
| 29 | + |
| 30 | +```typescript |
| 31 | +addMatchImageSnapshotCommand({ |
| 32 | + customSnapshotsDir: 'src/snapshots', |
| 33 | +}); |
| 34 | +``` |
| 35 | + |
| 36 | +4. Fix viewport size in `cypress.json`. |
| 37 | + |
| 38 | +```json |
| 39 | +{ |
| 40 | + ... |
| 41 | + "viewportHeight": 768, |
| 42 | + "viewportWidth": 1024 |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +# 2. Run tests |
| 47 | + |
| 48 | +```sh |
| 49 | +yarn e2e animal-ui-e2e --watch |
| 50 | +``` |
| 51 | + |
| 52 | +# 3. Open Storybook |
| 53 | + |
| 54 | +Watch your changes on http://localhost:4400 |
| 55 | + |
| 56 | +# 4. Create `<fz-animal-preview>` |
| 57 | + |
| 58 | +1. Add an `animal` input. |
| 59 | + |
| 60 | +2. Add Storybook knobs in `animal-preview.stories.ts`. |
| 61 | + |
| 62 | +```typescript |
| 63 | +import { text, ... } from '@storybook/addon-knobs'; |
| 64 | + |
| 65 | +export const main = () => ({ |
| 66 | + ... |
| 67 | + props: { |
| 68 | + name: text('name', 'Dolly') |
| 69 | + } |
| 70 | +}); |
| 71 | +``` |
| 72 | + |
| 73 | +3. Display a card with a different icon depending on animal type. |
| 74 | + |
| 75 | +4. Show price if present. |
| 76 | + |
| 77 | +# 5. Add a visual snapshot to test animals without price |
| 78 | + |
| 79 | +You can control knobs by adding `knob-x=y` to the query string. |
0 commit comments