Skip to content

Commit

Permalink
feat: improve description test
Browse files Browse the repository at this point in the history
  • Loading branch information
Shamzic committed Jan 1, 2025
1 parent 0a37051 commit 5d949d8
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions test/AidesVeloEngine.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Aide, AideRuleNames, AidesVeloEngine } from "../src";
import { Localisation } from "../src/data";
import { describe, expect, it } from "vitest";

describe("AidesVeloEngine", () => {
Expand Down Expand Up @@ -93,19 +94,24 @@ describe("AidesVeloEngine", () => {
});

it("should have a description", function () {
const engine = globalTestEngine.shallowCopy();
const allAides = engine.getAllAidesIn();
allAides.forEach((aide) => {
expect(typeof aide.description, 'Error description empty ' + aide.title).toBe("string")
const engine = globalTestEngine.shallowCopy();
const countries: Array<Localisation["country"]> = ["france", "monaco", "luxembourg"];

countries.forEach(country => {
const allAides = engine.getAllAidesIn(country);
allAides.forEach((aide) => {
expect(typeof aide.description, `Description should be a string for benefit: ${aide.title} (${country})`).toBe("string");

Check failure on line 103 in test/AidesVeloEngine.test.ts

View workflow job for this annotation

GitHub Actions / main

test/AidesVeloEngine.test.ts > AidesVeloEngine > getAllAidesIn() > should have a description

AssertionError: Description should be a string for benefit: Monaco (monaco): expected 'undefined' to be 'string' // Object.is equality Expected: "string" Received: "undefined" ❯ test/AidesVeloEngine.test.ts:103:115 ❯ test/AidesVeloEngine.test.ts:102:18 ❯ test/AidesVeloEngine.test.ts:100:15
expect(aide.description.length, `Description cannot be empty for benefit: ${aide.title} (${country})`).toBeGreaterThan(0);
const innerText = aide.description
.replace(/<\/?[^>]+>/gi, "")
.replace(/\s\s+/g, " ")
.trim()
expect(innerText.length).toBeGreaterThanOrEqual(10)
.trim();
expect(innerText.length, `Description must be at least 10 characters for benefit: ${aide.title} (${country})`).toBeGreaterThanOrEqual(10);
if (innerText.length > 420) {
console.warn(`Text length (${innerText.length}) exceeds maximum allowed length of 420 characters`);
console.warn(`Description text length (${innerText.length}) exceeds maximum allowed length of 420 characters for benefit: ${aide.title} (${country})`);
}
});
});
});
})

it("should return all aids in Luxembourg if specified", () => {
Expand Down

0 comments on commit 5d949d8

Please sign in to comment.