import { isNewerVersion, parseVersion } from "../../src/features/app-update/version-compare"; // Pure logic, no DOM/mount needed — same posture as highlight-tech-steps.cy.tsx: // reuses the component-test runner (Cypress's Mocha/Chai) purely for `expect`. // `.cy.tsx` (not `.cy.ts`) only because that's what cypress.config.ts's // component `specPattern` looks for. describe("parseVersion", () => { it("parses a v-prefixed tag into its three integer components", () => { expect(parseVersion("v1.4.2")).to.deep.equal({ major: 1, minor: 4, patch: 2 }); }); it("also accepts a bare X.Y.Z string (no leading v)", () => { expect(parseVersion("1.4.2")).to.deep.equal({ major: 1, minor: 4, patch: 2 }); }); it("returns null for anything that doesn't match exactly", () => { expect(parseVersion("")).to.be.null; expect(parseVersion("not-a-version")).to.be.null; expect(parseVersion("v1.4")).to.be.null; expect(parseVersion("v1.4.2-beta")).to.be.null; }); }); describe("isNewerVersion", () => { it("is true when the major version is higher", () => { expect(isNewerVersion("1.4.2", "v2.0.0")).to.be.true; }); it("is true when the minor version is higher, major equal", () => { expect(isNewerVersion("1.4.2", "v1.5.0")).to.be.true; }); it("is true when only the patch version is higher", () => { expect(isNewerVersion("1.4.2", "v1.4.3")).to.be.true; }); it("is false for the exact same version", () => { expect(isNewerVersion("1.4.2", "v1.4.2")).to.be.false; }); it("is false when the candidate is actually older", () => { expect(isNewerVersion("1.4.2", "v1.4.1")).to.be.false; expect(isNewerVersion("2.0.0", "v1.9.9")).to.be.false; }); it("fails closed (false) when either side doesn't parse", () => { expect(isNewerVersion("1.0", "v2.0.0")).to.be.false; expect(isNewerVersion("1.0.0", "not-a-tag")).to.be.false; }); });