Skip to content

Commit

Permalink
Merge pull request #32 from betagouv/improve-description-test
Browse files Browse the repository at this point in the history
Améliore le test des descriptions
  • Loading branch information
EmileRolley authored Jan 1, 2025
2 parents 0a37051 + 34b1b3a commit a81bcc2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-peaches-sing.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/rules/aides.publicodes
Original file line number Diff line number Diff line change
Expand Up @@ -9064,6 +9064,8 @@ aides . montmorillon:
aides . monaco:
remplace: commune
titre: Monaco
description: >
Monaco subventionne l'achat d'un vélo électrique neuf.
applicable si:
toutes ces conditions:
- vélo . électrique
Expand Down
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");
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 a81bcc2

Please sign in to comment.