|
1 | 1 | # Web Testing |
2 | 2 |
|
3 | | -DiracX Web uses a layered testing approach to ensure reliability at different levels of the application. |
| 3 | +DiracX Web uses a layered testing strategy where each layer builds on the previous one: |
| 4 | + |
| 5 | +1. **Storybook** illustrates shared and public components that extensions can import |
| 6 | +2. **Jest tests** verify that those stories render correctly and stay up to date |
| 7 | +3. **E2E tests** ensure essential user interactions work end-to-end |
4 | 8 |
|
5 | 9 | ## Testing layers |
6 | 10 |
|
7 | | -### Component tests (Jest + React Testing Library) |
| 11 | +### Storybook (visual documentation and component showcase) |
8 | 12 |
|
9 | | -Unit and integration tests for individual React components. These tests run in a simulated DOM environment (jsdom) and verify that components render correctly, handle user interactions, and manage state properly. |
| 13 | +[Storybook](https://storybook.js.org/) is the foundation of the testing strategy. Each shared or public component that extensions can import should have a corresponding story. Stories serve as living documentation, showing how components look and behave with different props, states, and edge cases. |
10 | 14 |
|
11 | 15 | ```bash |
12 | | -npm run test:diracx-web-components |
| 16 | +npm run doc:diracx-web-components |
13 | 17 | ``` |
14 | 18 |
|
15 | | -Tests live alongside their components in `packages/diracx-web-components/test/`. |
| 19 | +Stories live in `packages/diracx-web-components/stories/`. |
16 | 20 |
|
17 | | -**When to use**: Testing component rendering, props handling, user interactions, hooks, and context behavior. |
| 21 | +**What to document**: All reusable components exported by `diracx-web-components` — default states, loading/error/empty states, and key variations. |
18 | 22 |
|
19 | | -### End-to-end tests (Cypress) |
| 23 | +### Component tests (Jest + React Testing Library) |
20 | 24 |
|
21 | | -Full application tests that run in a real browser against a running DiracX backend. These tests simulate real user workflows including authentication, navigation, and data operations. |
| 25 | +Jest tests import and render the Storybook stories using `composeStories()` from `@storybook/react`. This ensures that the stories themselves are valid and that the components they illustrate work correctly. If a story breaks, the corresponding Jest test will catch it. |
22 | 26 |
|
23 | 27 | ```bash |
24 | | -export DIRACX_URL=<diracx-backend-url> |
25 | | -npm run --prefix packages/diracx-web test |
| 28 | +npm run test:diracx-web-components |
26 | 29 | ``` |
27 | 30 |
|
28 | | -Tests live in `packages/diracx-web/cypress/`. |
| 31 | +Tests live in `packages/diracx-web-components/test/`. |
29 | 32 |
|
30 | | -**When to use**: Testing complete user flows, authentication, API integration, and cross-component interactions. |
| 33 | +**What to test**: That stories render without errors, that key elements are present in the DOM, and that basic interactions (clicks, form inputs) produce the expected results. |
31 | 34 |
|
32 | | -### Visual documentation (Storybook) |
| 35 | +### End-to-end tests (Cypress) |
33 | 36 |
|
34 | | -While not a testing tool per se, [Storybook](https://storybook.js.org/) serves as a visual verification layer. Each component story acts as a living example that can be visually inspected and interacted with. |
| 37 | +E2E tests run in a real browser against a running DiracX backend. They verify that essential user workflows work correctly across the full stack — authentication, navigation, data display, and user actions. |
35 | 38 |
|
36 | 39 | ```bash |
37 | | -npm run doc:diracx-web-components |
| 40 | +export DIRACX_URL=<diracx-backend-url> |
| 41 | +npm run --prefix packages/diracx-web test |
38 | 42 | ``` |
39 | 43 |
|
40 | | -Stories live in `packages/diracx-web-components/stories/`. |
| 44 | +Tests live in `packages/diracx-web/test/e2e/`. |
41 | 45 |
|
42 | | -**When to use**: Documenting component variations, verifying visual appearance, and enabling manual exploratory testing. |
| 46 | +**What to test**: Critical user flows such as logging in, filtering and sorting data, performing actions on jobs, and verifying that interactive features (e.g., clicking a pie chart slice updates the search bar and table) work end-to-end. |
43 | 47 |
|
44 | | -## What to test at each level |
| 48 | +## How the layers connect |
45 | 49 |
|
46 | | -| Level | Scope | Speed | Examples | |
47 | | -|-------|-------|-------|----------| |
48 | | -| Component (Jest) | Single component or hook | Fast | Button renders correctly, form validates input | |
49 | | -| E2E (Cypress) | Full user workflow | Slow | User logs in, submits a job, views results | |
50 | | -| Visual (Storybook) | Component appearance | Manual | Theme variations, responsive layouts | |
| 50 | +| Layer | Purpose | Speed | Depends on | |
| 51 | +|-------|---------|-------|------------| |
| 52 | +| Storybook | Document components for extension developers | Manual | Mocks only | |
| 53 | +| Jest | Verify stories render and behave correctly | Fast | Storybook stories | |
| 54 | +| Cypress | Verify essential user workflows | Slow | Running backend | |
51 | 55 |
|
52 | 56 | ## Guidelines |
53 | 57 |
|
54 | | -- Write component tests for all new components and hooks |
55 | | -- Add Storybook stories for reusable UI components |
56 | | -- Add E2E tests for critical user workflows |
| 58 | +- Add Storybook stories for all shared/public components exported by `diracx-web-components` |
| 59 | +- Write Jest tests that render the stories via `composeStories()` to keep stories and tests in sync |
| 60 | +- Add E2E tests for critical user workflows and cross-component interactions |
57 | 61 | - Use [Jest coverage reports](https://jestjs.io/docs/code-coverage) to identify untested code |
0 commit comments