# 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 user’s and the developer’s 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. ### 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. ## Test in CI All test are covered by the CI pipeline. The unit tests are run on every commit and doesn't require any specific resources. The E2E tests are run too on every commit, but they require a test URL to be set in the environment variable `CYPRESS_TEST_URL` which provide an access to a test instance of the web-app. Actually, these tests are running on the test development instance at `https://app-dev.mse.kb28.ch/`.