1 import { And, Given, Then, When } from 'cypress-cucumber-preprocessor/steps';
3 import { UrlsCollection } from './urls.po';
5 const urlsCollection = new UrlsCollection();
7 Given('I am logged in', () => {
9 Cypress.Cookies.preserveOnce('token');
12 Given('I am on the {string} page', (page: string) => {
13 cy.visit(urlsCollection.pages[page].url);
14 cy.get(urlsCollection.pages[page].id).should('exist');
17 Then('I should be on the {string} page', (page: string) => {
18 cy.get(urlsCollection.pages[page].id).should('exist');
21 And('I should see a button to {string}', (button: string) => {
22 cy.get(`[aria-label="${button}"]`).should('be.visible');
25 When('I click on {string} button', (button: string) => {
26 cy.get(`[aria-label="${button}"]`).first().click();
29 // When you are clicking on an action in the table actions dropdown button
30 When('I click on {string} button from the table actions', (button: string) => {
31 cy.get('.table-actions button.dropdown-toggle').first().click();
32 cy.get(`[aria-label="${button}"]`).first().click();
35 And('select options {string}', (labels: string) => {
37 cy.get('a[data-testid=select-menu-edit]').click();
38 for (const label of labels.split(', ')) {
39 cy.get('.popover-body div.select-menu-item-content').contains(label).click();
44 And('{string} option {string}', (action: string, labels: string) => {
46 if (action === 'add') {
47 cy.get('cd-modal').find('.select-menu-edit').click();
48 for (const label of labels.split(', ')) {
49 cy.get('.popover-body input').type(`${label}{enter}`);
52 for (const label of labels.split(', ')) {
53 cy.contains('cd-modal .badge', new RegExp(`^${label}$`))
54 .find('.badge-remove')
62 * Fills in the given field using the value provided
63 * @param field ID of the field that needs to be filled out.
64 * @param value Value that should be filled in the field.
66 And('enter {string} {string}', (field: string, value: string) => {
67 cy.get('cd-modal').within(() => {
68 cy.get(`input[id=${field}]`).type(value);
72 And('I click on submit button', () => {
73 cy.get('[data-cy=submitBtn]').click();
77 * Selects any row on the datatable if it matches the given name
79 When('I select a row {string}', (row: string) => {
80 cy.get('cd-table .search input').first().clear().type(row);
81 cy.contains(`datatable-body-row datatable-body-cell .datatable-body-cell-label`, row).click();
84 Then('I should see the modal', () => {
85 cy.get('cd-modal').should('exist');
88 Then('I should not see the modal', () => {
89 cy.get('cd-modal').should('not.exist');
93 * Some modals have an additional confirmation to be provided
94 * by ticking the 'Are you sure?' box.
96 Then('I check the tick box in modal', () => {
97 cy.get('cd-modal .custom-control-label').click();
100 And('I confirm to {string}', (action: string) => {
101 cy.contains('cd-modal button', action).click();
102 cy.get('cd-modal').should('not.exist');
105 Then('I should see an error in {string} field', (field: string) => {
106 cy.get('cd-modal').within(() => {
107 cy.get(`input[id=${field}]`).should('have.class', 'ng-invalid');
111 Then('I should see a row with {string}', (row: string) => {
112 cy.get('cd-table .search input').first().clear().type(row);
113 cy.contains(`datatable-body-row datatable-body-cell .datatable-body-cell-label`, row).should(
118 Then('I should not see a row with {string}', (row: string) => {
119 cy.get('cd-table .search input').first().clear().type(row);
120 cy.contains(`datatable-body-row datatable-body-cell .datatable-body-cell-label`, row).should(
125 Then('I should see rows with following entries', (entries) => {
126 entries.hashes().forEach((entry: any) => {
127 cy.get('cd-table .search input').first().clear().type(entry.hostname);
129 `datatable-body-row datatable-body-cell .datatable-body-cell-label`,
135 And('I should see row {string} have {string}', (row: string, options: string) => {
137 cy.get('cd-table .search input').first().clear().type(row);
138 for (const option of options.split(',')) {
140 `datatable-body-row datatable-body-cell .datatable-body-cell-label .badge`,
147 And('I should see row {string} does not have {string}', (row: string, options: string) => {
149 cy.get('cd-table .search input').first().clear().type(row);
150 for (const option of options.split(',')) {
152 `datatable-body-row datatable-body-cell .datatable-body-cell-label .badge`,
154 ).should('not.exist');
159 And('I go to the {string} tab', (names: string) => {
160 for (const name of names.split(', ')) {
161 cy.contains('.nav.nav-tabs li', name).click();
165 And('select {string} {string}', (selectionName: string, option: string) => {
166 cy.get(`select[name=${selectionName}]`).select(option);
167 cy.get(`select[name=${selectionName}] option:checked`).contains(option);
170 When('I expand the row {string}', (row: string) => {
171 cy.contains('.datatable-body-row', row).first().find('.tc_expand-collapse').click();
174 And('I should see row {string} have {string} on this tab', (row: string, options: string) => {
176 cy.get('cd-table').should('exist');
177 cy.get('datatable-scroller, .empty-row');
178 cy.get('.datatable-row-detail').within(() => {
179 cy.get('cd-table .search input').first().clear().type(row);
180 for (const option of options.split(',')) {
182 `datatable-body-row datatable-body-cell .datatable-body-cell-label span`,