| 1 | import { Given } from "@badeball/cypress-cucumber-preprocessor"; |
| 2 | import { loginAsAdmin, logout } from "../common/authentication"; |
| 3 | import { navigateTo } from "../common/navigation"; |
| 4 | import { entryExists, searchForEntry } from "../common/data_tables"; |
| 5 | import { createHostgroup } from "../hostgroups/hostgroup"; |
| 6 | import { createHostgroupRule } from "./automember_hostgroup"; |
| 7 | import { createUserGroupRule } from "./automember_user_group"; |
| 8 | import { isOptionSelected } from "../common/ui/select"; |
| 9 | import { typeInTextbox } from "../common/ui/textbox"; |
| 10 | import { createUserGroup } from "../user_groups/user_groups"; |
| 11 | import { EntryType } from "./parameter_types"; |
| 12 | |
| 13 | const addEntryTableToGroupRule = ( |
| 14 | entryType: EntryType, |
| 15 | entry: string, |
| 16 | category: string |
| 17 | ) => { |
| 18 | cy.dataCy("settings-button-add-automember" + entryType + "regex").click(); |
| 19 | cy.dataCy("add-automember-condition-modal").should("exist"); |
| 20 | |
| 21 | cy.dataCy("modal-attribute-select-toggle").click(); |
| 22 | cy.dataCy("modal-attribute-select-toggle").should( |
| 23 | "have.attr", |
| 24 | "aria-expanded", |
| 25 | "true" |
| 26 | ); |
| 27 | cy.dataCy("modal-attribute-select-" + category).click(); |
| 28 | isOptionSelected(category, "modal-attribute-select"); |
| 29 | |
| 30 | typeInTextbox("modal-textbox-expression", entry); |
| 31 | cy.dataCy("modal-textbox-expression").should("have.value", entry); |
| 32 | |
| 33 | cy.dataCy("modal-button-add").click(); |
| 34 | cy.dataCy("add-automember-condition-success").should("exist"); |
| 35 | |
| 36 | cy.get("#automember" + entryType + "regex-table") |
| 37 | .find("td") |
| 38 | .contains(entry) |
| 39 | .should("exist"); |
| 40 | }; |
| 41 | |
| 42 | Given( |
| 43 | "hostgroup rule {string} exists and has {EntryType} entry {string} with category {string}", |
| 44 | ( |
| 45 | hostGroupName: string, |
| 46 | entryType: EntryType, |
| 47 | entry: string, |
| 48 | category: string |
| 49 | ) => { |
| 50 | loginAsAdmin(); |
| 51 | navigateTo("host-groups"); |
| 52 | |
| 53 | createHostgroup(hostGroupName, "test"); |
| 54 | searchForEntry(hostGroupName); |
| 55 | entryExists(hostGroupName); |
| 56 | |
| 57 | navigateTo("host-group-rules"); |
| 58 | createHostgroupRule(hostGroupName); |
| 59 | |
| 60 | searchForEntry(hostGroupName); |
| 61 | entryExists(hostGroupName); |
| 62 | |
| 63 | navigateTo("host-group-rules/" + hostGroupName); |
| 64 | addEntryTableToGroupRule(entryType, entry, category); |
| 65 | logout(); |
| 66 | } |
| 67 | ); |
| 68 | |
| 69 | Given( |
| 70 | "user group rule {string} exists and has {EntryType} entry {string} with category {string}", |
| 71 | ( |
| 72 | userGroupName: string, |
| 73 | entryType: EntryType, |
| 74 | entry: string, |
| 75 | category: string |
| 76 | ) => { |
| 77 | loginAsAdmin(); |
| 78 | navigateTo("user-groups"); |
| 79 | |
| 80 | createUserGroup(userGroupName); |
| 81 | |
| 82 | navigateTo("user-group-rules"); |
| 83 | createUserGroupRule(userGroupName); |
| 84 | |
| 85 | searchForEntry(userGroupName); |
| 86 | entryExists(userGroupName); |
| 87 | |
| 88 | navigateTo("user-group-rules/" + userGroupName); |
| 89 | addEntryTableToGroupRule(entryType, entry, category); |
| 90 | logout(); |
| 91 | } |
| 92 | ); |