| 1 | import { Given } from "@badeball/cypress-cucumber-preprocessor"; |
| 2 | import { loginAsAdmin, logout } from "../common/authentication"; |
| 3 | import { |
| 4 | selectEntry, |
| 5 | searchForEntry, |
| 6 | entryDoesNotExist, |
| 7 | entryExists, |
| 8 | isSelected, |
| 9 | } from "../common/data_tables"; |
| 10 | import { navigateTo } from "../common/navigation"; |
| 11 | import { createUser, validateUser } from "../common/user_management"; |
| 12 | |
| 13 | const preserveUser = (username: string) => { |
| 14 | searchForEntry(username); |
| 15 | entryExists(username); |
| 16 | |
| 17 | selectEntry(username); |
| 18 | isSelected(username); |
| 19 | |
| 20 | cy.dataCy("active-users-button-delete").click(); |
| 21 | cy.dataCy("delete-users-modal").should("exist"); |
| 22 | |
| 23 | cy.dataCy("modal-radio-preserve").click(); |
| 24 | cy.dataCy("modal-radio-preserve").should("be.checked"); |
| 25 | cy.dataCy("preserve-users-modal").should("exist"); |
| 26 | |
| 27 | cy.dataCy("modal-button-preserve").click(); |
| 28 | cy.dataCy("preserve-users-modal").should("not.exist"); |
| 29 | |
| 30 | searchForEntry(username); |
| 31 | entryDoesNotExist(username); |
| 32 | |
| 33 | navigateTo("preserved-users"); |
| 34 | |
| 35 | searchForEntry(username); |
| 36 | entryExists(username); |
| 37 | }; |
| 38 | |
| 39 | Given("I delete preserved user {string}", (username: string) => { |
| 40 | loginAsAdmin(); |
| 41 | navigateTo("preserved-users"); |
| 42 | selectEntry(username); |
| 43 | |
| 44 | cy.dataCy("preserved-users-button-delete").click(); |
| 45 | cy.dataCy("delete-users-modal").should("exist"); |
| 46 | |
| 47 | cy.dataCy("modal-button-delete").click(); |
| 48 | cy.dataCy("delete-users-modal").should("not.exist"); |
| 49 | |
| 50 | searchForEntry(username); |
| 51 | entryDoesNotExist(username); |
| 52 | logout(); |
| 53 | }); |
| 54 | |
| 55 | Given( |
| 56 | "Preserved user {string} {string} {string} exists and is using password {string}", |
| 57 | (login: string, firstName: string, lastName: string, password: string) => { |
| 58 | loginAsAdmin(); |
| 59 | createUser(firstName, lastName, password, login); |
| 60 | validateUser(login); |
| 61 | preserveUser(login); |
| 62 | logout(); |
| 63 | } |
| 64 | ); |