feat(drivers): country flag before the driver's name in timing, overlay, results, printouts and PDF (1.89.20)
This commit is contained in:
1 parent
da20a7e978
commit
6e45918e74
101 files changed
+2898
-45
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { existsSync } from "node:fs";
|
||||
import { COUNTRIES, countryCode, countryName, flagHtml, driverCountryCode } from "../src/country_flags.js";
|
||||
|
||||
test("a driver's country: name, English name, code or 3-letter code all give the flag", () => {
|
||||
for (const value of ["Sverige", "sweden", "SE", "SWE", " sverige "]) assert.equal(countryCode(value), "SE", value);
|
||||
assert.equal(countryCode("Norge"), "NO");
|
||||
assert.equal(countryCode("GBR"), "GB");
|
||||
assert.equal(countryName("NOR", "sv"), "Norge");
|
||||
assert.equal(countryName("NO", "en"), "Norway");
|
||||
});
|
||||
|
||||
test("no country, or an unknown one: no flag", () => {
|
||||
assert.equal(flagHtml(""), "");
|
||||
assert.equal(flagHtml("Atlantis"), "");
|
||||
assert.match(flagHtml("Sverige"), /<img class="country-flag" src="\/src\/flags\/se\.svg" alt="SE" title="Sverige"/);
|
||||
});
|
||||
|
||||
test("every country in the list has its flag file in the repo", () => {
|
||||
for (const [code] of COUNTRIES) assert.ok(existsSync(new URL(`../src/flags/${code.toLowerCase()}.svg`, import.meta.url)), code);
|
||||
});
|
||||
|
||||
test("the same person in another class: the country only has to be set once", () => {
|
||||
const drivers = [{ id: "a", profileId: "p", country: "Norge" }, { id: "b", profileId: "p", country: "" }, { id: "c", profileId: "q" }];
|
||||
assert.equal(driverCountryCode(drivers, "b"), "NO");
|
||||
assert.equal(driverCountryCode(drivers, "c"), "");
|
||||
assert.equal(driverCountryCode(drivers, "missing"), "");
|
||||
});
|
||||
@@ -71,3 +71,9 @@ test("practice ranked on 3 laps in a row: only result, gap and best lap as times
|
||||
assert.match(html, /class="overlay-prediction"/, "the next-lap bar stays");
|
||||
for (const gone of ["table.laps", "table.ahead_gap", "table.own_delta"]) assert.doesNotMatch(html, new RegExp(gone.replace(".", "\\.")), gone);
|
||||
});
|
||||
|
||||
test("a driver's country: a small local flag before the name on the overlay; none without a country", () => {
|
||||
const withFlag = renderOverlayLeaderboard([{ key: "a", driverId: "a", displayName: "Roy", countryCode: "NO", laps: 3, resultDisplay: "-", bestLapMs: 17500 }], deps);
|
||||
assert.match(withFlag, /<img class="country-flag" src="\/src\/flags\/no\.svg"[^>]*\/>Roy/);
|
||||
assert.doesNotMatch(renderOverlayLeaderboard(rows(1), deps), /country-flag/);
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { createRequire } from "node:module";
|
||||
import { COUNTRIES } from "../src/country_flags.js";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const { buildStyledPdf } = require("../server/pdf_render.js");
|
||||
const { PDF_FLAG_CODES } = require("../server/pdf_flags.js");
|
||||
|
||||
const pdf = (flags) => buildStyledPdf({ title: "Final", filename: "x.pdf", theme: "classic", sections: [{ title: "A-final", headers: ["Pos", "Förare", "Resultat"], rows: [["1", "Anders Larsson", "20/5:01"], ["2", "Roy Gjemble", "20/5:04"], ["3", "Kim Lee", "19/5:00"]], flags }] }).toString("latin1");
|
||||
|
||||
test("PDF: a driver's flag is drawn before the name; no country, no flag", () => {
|
||||
const sweden = "0.000 0.416 0.655 rg"; // #006aa7
|
||||
const norway = "0.729 0.047 0.184 rg"; // #ba0c2f
|
||||
const withFlags = pdf(["SE", "NO", ""]);
|
||||
assert.ok(withFlags.includes(sweden), "Swedish blue");
|
||||
assert.ok(withFlags.includes(norway), "Norwegian red");
|
||||
assert.ok(!pdf([]).includes(sweden), "no flags sent: none drawn");
|
||||
});
|
||||
|
||||
test("PDF: a country without a drawn flag shows its code instead", () => {
|
||||
assert.match(pdf(["GB", "", ""]), /\(GB\) Tj/);
|
||||
});
|
||||
|
||||
test("every flag the PDF draws is a country the app knows", () => {
|
||||
const known = new Set(COUNTRIES.map(([code]) => code));
|
||||
for (const code of PDF_FLAG_CODES) assert.ok(known.has(code), code);
|
||||
});
|
||||
@@ -54,3 +54,5 @@ import "./sync_status.test.js";
|
||||
import "./decoder_diagnostics.test.js";
|
||||
import "./pdf_render.test.js";
|
||||
import "./driver_list.test.js";
|
||||
import "./country_flags.test.js";
|
||||
import "./pdf_flags.test.js";
|
||||
Reference in new issue
Block a user