diff --git a/web-app/cypress/e2e/serie.cy.ts b/web-app/cypress/e2e/serie.cy.ts new file mode 100644 index 0000000..a52e072 --- /dev/null +++ b/web-app/cypress/e2e/serie.cy.ts @@ -0,0 +1,132 @@ +/// + +import { Serie } from "../../src/Measures/Serie"; +import { TEMPERATURE, HUMIDITY } from "../../src/const"; +import { Colors } from "../../src/Measures/Utils"; + +describe("Serie Component Tests", () => { + // Mock data for tests + const mockDataTemperature = [ + { time: 1625097600000, value: new Date(22.5) }, + { time: 1625184000000, value: new Date(23.8) }, + ]; + + const mockDataHumidity = [ + { time: 1625097600000, value: new Date(45) }, + { time: 1625184000000, value: new Date(48) }, + ]; + + it("should initialize with correct properties", () => { + // Create a new Serie instance + const serie = new Serie( + TEMPERATURE, + mockDataTemperature, + "user1", + "bedroom", + "sensor1" + ); + + // Verify that it has the correct type + expect(serie).to.be.instanceOf(Serie); + }); + + it("should return the correct label for temperature", () => { + const serie = new Serie( + TEMPERATURE, + mockDataTemperature, + "user1", + "bedroom", + "sensor1" + ); + + expect(serie.getLabel()).to.equal("Temperature [°C]"); + }); + + it("should return the correct label for humidity", () => { + const serie = new Serie( + HUMIDITY, + mockDataHumidity, + "user1", + "bedroom", + "sensor1" + ); + + expect(serie.getLabel()).to.equal("Humidity [%]"); + }); + + it("should return 'Unknown' label for unknown type", () => { + const serie = new Serie( + "UNKNOWN_TYPE", + mockDataTemperature, + "user1", + "bedroom", + "sensor1" + ); + + expect(serie.getLabel()).to.equal("Unknown"); + }); + + it("should format temperature data correctly with getSerie()", () => { + const serie = new Serie( + TEMPERATURE, + mockDataTemperature.map((item) => ({ + time: item.time, + value: new Date(item.value), + })), + "user1", + "bedroom", + "sensor1" + ); + + const result = serie.getSerie(); + + // Verify the properties of the formatted data + expect(result).to.have.property("label", "Temperature [°C]"); + expect(result).to.have.property("borderColor", Colors.BLUE); + expect(result).to.have.property("backgroundColor", Colors.BLUE); + expect(result).to.have.property("borderWidth", 1); + expect(result).to.have.property("yAxisID", TEMPERATURE); + + // Verify the data points + expect(result.data).to.have.length(mockDataTemperature.length); + expect(result.data[0]).to.have.property("x", mockDataTemperature[0].time); + expect(result.data[1]).to.have.property("x", mockDataTemperature[1].time); + }); + + it("should format humidity data correctly with getSerie()", () => { + const serie = new Serie( + HUMIDITY, + mockDataHumidity, + "user1", + "bedroom", + "sensor1" + ); + + const result = serie.getSerie(); + + // Verify the properties of the formatted data + expect(result).to.have.property("label", "Humidity [%]"); + expect(result).to.have.property("borderColor", Colors.GREEN); + expect(result).to.have.property("backgroundColor", Colors.GREEN); + expect(result).to.have.property("borderWidth", 1); + expect(result).to.have.property("yAxisID", HUMIDITY); + }); + + it("should handle unknown types appropriately in getSerie()", () => { + const serie = new Serie( + "UNKNOWN_TYPE", + mockDataTemperature, + "user1", + "bedroom", + "sensor1" + ); + + const result = serie.getSerie(); + + // Verify the properties for unknown type + expect(result).to.have.property("label", "Unknown"); + expect(result).to.have.property("borderColor", Colors.RED); + expect(result).to.have.property("backgroundColor", Colors.RED); + expect(result).to.have.property("yAxisID", TEMPERATURE); // Defaults to TEMPERATURE + }); +}); diff --git a/web-app/package.json b/web-app/package.json index 5143db1..a0a743a 100644 --- a/web-app/package.json +++ b/web-app/package.json @@ -7,9 +7,7 @@ "build": "vue-cli-service build", "cypress:open": "cypress open", "cypress:run": "cypress run", - "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" + "test": "cypress run --spec 'cypress/e2e/*.cy.ts'" }, "dependencies": { "axios": "^1.9.0",