]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/cypress/integration/common/01-global.feature.po.ts
575d4013b9376267427107c7fcad3417ee448310
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / cypress / integration / common / 01-global.feature.po.ts
1 import { And, Given, Then, When } from 'cypress-cucumber-preprocessor/steps';
2
3 import { UrlsCollection } from './urls.po';
4
5 const urlsCollection = new UrlsCollection();
6
7 Given('I am logged in', () => {
8 cy.login();
9 Cypress.Cookies.preserveOnce('token');
10 });
11
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');
15 });
16
17 Then('I should be on the {string} page', (page: string) => {
18 cy.get(urlsCollection.pages[page].id).should('exist');
19 });
20
21 And('I should see a button to {string}', (button: string) => {
22 cy.get(`[aria-label="${button}"]`).should('be.visible');
23 });
24
25 When('I click on {string} button', (button: string) => {
26 cy.get(`[aria-label="${button}"]`).first().click();
27 });
28
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();
33 });
34
35 And('select options {string}', (labels: string) => {
36 if (labels) {
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();
40 }
41 }
42 });
43
44 And('{string} option {string}', (action: string, labels: string) => {
45 if (labels) {
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}`);
50 }
51 } else {
52 for (const label of labels.split(', ')) {
53 cy.contains('cd-modal .badge', new RegExp(`^${label}$`))
54 .find('.badge-remove')
55 .click();
56 }
57 }
58 }
59 });
60
61 /**
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.
65 */
66 And('enter {string} {string}', (field: string, value: string) => {
67 cy.get('cd-modal').within(() => {
68 cy.get(`input[id=${field}]`).type(value);
69 });
70 });
71
72 And('I click on submit button', () => {
73 cy.get('[data-cy=submitBtn]').click();
74 });
75
76 /**
77 * Selects any row on the datatable if it matches the given name
78 */
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();
82 });
83
84 Then('I should see the modal', () => {
85 cy.get('cd-modal').should('exist');
86 });
87
88 Then('I should not see the modal', () => {
89 cy.get('cd-modal').should('not.exist');
90 });
91
92 /**
93 * Some modals have an additional confirmation to be provided
94 * by ticking the 'Are you sure?' box.
95 */
96 Then('I check the tick box in modal', () => {
97 cy.get('cd-modal .custom-control-label').click();
98 });
99
100 And('I confirm to {string}', (action: string) => {
101 cy.contains('cd-modal button', action).click();
102 cy.get('cd-modal').should('not.exist');
103 });
104
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');
108 });
109 });
110
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(
114 'exist'
115 );
116 });
117
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(
121 'not.exist'
122 );
123 });
124
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);
128 cy.contains(
129 `datatable-body-row datatable-body-cell .datatable-body-cell-label`,
130 entry.hostname
131 ).should('exist');
132 });
133 });
134
135 And('I should see row {string} have {string}', (row: string, options: string) => {
136 if (options) {
137 cy.get('cd-table .search input').first().clear().type(row);
138 for (const option of options.split(',')) {
139 cy.contains(
140 `datatable-body-row datatable-body-cell .datatable-body-cell-label .badge`,
141 option
142 ).should('exist');
143 }
144 }
145 });
146
147 And('I should see row {string} does not have {string}', (row: string, options: string) => {
148 if (options) {
149 cy.get('cd-table .search input').first().clear().type(row);
150 for (const option of options.split(',')) {
151 cy.contains(
152 `datatable-body-row datatable-body-cell .datatable-body-cell-label .badge`,
153 option
154 ).should('not.exist');
155 }
156 }
157 });
158
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();
162 }
163 });
164
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);
168 });
169
170 When('I expand the row {string}', (row: string) => {
171 cy.contains('.datatable-body-row', row).first().find('.tc_expand-collapse').click();
172 });
173
174 And('I should see row {string} have {string} on this tab', (row: string, options: string) => {
175 if (options) {
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(',')) {
181 cy.contains(
182 `datatable-body-row datatable-body-cell .datatable-body-cell-label span`,
183 option
184 ).should('exist');
185 }
186 });
187 }
188 });