| 1 | import { Given } from "@badeball/cypress-cucumber-preprocessor"; |
| 2 | import { loginAsAdmin, logout } from "../common/authentication"; |
| 3 | import { |
| 4 | entryDoesNotExist, |
| 5 | searchForEntry, |
| 6 | selectEntry, |
| 7 | validateEntry, |
| 8 | } from "../common/data_tables"; |
| 9 | import { navigateTo } from "../common/navigation"; |
| 10 | import { typeInTextbox } from "../common/ui/textbox"; |
| 11 | |
| 12 | export const addSudoRule = (ruleName: string) => { |
| 13 | cy.dataCy("sudo-rules-button-add").click(); |
| 14 | cy.dataCy("add-sudo-rule-modal").should("be.visible"); |
| 15 | |
| 16 | typeInTextbox("modal-textbox-rule-name", ruleName); |
| 17 | cy.dataCy("modal-textbox-rule-name").should("have.value", ruleName); |
| 18 | |
| 19 | cy.dataCy("modal-button-add").click(); |
| 20 | cy.dataCy("add-sudo-rule-modal").should("not.exist"); |
| 21 | }; |
| 22 | |
| 23 | Given("sudo rule {string} exists", (ruleName: string) => { |
| 24 | loginAsAdmin(); |
| 25 | navigateTo("sudo-rules"); |
| 26 | addSudoRule(ruleName); |
| 27 | validateEntry(ruleName); |
| 28 | logout(); |
| 29 | }); |
| 30 | |
| 31 | Given("I delete sudo rule {string}", (ruleName: string) => { |
| 32 | loginAsAdmin(); |
| 33 | navigateTo("sudo-rules"); |
| 34 | selectEntry(ruleName); |
| 35 | |
| 36 | cy.dataCy("sudo-rules-button-delete").click(); |
| 37 | cy.dataCy("delete-sudo-rules-modal").should("be.visible"); |
| 38 | cy.dataCy("modal-button-delete").click(); |
| 39 | cy.dataCy("delete-sudo-rules-modal").should("not.exist"); |
| 40 | cy.dataCy("remove-sudorules-success").should("be.visible"); |
| 41 | |
| 42 | searchForEntry(ruleName); |
| 43 | entryDoesNotExist(ruleName); |
| 44 | logout(); |
| 45 | }); |