1
18import { test, expect } from "../fixtures";
19
20test.describe("Confluence P2 — search sorts (T-155)", () => {
21 test("the /search page offers a sort control; selecting it is reflected in the URL", async ({
22 authPage,
23 freshWorkspace,
24 }) => {
25 const ws = await freshWorkspace("Search Sort Space");
26 await authPage.goto(`/w/${ws.id}/search`);
27
28 const sort = authPage.getByTestId("search-sort");
29 await expect(sort).toBeVisible();
30
31 await expect(sort.locator("option")).toHaveCount(3);
32 expect(await sort.locator("option").allInnerTexts()).toEqual([
33 "Relevance",
34 "Newest",
35 "Recently updated",
36 ]);
37
38 expect(authPage.url()).not.toContain("sort=");
39
40
41 await sort.selectOption("createdAt");
42 await authPage.waitForURL(/sort=createdAt/, { timeout: 10_000 });
43
44
45 await sort.selectOption("updatedAt");
46 await authPage.waitForURL(/sort=updatedAt/, { timeout: 10_000 });
47
48
49 await sort.selectOption("relevance");
50 await authPage.waitForURL((u) => !u.toString().includes("sort="), { timeout: 10_000 });
51 });
52
53 test("API accepts sortBy (200 for the three modes, 400 for an unknown value)", async ({
54 api,
55 freshWorkspace,
56 }) => {
57 const ws = await freshWorkspace("Search Sort API Space");
58 for (const sortBy of ["relevance", "createdAt", "updatedAt"]) {
59 const res = await api.post("/api/v1/search", {
60 data: { q: "sort probe", workspaceId: ws.id, sortBy },
61 });
62 expect(res.status(), `sortBy=${sortBy} should be 200`).toBe(200);
63 }
64
65 const bad = await api.post("/api/v1/search", {
66 data: { q: "sort probe", workspaceId: ws.id, sortBy: "not-a-sort" },
67 });
68 expect(bad.status()).toBe(400);
69 });
70});
71