Debian Codegraph @

install/freeipa-webui/cypress/e2e/common/data_tables.ts

raw symbols SCIP
1 import { When, Then } from "@badeball/cypress-cucumber-preprocessor";
2
3 export const entryExists = (name: string) => {
4 cy.get("tr[id='" + name + "']").should("exist");
5 };
6
7 export const entryDoesNotExist = (name: string) => {
8 cy.get("tr[id='" + name + "']").should("not.exist");
9 };
10
11 export const searchForEntry = (name: string) => {
12 cy.dataCy("search").find("input").clear();
13 cy.dataCy("search").find("input").should("have.value", "");
14 cy.dataCy("search").find("input").type(name);
15 cy.dataCy("search").find("input").should("have.value", name);
16
17 cy.intercept("POST", "/ipa/session/json").as("search");
18
19 cy.dataCy("search").find("button[type='submit']").click();
20
21 cy.wait("@search");
22 cy.dataCy("search").find("button[type='submit']").should("be.enabled");
23 };
24
25 export const checkEntry = (name: string) => {
26 cy.get("tr[id='" + name + "'] input[type=checkbox]").check();
27 cy.get("tr[id='" + name + "'] input[type=checkbox]").should("be.checked");
28 };
29
30 export const selectEntry = (name: string) => {
31 searchForEntry(name);
32 checkEntry(name);
33 };
34
35 export const isSelected = (name: string) => {
36 cy.get("tr[id='" + name + "'] input[type=checkbox]").should("be.checked");
37 };
38
39 export const isNotSelected = (name: string) => {
40 cy.get("tr[id='" + name + "'] input[type=checkbox]").should("not.be.checked");
41 };
42
43 export const validateEntry = (name: string) => {
44 searchForEntry(name);
45 entryExists(name);
46 };
47
48 When("I search for {string} in the data table", (name: string) => {
49 searchForEntry(name);
50 });
51
52 Then("I should see {string} entry in the data table", (name: string) => {
53 entryExists(name);
54 });
55
56 Then(
57 "I should see {string} entry in the data table with ID {string}",
58 (name: string, tableId: string) => {
59 cy.get("#" + tableId)
60 .find("td")
61 .contains(name)
62 .should("exist");
63 }
64 );
65
66 Then("I should not see {string} entry in the data table", (name: string) => {
67 entryDoesNotExist(name);
68 });
69
70 Then(
71 "I should not see {string} entry in the data table with ID {string}",
72 (name: string, tableId: string) => {
73 cy.get("#" + tableId)
74 .find("td")
75 .contains(name)
76 .should("not.exist");
77 }
78 );
79
80 Then(
81 "I should see {string} entry in the data table with attribute {string} set to {string}",
82 (name: string, attribute: string, value: string) => {
83 entryExists(name);
84 cy.get("tr[id='" + name + "'] td[data-label='" + attribute + "']").should(
85 "have.text",
86 value
87 );
88 }
89 );
90
91 When("I select entry {string} in the data table", (name: string) => {
92 selectEntry(name);
93 });
94
95 When(
96 "I select {string} entry in the data table with ID {string}",
97 (name: string, tableId: string) => {
98 cy.get("#" + tableId)
99 .contains("td", name)
100 .parent("tr")
101 .find("input[type=checkbox]")
102 .check();
103 }
104 );
105
106 Then(
107 "I should see {string} entry selected in the data table",
108 (name: string) => {
109 isSelected(name);
110 }
111 );
112
113 Then(
114 "I should see {string} entry selected in the data table with ID {string}",
115 (name: string, tableId: string) => {
116 cy.get("#" + tableId)
117 .contains("td", name)
118 .parent("tr")
119 .find("input[type=checkbox]")
120 .should("be.checked");
121 }
122 );
123
124 Then(
125 "I should see {string} entry not selected in the data table",
126 (name: string) => {
127 isNotSelected(name);
128 }
129 );
130
131 Then("I should see no table with ID {string}", (tableId: string) => {
132 cy.get("table#" + tableId).should("not.exist");
133 });