129 lines
3.7 KiB
TypeScript
129 lines
3.7 KiB
TypeScript
/// <reference types="cypress" />
|
|
|
|
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
|
|
});
|
|
}); |