1import { raiseTicket } from "../../../helpers/factories";
2import { expect, test, uid, usePersona } from "../../../helpers/fixtures";
3import { TicketList, resetDefaultTicketView } from "../../../helpers/list";
4import { personas } from "../../../helpers/personas";
5
6usePersona("manager");
7
8test.afterEach(async ({ api }) => {
9 await resetDefaultTicketView(api, personas.manager.email);
10});
11
12test("a saved view can be pinned and unpinned, made public and deleted", async ({
13 page,
14 api,
15}) => {
16 const label = `E2E view ${uid()}`;
17 const list = new TicketList(page);
18 await list.goto();
19 await list.searchSubject(label);
20 const view = await list.createView(api, label);
21 expect((await api.get("OD View", view)).filters).toContain(label);
22 const saved = (field: string) => async () => (await api.get("OD View", view))[field];
23
24 const sidebar = page.getByRole("navigation", { name: "Main" });
25 await list.viewAction(label, "Pin View");
26 await expect(sidebar.getByRole("button", { name: label })).toBeVisible();
27 await expect.poll(saved("pinned")).toBe(1);
28 await list.viewAction(label, "Unpin View");
29 await expect.poll(saved("pinned")).toBe(0);
30
31 await list.viewAction(label, "Make Public");
32 await expect.poll(saved("public")).toBe(1);
33
34 await list.viewAction(label, "Delete");
35 await page.getByRole("dialog").getByRole("button", { name: "Confirm" }).click();
36 await expect.poll(() => api.exists("OD View", { label })).toBeUndefined();
37 await expect(sidebar.getByRole("button", { name: label })).toHaveCount(0);
38});
39
40test("changing a view's filters and saving them sticks when it is reopened", async ({
41 page,
42 api,
43 apiAs,
44}) => {
45 const token = uid();
46 const customer = await apiAs("customer");
47 const first = await raiseTicket(customer, `E2E first ${token}`);
48 const second = await raiseTicket(customer, `E2E second ${token}`);
49 const label = `E2E view ${token}`;
50 const list = new TicketList(page);
51 await list.goto();
52 await list.searchSubject(first.subject);
53 const view = await list.createView(api, label);
54
55 await list.searchSubject(second.subject);
56 await page.getByRole("button", { name: "Save Changes" }).click();
57 await expect.poll(async () => (await api.get("OD View", view)).filters).toContain(second.subject);
58
59 await list.goto();
60 await page.goto(`/opendesk/tickets?view=${view}`);
61 await expect(list.row(second.subject)).toBeVisible();
62 await expect(list.row(first.subject)).toHaveCount(0);
63});
64
65test("a view can be duplicated and renamed", async ({ page, api }) => {
66 const label = `E2E view ${uid()}`;
67 const list = new TicketList(page);
68 await list.goto();
69 await list.searchSubject(label);
70 const original = await list.createView(api, label);
71
72 await list.viewAction(label, "Duplicate");
73 const duplicate = page.getByRole("dialog", { name: "Duplicate View" });
74 await expect(duplicate.getByRole("textbox").first()).toHaveValue(`${label} (New)`);
75 await duplicate.getByRole("button", { name: "Duplicate" }).click();
76 await expect.poll(() => api.exists("OD View", { label: `${label} (New)` })).toBeTruthy();
77 const copy = (await api.exists("OD View", { label: `${label} (New)` }))!;
78 expect((await api.get("OD View", copy)).filters).toBe((await api.get("OD View", original)).filters);
79
80 const renamed = `E2E view ${uid()} renamed`;
81 await list.viewAction(label, "Edit");
82 const edit = page.getByRole("dialog", { name: "Edit View" });
83 await edit.getByRole("textbox").first().fill(renamed);
84 await edit.getByRole("button", { name: "Update" }).click();
85 await expect.poll(async () => (await api.get("OD View", original)).label).toBe(renamed);
86});
87
88test("public views reach other agents and private ones do not", async ({
89 page,
90 api,
91 pageAs,
92}) => {
93 const label = `E2E view ${uid()}`;
94 const list = new TicketList(page);
95 await list.goto();
96 await list.searchSubject(label);
97 const view = await list.createView(api, label);
98 const agentSees = async () => {
99 const agentPage = await pageAs("agent");
100 await new TicketList(agentPage).goto();
101 await agentPage.getByRole("banner").getByRole("button", { name: "List", exact: true }).click();
102 const count = await agentPage.getByRole("menuitem", { name: label }).count();
103 await agentPage.close();
104 return count;
105 };
106
107 expect(await agentSees()).toBe(0);
108 await list.viewAction(label, "Make Public");
109 await expect.poll(async () => (await api.get("OD View", view)).public).toBe(1);
110 expect(await agentSees()).toBe(1);
111
112 await list.viewAction(label, "Make Private");
113 await page.getByRole("dialog").getByRole("button", { name: "Confirm" }).click();
114 await expect.poll(async () => (await api.get("OD View", view)).public).toBe(0);
115 expect(await agentSees()).toBe(0);
116});
117
118test("a standard view can be hidden from and shown in the sidebar", async ({ page, api }) => {
119 const standard = (await api.list("OD View", {
120 fields: ["name", "label"],
121 filters: { is_standard: 1, public: 1, dt: "OD Ticket" },
122 limit: 1,
123 }))[0];
124 const sidebar = page.getByRole("navigation", { name: "Main" });
125 const list = new TicketList(page);
126 try {
127 await list.goto();
128 await expect(sidebar.getByRole("button", { name: standard.label })).toBeVisible();
129
130 await list.viewAction(standard.label, "Hide from sidebar");
131 await page.getByRole("dialog").getByRole("button", { name: "Confirm" }).click();
132 await expect(sidebar.getByRole("button", { name: standard.label })).toHaveCount(0);
133 await expect.poll(async () => (await api.get("OD View", standard.name)).public).toBe(0);
134
135 await list.viewAction(standard.label, "Show in sidebar");
136 await expect(sidebar.getByRole("button", { name: standard.label })).toBeVisible();
137 } finally {
138 await api.update("OD View", standard.name, { public: 1 });
139 }
140});
141