Skip to content

Commit 1af83f9

Browse files
committed
test(web-awesome): add unit tests for defaultSortBy config option
1 parent 19b870c commit 1af83f9

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { epic, feature, label, story } from "allure-js-commons";
2+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3+
4+
const STORAGE_KEY = "ALLURE_REPORT_SORT_BY";
5+
6+
beforeEach(async () => {
7+
await epic("coverage");
8+
await feature("sort");
9+
await story("treeSort");
10+
await label("coverage", "sort");
11+
});
12+
13+
describe("stores > treeSort", () => {
14+
beforeEach(() => {
15+
vi.resetModules();
16+
localStorage.clear();
17+
delete (globalThis as any).allureReportOptions;
18+
});
19+
20+
it("defaults to order,asc when no config and no localStorage value", async () => {
21+
const { sortBy } = await import("../../src/stores/treeSort.js");
22+
23+
expect(sortBy.value).toBe("order,asc");
24+
});
25+
26+
it("uses defaultSortBy from reportOptions when localStorage is empty", async () => {
27+
(globalThis as any).allureReportOptions = { defaultSortBy: "name,asc" };
28+
29+
const { sortBy } = await import("../../src/stores/treeSort.js");
30+
31+
expect(sortBy.value).toBe("name,asc");
32+
});
33+
34+
it("is case-insensitive for defaultSortBy", async () => {
35+
(globalThis as any).allureReportOptions = { defaultSortBy: "Name,ASC" };
36+
37+
const { sortBy } = await import("../../src/stores/treeSort.js");
38+
39+
expect(sortBy.value).toBe("name,asc");
40+
});
41+
42+
it("ignores invalid defaultSortBy and falls back to order,asc", async () => {
43+
(globalThis as any).allureReportOptions = { defaultSortBy: "invalid,value" };
44+
45+
const { sortBy } = await import("../../src/stores/treeSort.js");
46+
47+
expect(sortBy.value).toBe("order,asc");
48+
});
49+
50+
it("localStorage takes priority over defaultSortBy from reportOptions", async () => {
51+
localStorage.setItem(STORAGE_KEY, "duration,desc");
52+
(globalThis as any).allureReportOptions = { defaultSortBy: "name,asc" };
53+
54+
const { sortBy } = await import("../../src/stores/treeSort.js");
55+
56+
expect(sortBy.value).toBe("duration,desc");
57+
});
58+
});

0 commit comments

Comments
 (0)