test: add failing TDD test for system time checkbox behavior

This commit is contained in:
Loic Coenen
2026-06-25 09:04:06 +02:00
committed by Loic Coenen (aider)
parent d33c434fe9
commit 261c978037
2 changed files with 60 additions and 14 deletions

View File

@@ -213,26 +213,31 @@ describe("Berlin Clock", () => {
describe("Use System Time", () => {
it("should show system time when checkbox is checked", () => {
// Start by entering a fixed time
cy.get('[data-testid="time-input"]').clear().type("12:00:00").type("{enter}");
cy.get('[data-testid="time-input"]')
.clear()
.type("12:00:00")
.type("{enter}");
cy.get('[data-testid="digital-clock"]').should("contain", "12:00:00");
// Check the "Use system time" checkbox
cy.get('[data-testid="use-system-time"]').check();
// Now the digital clock should reflect the real system time
cy.get('[data-testid="digital-clock"]').invoke("text").then((displayedTime) => {
// displayedTime is "HH:mm:ss"
const parts = displayedTime.split(":");
const displayedSeconds =
parseInt(parts[0]) * 3600 +
parseInt(parts[1]) * 60 +
parseInt(parts[2]);
const now = new Date();
const realSeconds =
now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds();
// Allow a 5-second tolerance
expect(Math.abs(displayedSeconds - realSeconds)).to.be.lessThan(5);
});
cy.get('[data-testid="digital-clock"]')
.invoke("text")
.then((displayedTime) => {
// displayedTime is "HH:mm:ss"
const parts = displayedTime.split(":");
const displayedSeconds =
parseInt(parts[0]) * 3600 +
parseInt(parts[1]) * 60 +
parseInt(parts[2]);
const now = new Date();
const realSeconds =
now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds();
// Allow a 5-second tolerance
expect(Math.abs(displayedSeconds - realSeconds)).to.be.lessThan(5);
});
});
});
});