From bd503d564174891e04ce3ef8daa8ac617c3a2a70 Mon Sep 17 00:00:00 2001 From: fastium Date: Fri, 13 Jun 2025 19:45:13 +0200 Subject: [PATCH] test(web-app): add e2e fetch process It tests the normal request case of timeserie --- web-app/cypress.config.ts | 17 +- web-app/cypress.unit.js | 40 ----- web-app/cypress/e2e/fetch_process.cy.ts | 16 ++ web-app/cypress/fixtures/example.json | 5 + web-app/cypress/support/commands.ts | 37 ++++ web-app/cypress/support/e2e.ts | 17 ++ web-app/package.json | 4 +- web-app/src/components/ChartComponent.vue | 16 +- web-app/src/components/ControlPanel.vue | 11 +- web-app/tests/e2e/app.spec.ts | 196 ---------------------- web-app/tests/support/commands.ts | 73 -------- web-app/tests/support/e2e.ts | 11 -- web-app/tests/tests.md | 146 ---------------- web-app/tests/unit/Serie.spec.ts | 129 -------------- 14 files changed, 93 insertions(+), 625 deletions(-) delete mode 100644 web-app/cypress.unit.js create mode 100644 web-app/cypress/e2e/fetch_process.cy.ts create mode 100644 web-app/cypress/fixtures/example.json create mode 100644 web-app/cypress/support/commands.ts create mode 100644 web-app/cypress/support/e2e.ts delete mode 100644 web-app/tests/e2e/app.spec.ts delete mode 100644 web-app/tests/support/commands.ts delete mode 100644 web-app/tests/support/e2e.ts delete mode 100644 web-app/tests/tests.md delete mode 100644 web-app/tests/unit/Serie.spec.ts diff --git a/web-app/cypress.config.ts b/web-app/cypress.config.ts index 68d0dc3..17161e3 100644 --- a/web-app/cypress.config.ts +++ b/web-app/cypress.config.ts @@ -2,21 +2,8 @@ import { defineConfig } from "cypress"; export default defineConfig({ e2e: { - specPattern: "tests/e2e/*.spec.ts", - baseUrl: "http://localhost:8080", - supportFile: "tests/support/e2e.ts", - // Don't skip server checks - we want to ensure the app is running - // Wait up to 10 seconds for the server to be available - defaultCommandTimeout: 10000, - requestTimeout: 10000, - responseTimeout: 10000, - pageLoadTimeout: 30000, - }, - component: { - devServer: { - framework: "vue", - bundler: "webpack", + setupNodeEvents(on, config) { + // implement node event listeners here }, - specPattern: "src/**/*.cy.ts", }, }); diff --git a/web-app/cypress.unit.js b/web-app/cypress.unit.js deleted file mode 100644 index 0dca11f..0000000 --- a/web-app/cypress.unit.js +++ /dev/null @@ -1,40 +0,0 @@ -const { defineConfig } = require('cypress'); - -module.exports = defineConfig({ - // Shared settings for all test types - watchForFileChanges: false, - screenshotOnRunFailure: false, - video: false, - defaultCommandTimeout: 10000, - chromeWebSecurity: false, - retries: { - runMode: 2, - openMode: 0, - }, - - // E2E test configuration - e2e: { - specPattern: ['tests/e2e/*.spec.ts', 'tests/unit/*.spec.ts'], - baseUrl: null, // No baseUrl to prevent server checks in headless mode - supportFile: 'tests/support/e2e.ts', - experimentalRunAllSpecs: true, - testIsolation: false, // Allow shared context for unit tests - setupNodeEvents(on, config) { - // Disable baseUrl verification for headless testing - on('before:browser:launch', (browser, launchOptions) => { - return launchOptions; - }); - return config; - }, - }, - - // Component test configuration (for Vue components) - component: { - devServer: { - framework: 'vue', - bundler: 'webpack', - }, - specPattern: 'tests/unit/*.spec.ts', // Component tests are in unit directory - supportFile: 'tests/support/e2e.ts', - }, -}); diff --git a/web-app/cypress/e2e/fetch_process.cy.ts b/web-app/cypress/e2e/fetch_process.cy.ts new file mode 100644 index 0000000..8aaf42c --- /dev/null +++ b/web-app/cypress/e2e/fetch_process.cy.ts @@ -0,0 +1,16 @@ +/// + +describe("Test fetch measurments button in the main page", () => { + beforeEach(() => { + cy.visit("http://localhost:8080/"); + }); + + it("Fetch timeseries with valid user-room-device", () => { + cy.get('[data-cy="new-measurements-button"]').should("be.visible"); + // keep default mulitselector value for the test + cy.get('[data-cy="new-measurements-button"]').click(); + + cy.get('[data-cy="main-chart"]').should("be.visible"); + cy.get('[data-cy="no-data-display"]').should("not.exist"); + }); +}); diff --git a/web-app/cypress/fixtures/example.json b/web-app/cypress/fixtures/example.json new file mode 100644 index 0000000..02e4254 --- /dev/null +++ b/web-app/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/web-app/cypress/support/commands.ts b/web-app/cypress/support/commands.ts new file mode 100644 index 0000000..698b01a --- /dev/null +++ b/web-app/cypress/support/commands.ts @@ -0,0 +1,37 @@ +/// +// *********************************************** +// This example commands.ts shows you how to +// create various custom commands and overwrite +// existing commands. +// +// For more comprehensive examples of custom +// commands please read more here: +// https://on.cypress.io/custom-commands +// *********************************************** +// +// +// -- This is a parent command -- +// Cypress.Commands.add('login', (email, password) => { ... }) +// +// +// -- This is a child command -- +// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) +// +// +// -- This is a dual command -- +// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) +// +// +// -- This will overwrite an existing command -- +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) +// +// declare global { +// namespace Cypress { +// interface Chainable { +// login(email: string, password: string): Chainable +// drag(subject: string, options?: Partial): Chainable +// dismiss(subject: string, options?: Partial): Chainable +// visit(originalFn: CommandOriginalFn, url: string, options: Partial): Chainable +// } +// } +// } \ No newline at end of file diff --git a/web-app/cypress/support/e2e.ts b/web-app/cypress/support/e2e.ts new file mode 100644 index 0000000..e4e246e --- /dev/null +++ b/web-app/cypress/support/e2e.ts @@ -0,0 +1,17 @@ +// *********************************************************** +// This example support/e2e.ts is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// Import commands.js using ES2015 syntax: +import './commands' \ No newline at end of file diff --git a/web-app/package.json b/web-app/package.json index 0a4bc86..5143db1 100644 --- a/web-app/package.json +++ b/web-app/package.json @@ -7,8 +7,8 @@ "build": "vue-cli-service build", "cypress:open": "cypress open", "cypress:run": "cypress run", - "test:unit": "cypress run --config-file cypress.unit.js --spec 'tests/unit/*.spec.ts'", - "test:e2e": "cypress run --spec 'tests/e2e/*.spec.ts'", + "test:unit": "cypress run --config-file cypress.unit.ts --spec 'cypress/unit/*.cy.ts'", + "test:e2e": "cypress run --spec 'cypress/e2e/*.cy.ts'", "test": "npm run test:unit && npm run test:e2e" }, "dependencies": { diff --git a/web-app/src/components/ChartComponent.vue b/web-app/src/components/ChartComponent.vue index ff4ac4a..30b0869 100644 --- a/web-app/src/components/ChartComponent.vue +++ b/web-app/src/components/ChartComponent.vue @@ -1,16 +1,10 @@ diff --git a/web-app/src/components/ControlPanel.vue b/web-app/src/components/ControlPanel.vue index f12fe36..f21f4a5 100644 --- a/web-app/src/components/ControlPanel.vue +++ b/web-app/src/components/ControlPanel.vue @@ -1,10 +1,14 @@