Files
MSE-SoftwEng/web-app/test.md

79 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# End-to-End and Unit Testing Documentation for Home Monitor
## Test Description
The Home Monitor project uses Cypress to automate both End-to-End (E2E) and unit tests. These tests ensure that the main features of the application work correctly, both from the users and the developers perspectives.
### Types of Tests
- **End-to-End (E2E) Tests**: Simulate real user behavior on the web interface. They check critical user flows, data display, error handling, and the responsiveness of the application.
- **Unit Tests**: Verify the correct functioning of TypeScript components and functions in isolation.
### Test Structure
- E2E tests are located in `web-app/cypress/e2e/`
- Unit tests are located in `web-app/cypress/unit/`
- Custom commands and global setup are in `web-app/cypress/support/`
- Cypress configuration is in `web-app/cypress.config.ts`
## How to Run the Tests
### Install Dependencies
```bash
cd ./web-app
npm install --inlude=dev
```
### Before Running Tests
A test url is needed to perform the tests in local:
```bash
export CYPRESS_TEST_URL=http://your-test-url.com
```
Note: most of the time, if you are testing in local, you can use:
```bash
export CYPRESS_TEST_URL=http://localhost:8080/
```
### Run unit Tests
```bash
npm run test:unit
```
### Run E2E Tests
```bash
npm run test:e2e
```
### Run All Tests
```bash
npm run test
```
### Note
The cypress GUI can be launched with the command:
```bash
npx cypress open
```
## Test Coverage
### End-to-End (E2E) Tests
- **Fetch Measurements Button**:
- Verifies that the "Fetch Measurements" button is visible and functional on the main page.
- Tests fetching timeseries data with a valid user-room-device selection, ensuring the main chart is displayed and no "no data" message appears.
- Tests fetching timeseries data with an invalid user-room-device selection (e.g., changing the user to "Sylvan"), ensuring the main chart is not displayed and the "no data" message is shown.
#### Important Notes
The E2E tests use a web-app development image deployed on https://app.mse.kb28.ch/ for the moment. Because there is a problem with the service image in the CI. The environment variables cannot be set correctly to the job's service. An issue is opened to fix this problem: [#37].
### Unit Tests
- **Serie Component**:
- Checks that a `Serie` instance initializes with the correct properties.
- Validates that the correct label is returned for temperature and humidity types.
- Ensures the label "Unknown" is returned for unknown types.
- Verifies that temperature and humidity data are formatted correctly by `getSerie()`, including label, color, and data structure.
- Ensures unknown types are handled appropriately in `getSerie()`, defaulting to the correct color and axis.