mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-09-17 08:36:25 +00:00
56 lines
2.3 KiB
TypeScript
56 lines
2.3 KiB
TypeScript
import { describe, test, expect } from "bun:test";
|
|||
|
|
import { parseJobCards, parseJobDetail } from "../src/helpers";
|
||
|
|
|
||
|
|
// Minimal search-card markup: parseJobCards splits on the job-posting URN and
|
||
|
|
// needs an id, a base-search-card__title, and a full-link. Everything else is
|
||
|
|
// optional. We inject HTML entities into the title/company to exercise decoding.
|
||
|
|
function searchCard(id: string, title: string, company = "Acme"): string {
|
||
|
|
return `<li>
|
||
|
|
<div data-entity-urn="urn:li:jobPosting:${id}">
|
||
|
|
<a class="base-card__full-link" href="https://www.linkedin.com/jobs/view/${id}"></a>
|
||
|
|
<h3 class="base-search-card__title">${title}</h3>
|
||
|
|
<h4 class="base-search-card__subtitle"><a href="https://www.linkedin.com/company/acme">${company}</a></h4>
|
||
|
|
</div>
|
||
|
|
</li>`;
|
||
|
|
}
|
||
|
|
|
||
|
|
describe("decodeHtmlEntities (via parseJobCards)", () => {
|
||
|
|
test("decodes hexadecimal numeric entities (é)", () => {
|
||
|
|
const [card] = parseJobCards(searchCard("123", "Café Manager"));
|
||
|
|
expect(card.title).toBe("Café Manager");
|
||
|
|
});
|
||
|
|
|
||
|
|
test("decodes uppercase-X hexadecimal entities (&#X...;)", () => {
|
||
|
|
const [card] = parseJobCards(searchCard("124", "Debüt Role")); // ü = ü
|
||
|
|
expect(card.title).toBe("Debüt Role");
|
||
|
|
});
|
||
|
|
|
||
|
|
test("still decodes decimal numeric entities (é) — regression", () => {
|
||
|
|
const [card] = parseJobCards(searchCard("125", "Café Lead"));
|
||
|
|
expect(card.title).toBe("Café Lead");
|
||
|
|
});
|
||
|
|
|
||
|
|
test("decodes supplementary-plane code points with fromCodePoint (😀)", () => {
|
||
|
|
const [card] = parseJobCards(searchCard("126", "Growth 😀"));
|
||
|
|
expect(card.title).toBe("Growth 😀");
|
||
|
|
});
|
||
|
|
|
||
|
|
test("decodes hex supplementary-plane code points (😀)", () => {
|
||
|
|
const [card] = parseJobCards(searchCard("127", "Growth 😀"));
|
||
|
|
expect(card.title).toBe("Growth 😀");
|
||
|
|
});
|
||
|
|
|
||
|
|
test("decodes hex entities in the company subtitle too", () => {
|
||
|
|
const [card] = parseJobCards(searchCard("128", "Engineer", "Nørrebro ApS"));
|
||
|
|
expect(card.company).toBe("Nørrebro ApS");
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe("decodeHtmlEntities (via parseJobDetail)", () => {
|
||
|
|
test("decodes hex entities inside the job title", () => {
|
||
|
|
const html = `<h1 class="topcard__title">Señor Engineer</h1>`;
|
||
|
|
const job = parseJobDetail(html, "999");
|
||
|
|
expect(job.title).toBe("Señor Engineer");
|
||
|
|
});
|
||
|
|
});
|