Debian Codegraph @

install/freeipa-webui/cypress/e2e/common/ui/textbox_list.ts

raw symbols SCIP
1 import { When, Then } from "@badeball/cypress-cucumber-preprocessor";
2
3 export const addElementToTextboxList = (
4 dataCyAddButton: string,
5 dataCyList: string,
6 elementToAdd: string
7 ) => {
8 cy.dataCy(dataCyAddButton).click();
9
10 cy.dataCy(dataCyList)
11 .children()
12 .find('[name="value"]')
13 .last()
14 .find("input")
15 .type(elementToAdd);
16
17 cy.dataCy(dataCyList)
18 .children()
19 .find('div[name="value"]')
20 .last()
21 .find("input")
22 .should("have.value", elementToAdd);
23 };
24
25 export const removeElementFromTextboxList = (
26 elementToRemove: string,
27 dataCy: string
28 ) => {
29 cy.dataCy(dataCy)
30 .find(`input[value="${elementToRemove}"]`)
31 .closest('div[name="value"]')
32 .find('button:contains("Delete")')
33 .click();
34 cy.dataCy(dataCy)
35 .find(`input[value="${elementToRemove}"]`)
36 .should("not.exist");
37 };
38
39 export const removeAllElementsFromTextboxList = (dataCy: string) => {
40 const deleteButtonSelector = `[data-cy^="${dataCy}-button-delete-"]`;
41
42 cy.get("body").then(($body) => {
43 if ($body.find(deleteButtonSelector).length > 0) {
44 cy.get(deleteButtonSelector).first().click();
45
46 removeAllElementsFromTextboxList(dataCy);
47 }
48 });
49 };
50
51 When(
52 "I add {string} to {string} textbox list",
53 (elementToAdd: string, dataCyList: string) => {
54 const addButtonSelector = `${dataCyList}-button-add`;
55 addElementToTextboxList(addButtonSelector, dataCyList, elementToAdd);
56 }
57 );
58
59 Then(
60 "I should see {string} in the {string} textbox list",
61 (element: string, dataCyList: string) => {
62 cy.get(`[data-cy^='${dataCyList}']`)
63 .filter(`[value="${element}"]`)
64 .should("exist");
65 }
66 );
67
68 When(
69 "I remove all elements from the {string} textbox list",
70 (dataCyList: string) => {
71 removeAllElementsFromTextboxList(dataCyList);
72 }
73 );
74
75 Then(
76 "I should not see {string} in the {string} textbox list",
77 (element: string, dataCyList: string) => {
78 cy.dataCy(dataCyList)
79 .find('[data-cy^="' + dataCyList + '-textbox-"]')
80 .each(($el) => {
81 expect($el).not.to.have.value(element);
82 });
83 }
84 );
85
86 Then(
87 "I should see the {string} textbox list is empty",
88 (dataCyList: string) => {
89 cy.dataCy(dataCyList).children().first().should("be.empty");
90 }
91 );