]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/cypress/e2e/common/forms-helper.feature.po.ts
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / cypress / e2e / common / forms-helper.feature.po.ts
CommitLineData
aee94f69
TL
1import { And, Then } from 'cypress-cucumber-preprocessor/steps';
2
3/**
4 * Fills in the given field using the value provided
5 * @param field ID of the field that needs to be filled out.
6 * @param value Value that should be filled in the field.
7 */
8And('enter {string} {string}', (field: string, value: string) => {
9 cy.get('.cd-col-form').within(() => {
10 cy.get(`input[id=${field}]`).clear().type(value);
11 });
12});
13
14/**
15 * Fills in the given field using the value provided
16 * @param field ID of the field that needs to be filled out.
17 * @param value Value that should be filled in the field.
18 */
19And('enter {string} {string} in the modal', (field: string, value: string) => {
20 cy.get('cd-modal').within(() => {
21 cy.get(`input[id=${field}]`).clear().type(value);
22 });
23});
24
25And('select options {string}', (labels: string) => {
26 if (labels) {
27 cy.get('a[data-testid=select-menu-edit]').click();
28 for (const label of labels.split(', ')) {
29 cy.get('.popover-body div.select-menu-item-content').contains(label).click();
30 }
31 }
32});
33
34And('{string} option {string}', (action: string, labels: string) => {
35 if (labels) {
36 if (action === 'add') {
37 cy.get('cd-modal').find('.select-menu-edit').click();
38 for (const label of labels.split(', ')) {
39 cy.get('.popover-body input').type(`${label}{enter}`);
40 }
41 } else {
42 for (const label of labels.split(', ')) {
43 cy.contains('cd-modal .badge', new RegExp(`^${label}$`))
44 .find('.badge-remove')
45 .click();
46 }
47 }
48 }
49});
50
51And('I click on submit button', () => {
52 cy.get('[data-cy=submitBtn]').click();
53});
54
55/**
56 * Some modals have an additional confirmation to be provided
57 * by ticking the 'Are you sure?' box.
58 */
59Then('I check the tick box in modal', () => {
60 cy.get('cd-modal input#confirmation').click();
61});
62
63And('I confirm to {string}', (action: string) => {
64 cy.contains('cd-modal button', action).click();
65 cy.get('cd-modal').should('not.exist');
66});
67
68Then('I should see an error in {string} field', (field: string) => {
69 cy.get('cd-modal').within(() => {
70 cy.get(`input[id=${field}]`).should('have.class', 'ng-invalid');
71 });
72});
73
74And('select {string} {string}', (selectionName: string, option: string) => {
75 cy.get(`select[name=${selectionName}]`).select(option);
76 cy.get(`select[name=${selectionName}] option:checked`).contains(option);
77});