A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!
TypeScript agent-skillsaidsh-pluginhacktoberfestjavascriptmcp-serverreactresume-builderself-hostedtypescript
import { describe, expect, it } from "vite-plus/test";
import { sortSectionItemsByPeriod } from "./section-sort";
type Item = {
id: string;
period: string;
};
const item = (id: string, period: string): Item => ({ id, period });
const ids = (items: readonly Item[]) => items.map(({ id }) => id);
describe("sortSectionItemsByPeriod", () => {
it("orders ongoing, ended, equal, and unresolved periods by the documented total order", () => {
const equalFirst = item("equal-first", "2020 - 2023");
const equalSecond = item("equal-second", "2020 - 2023");
const input = [
item("blank", ""),
equalFirst,
item("ended-2024", "2020 - 2024"),
item("ongoing-2020", "2020 - Present"),
item("prose", "A long time ago"),
item("ended-2025", "2022 - 2025"),
equalSecond,
item("ongoing-2024", "January 2024 - Present"),
item("reversed", "2025 - 2024"),
];
const result = sortSectionItemsByPeriod(input, "en-US");
expect(ids(result.items)).toEqual([
"ongoing-2024",
"ongoing-2020",
"ended-2025",
"ended-2024",
"equal-first",
"equal-second",
"blank",
"prose",
"reversed",
]);
expect(result.unresolvedIds).toEqual(["blank", "prose", "reversed"]);
});
it("uses locale-aware months and ranks year precision below a known month in the same year", () => {
const input = [
item("year-only-end", "2020 - 2024"),
item("localized-march", "janvier 2020 - mars 2024"),
item("localized-february", "janvier 2020 - février 2024"),
];
const result = sortSectionItemsByPeriod(input, "fr-FR");
expect(ids(result.items)).toEqual(["localized-march", "localized-february", "year-only-end"]);
expect(result.unresolvedIds).toEqual([]);
});
it("ranks missing end points after known end points, then compares known starts", () => {
const input = [item("single-2025", "2025"), item("ended-2020", "2019 - 2020"), item("single-2024", "2024")];
const result = sortSectionItemsByPeriod(input, "en-US");
expect(ids(result.items)).toEqual(["ended-2020", "single-2025", "single-2024"]);
});
});