Skip to content

Commit 2d36a96

Browse files
daniel-jispond
authored andcommitted
add clusterOI panel ui test
1 parent 97330ac commit 2d36a96

File tree

2 files changed

+89
-18
lines changed

2 files changed

+89
-18
lines changed

src/clustersOfInterest.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ function _action_drop_down(self, pg) {
10081008

10091009
if (!self._is_CDC_executive_mode) {
10101010
dropdown.push({
1011-
label: "Clone this cluster of interest in a new editor pane",
1011+
label: "Clone this cluster of interest in a new editor panel",
10121012
action: function (button, value) {
10131013
let ref_set = self.priority_groups_find_by_name(pg.name);
10141014
let copied_node_objects = _.clone(ref_set.node_objects);
@@ -1418,6 +1418,7 @@ function draw_priority_set_table(self, container, priority_groups) {
14181418
0,
14191419
{
14201420
icon: "fa-info-circle",
1421+
classed: { "view-edit-cluster": true },
14211422
help: "View/edit this cluster of interest",
14221423
dropdown: _action_drop_down(self, pg),
14231424
/*action: function (button, menu_value) {

ui-tests/clusterOI.spec.js

Lines changed: 87 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ test.afterEach(({ page }) => {
1818
expect(errors).toEqual([]);
1919
});
2020

21+
/**
22+
* Returns a function that accepts a dialog and conditionally dismisses it
23+
* @param {*} message message that the dialog should contain to be dismissed
24+
* @returns function that accepts a dialog and dismisses it if the message matches
25+
*/
26+
const getAcceptDialogFunction = (message) => {
27+
return async (dialog) => {
28+
if (dialog.message().includes(message)) {
29+
await dialog.accept();
30+
} else {
31+
await dialog.dismiss();
32+
}
33+
}
34+
}
35+
2136
const openEditor = async (page) => {
2237
// go to clusterOI tab
2338
await expect(page.locator("#priority-set-tab")).toBeVisible();
@@ -35,8 +50,10 @@ const openEditor = async (page) => {
3550
await expect(jsPanels).toHaveLength(1);
3651
}
3752

38-
const createCluster = async (page, nodes) => {
39-
await openEditor(page);
53+
const createCluster = async (page, nodes, editorOpen = false) => {
54+
if (!editorOpen) {
55+
await openEditor(page);
56+
}
4057

4158
for (const node of nodes) {
4259
await page.locator('[data-hivtrace-ui-role="priority-panel-nodeids"]').fill(node);
@@ -64,12 +81,21 @@ const previewClusterOI = async (page) => {
6481
* Assumes that the clusterOI editor has nodes
6582
* Assumes that a current clusterOI does not have the same name
6683
*/
67-
const saveClusterOI = async (page, name) => {
84+
const saveClusterOI = async (page, name, expectDialog = false) => {
6885
await page.locator("#priority-panel-save").click();
6986
await expect(page.locator(".has-error")).toBeVisible();
7087

7188
await page.locator('[data-hivtrace-ui-role="priority-panel-name"]').fill(name);
72-
await page.locator("#priority-panel-save").click();
89+
90+
if (expectDialog) {
91+
const acceptDialog = getAcceptDialogFunction("This cluster of interest does not include all the nodes in the current");
92+
await page.on('dialog', acceptDialog);
93+
await page.locator("#priority-panel-save").click();
94+
await page.off('dialog', acceptDialog);
95+
} else {
96+
await page.locator("#priority-panel-save").click();
97+
}
98+
7399
await expect(page.locator(".has-error")).toHaveCount(0);
74100

75101
// jspanel should not be visible
@@ -87,18 +113,7 @@ const saveClusterOI = async (page, name) => {
87113
test('clusterOI editor opens, can add nodes', async ({ page }) => {
88114
// these specific nodes cause a confirm to appear when trying to save the clusterOI
89115
await createCluster(page, ["BMK384750US2015", "BMK385560US2007"]);
90-
91-
const acceptDialog = async (dialog) => {
92-
if (dialog.message().includes("This cluster of interest does not include all the nodes in the current")) {
93-
await dialog.accept();
94-
} else {
95-
await dialog.dismiss();
96-
}
97-
}
98-
99-
await page.on('dialog', acceptDialog);
100-
await saveClusterOI(page, "Cluster 1");
101-
await page.off('dialog', acceptDialog);
116+
await saveClusterOI(page, "Cluster 1", true);
102117
});
103118

104119
test('preview cluster and then open clusterOI editor', async ({ page }) => {
@@ -128,4 +143,59 @@ test('add nodes via graph to clusterOI editor and save', async ({ page }) => {
128143
await previewClusterOI(page);
129144

130145
await saveClusterOI(page, "Cluster 1");
131-
});
146+
});
147+
148+
test('add nodes via graph to clusterOI editor, save, clone clusterOI, save, and delete all', async ({ page }) => {
149+
// add nodes via graph to clusterOI editor and save
150+
await openEditor(page);
151+
152+
await page.locator("#trace-default-tab").click();
153+
await page.locator(".cluster-group").first().click();
154+
await page.getByText("Add this cluster to the cluster of interest", { exact: true }).click();
155+
156+
await previewClusterOI(page);
157+
158+
await saveClusterOI(page, "Cluster 1");
159+
160+
// clone clusterOI and save
161+
await page.locator(".view-edit-cluster").first().click();
162+
await page.getByText("Clone this cluster of interest in a new editor panel", { exact: true }).click();
163+
164+
const jsPanels = await page.locator(".jsPanel").all();
165+
await expect(jsPanels).toHaveLength(1);
166+
167+
await createCluster(page, ["01_AEMK272426TH2015"], true);
168+
169+
await saveClusterOI(page, "Cluster 2", true);
170+
171+
await expect(await page.locator("#priority_set_table")
172+
.filter({ has: page.getByText("Cluster 1") })
173+
.filter({ has: page.getByText("Cluster 2") }))
174+
.toBeVisible();
175+
176+
// delete all clusters, accept confirmation dialog
177+
await page.locator(".view-edit-cluster").first().click();
178+
const acceptDialog = getAcceptDialogFunction("This action cannot be undone. Proceed?")
179+
await page.on('dialog', acceptDialog);
180+
await page.getByText("Delete this cluster of interest", { exact: true }).first().click();
181+
await page.off('dialog', acceptDialog);
182+
183+
await expect(await page.locator("#priority_set_table")
184+
.filter({ has: page.getByText("Cluster 1") })
185+
.filter({ has: page.getByText("Cluster 2") }))
186+
.toHaveCount(0);
187+
188+
await expect(await page.locator("#priority_set_table")
189+
.filter({ has: page.getByText("Cluster 2") }))
190+
.toHaveCount(1);
191+
192+
// delete the last cluster
193+
await page.locator(".view-edit-cluster").first().click();
194+
const acceptDialog2 = getAcceptDialogFunction("This action cannot be undone. Proceed?")
195+
await page.on('dialog', acceptDialog2);
196+
await page.getByText("Delete this cluster of interest", { exact: true }).first().click();
197+
await page.off('dialog', acceptDialog2);
198+
199+
await expect(await page.locator("#priority_set_table tbody tr"))
200+
.toHaveCount(0);
201+
})

0 commit comments

Comments
 (0)