| 1 | import { When, Then, Given } from "@badeball/cypress-cucumber-preprocessor"; |
| 2 | import { |
| 3 | entryDoesNotExist, |
| 4 | entryExists, |
| 5 | searchForEntry, |
| 6 | selectEntry, |
| 7 | validateEntry, |
| 8 | } from "../common/data_tables"; |
| 9 | import "../user_groups/user_groups"; |
| 10 | import "../common/data_tables"; |
| 11 | import { navigateTo } from "../common/navigation"; |
| 12 | import { loginAsAdmin, logout } from "../common/authentication"; |
| 13 | import { isOptionSelected, selectOption } from "../common/ui/select"; |
| 14 | |
| 15 | const fillUserGroupRule = (userGroupName: string, selector: string) => { |
| 16 | selectOption(userGroupName, selector); |
| 17 | isOptionSelected(userGroupName, selector); |
| 18 | }; |
| 19 | |
| 20 | export const createUserGroupRule = (userGroupName: string) => { |
| 21 | cy.dataCy("auto-member-user-rules-button-add").click(); |
| 22 | cy.dataCy("add-rule-modal").should("exist"); |
| 23 | |
| 24 | fillUserGroupRule(userGroupName, "modal-select-automember"); |
| 25 | |
| 26 | cy.dataCy("modal-button-add").click(); |
| 27 | cy.dataCy("add-rule-modal").should("not.exist"); |
| 28 | searchForEntry(userGroupName); |
| 29 | entryExists(userGroupName); |
| 30 | }; |
| 31 | |
| 32 | const deleteUserGroupRule = (userGroupName: string) => { |
| 33 | selectEntry(userGroupName); |
| 34 | |
| 35 | cy.dataCy("auto-member-user-rules-button-delete").click(); |
| 36 | cy.dataCy("delete-rule-modal").should("exist"); |
| 37 | |
| 38 | cy.dataCy("modal-button-delete").click(); |
| 39 | cy.dataCy("delete-rule-modal").should("not.exist"); |
| 40 | |
| 41 | searchForEntry(userGroupName); |
| 42 | entryDoesNotExist(userGroupName); |
| 43 | cy.dataCy("delete-rule-success").should("exist"); |
| 44 | }; |
| 45 | |
| 46 | const setDefaultUserGroupRule = (userGroupName: string) => { |
| 47 | cy.dataCy("typeahead-select-toggle").click(); |
| 48 | cy.dataCy("typeahead-select-" + userGroupName).click(); |
| 49 | cy.dataCy("auto-member-default-user-rules-modal").should("exist"); |
| 50 | |
| 51 | cy.dataCy("modal-button-ok").click(); |
| 52 | cy.dataCy("auto-member-default-user-rules-modal").should("not.exist"); |
| 53 | cy.get("[data-cy='typeahead-select-input'] input").should( |
| 54 | "have.value", |
| 55 | userGroupName |
| 56 | ); |
| 57 | cy.dataCy("default-group-success").should("exist"); |
| 58 | }; |
| 59 | |
| 60 | Given("user group rule {string} exists", (userGroupName: string) => { |
| 61 | loginAsAdmin(); |
| 62 | navigateTo("user-groups"); |
| 63 | |
| 64 | cy.dataCy("user-groups-button-add").click(); |
| 65 | cy.dataCy("add-user-group-modal").should("exist"); |
| 66 | |
| 67 | cy.dataCy("modal-textbox-group-name").type(userGroupName); |
| 68 | cy.dataCy("modal-textbox-group-name").should("have.value", userGroupName); |
| 69 | |
| 70 | cy.dataCy("modal-button-add").click(); |
| 71 | cy.dataCy("add-user-group-modal").should("not.exist"); |
| 72 | searchForEntry(userGroupName); |
| 73 | entryExists(userGroupName); |
| 74 | |
| 75 | navigateTo("user-group-rules"); |
| 76 | createUserGroupRule(userGroupName); |
| 77 | |
| 78 | searchForEntry(userGroupName); |
| 79 | entryExists(userGroupName); |
| 80 | logout(); |
| 81 | }); |
| 82 | |
| 83 | When( |
| 84 | "I create user group rule based on user group {string}", |
| 85 | (userGroupName: string) => { |
| 86 | createUserGroupRule(userGroupName); |
| 87 | } |
| 88 | ); |
| 89 | |
| 90 | Then( |
| 91 | "I should see user group rule {string} in the user group rule table", |
| 92 | (userGroupName: string) => { |
| 93 | validateEntry(userGroupName); |
| 94 | } |
| 95 | ); |
| 96 | |
| 97 | Then( |
| 98 | "I should see user group rule {string} as the default user group rule", |
| 99 | (userGroupName: string) => { |
| 100 | cy.dataCy("typeahead-select-input") |
| 101 | .find("input") |
| 102 | .should("have.value", userGroupName); |
| 103 | } |
| 104 | ); |
| 105 | |
| 106 | Then( |
| 107 | "I should not see user group rule {string} in the user group rule table", |
| 108 | (userGroupName: string) => { |
| 109 | searchForEntry(userGroupName); |
| 110 | entryDoesNotExist(userGroupName); |
| 111 | } |
| 112 | ); |
| 113 | |
| 114 | Given("I delete user group rule {string}", (userGroupName: string) => { |
| 115 | loginAsAdmin(); |
| 116 | navigateTo("user-group-rules"); |
| 117 | |
| 118 | deleteUserGroupRule(userGroupName); |
| 119 | |
| 120 | searchForEntry(userGroupName); |
| 121 | entryDoesNotExist(userGroupName); |
| 122 | logout(); |
| 123 | }); |
| 124 | |
| 125 | When("I try to delete user group rule {string}", (userGroupName: string) => { |
| 126 | navigateTo("user-group-rules"); |
| 127 | deleteUserGroupRule(userGroupName); |
| 128 | searchForEntry(userGroupName); |
| 129 | entryDoesNotExist(userGroupName); |
| 130 | }); |
| 131 | |
| 132 | When("I set default user group rule {string}", (userGroupName: string) => { |
| 133 | setDefaultUserGroupRule(userGroupName); |
| 134 | }); |