| 1 | import { When, Then, Given } from "@badeball/cypress-cucumber-preprocessor"; |
| 2 | import { |
| 3 | entryDoesNotExist, |
| 4 | entryExists, |
| 5 | searchForEntry, |
| 6 | selectEntry, |
| 7 | } from "../common/data_tables"; |
| 8 | import { navigateTo } from "../common/navigation"; |
| 9 | import { loginAsAdmin, logout } from "../common/authentication"; |
| 10 | |
| 11 | const fillHostgroup = (hostgroupName: string, hostgroupDescription: string) => { |
| 12 | cy.dataCy("modal-textbox-hostgroup-name").type(hostgroupName); |
| 13 | cy.dataCy("modal-textbox-hostgroup-name").should("have.value", hostgroupName); |
| 14 | |
| 15 | cy.dataCy("modal-textbox-hostgroup-description").type(hostgroupDescription); |
| 16 | cy.dataCy("modal-textbox-hostgroup-description").should( |
| 17 | "have.value", |
| 18 | hostgroupDescription |
| 19 | ); |
| 20 | }; |
| 21 | |
| 22 | export const createHostgroup = ( |
| 23 | hostgroupName: string, |
| 24 | hostgroupDescription: string |
| 25 | ) => { |
| 26 | cy.dataCy("host-groups-button-add").click(); |
| 27 | cy.dataCy("add-hostgroup-modal").should("exist"); |
| 28 | |
| 29 | fillHostgroup(hostgroupName, hostgroupDescription); |
| 30 | |
| 31 | cy.dataCy("modal-button-add").click(); |
| 32 | cy.dataCy("add-hostgroup-modal").should("not.exist"); |
| 33 | }; |
| 34 | |
| 35 | const deleteHostgroup = (hostgroupName: string) => { |
| 36 | selectEntry(hostgroupName); |
| 37 | |
| 38 | cy.dataCy("host-groups-button-delete").click(); |
| 39 | cy.dataCy("delete-hostgroups-modal").should("exist"); |
| 40 | |
| 41 | cy.dataCy("modal-button-delete").click(); |
| 42 | cy.dataCy("delete-hostgroups-modal").should("not.exist"); |
| 43 | |
| 44 | searchForEntry(hostgroupName); |
| 45 | entryDoesNotExist(hostgroupName); |
| 46 | }; |
| 47 | |
| 48 | const validateHostgroup = (hostgroupName: string) => { |
| 49 | searchForEntry(hostgroupName); |
| 50 | entryExists(hostgroupName); |
| 51 | }; |
| 52 | |
| 53 | When( |
| 54 | "I create hostgroup {string} with description {string}", |
| 55 | (hostgroupName: string, hostgroupDescription: string) => { |
| 56 | createHostgroup(hostgroupName, hostgroupDescription); |
| 57 | } |
| 58 | ); |
| 59 | |
| 60 | Then( |
| 61 | "I should see hostgroup {string} in the data table", |
| 62 | (hostgroupName: string) => { |
| 63 | validateHostgroup(hostgroupName); |
| 64 | } |
| 65 | ); |
| 66 | |
| 67 | Then( |
| 68 | "I should not see hostgroup {string} in the data table", |
| 69 | (hostgroupName: string) => { |
| 70 | searchForEntry(hostgroupName); |
| 71 | entryDoesNotExist(hostgroupName); |
| 72 | } |
| 73 | ); |
| 74 | |
| 75 | Given( |
| 76 | "Hostgroup {string} with description {string} exists", |
| 77 | (hostgroupName: string, hostgroupDescription: string) => { |
| 78 | loginAsAdmin(); |
| 79 | navigateTo("host-groups"); |
| 80 | |
| 81 | createHostgroup(hostgroupName, hostgroupDescription); |
| 82 | validateHostgroup(hostgroupName); |
| 83 | |
| 84 | logout(); |
| 85 | } |
| 86 | ); |
| 87 | |
| 88 | Given("I delete hostgroup {string}", (hostgroupName: string) => { |
| 89 | loginAsAdmin(); |
| 90 | navigateTo("host-groups"); |
| 91 | |
| 92 | deleteHostgroup(hostgroupName); |
| 93 | |
| 94 | searchForEntry(hostgroupName); |
| 95 | entryDoesNotExist(hostgroupName); |
| 96 | logout(); |
| 97 | }); |
| 98 | |
| 99 | When("I try to delete hostgroup {string}", (hostgroupName: string) => { |
| 100 | navigateTo("host-groups"); |
| 101 | deleteHostgroup(hostgroupName); |
| 102 | searchForEntry(hostgroupName); |
| 103 | entryDoesNotExist(hostgroupName); |
| 104 | }); |