summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/cypress/e2e/common/table-helper.feature.po.ts
blob: 330950acd44727a926bc980fefd074ad0fa3ae7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { And, Then, When } from 'cypress-cucumber-preprocessor/steps';

// When you are clicking on an action in the table actions dropdown button
When('I click on {string} button from the table actions', (button: string) => {
  cy.get('.table-actions button.dropdown-toggle').first().click();
  cy.get(`[aria-label="${button}"]`).first().click();
});

// When you are clicking on an action inside the expanded table row
When('I click on {string} button from the expanded row', (button: string) => {
  cy.get('.datatable-row-detail').within(() => {
    cy.get('.table-actions button.dropdown-toggle').first().click();
    cy.get(`[aria-label="${button}"]`).first().click();
  });
});

When('I click on {string} button from the table actions in the expanded row', (button: string) => {
  cy.get('.datatable-row-detail').within(() => {
    cy.get('.table-actions button.dropdown-toggle').first().click();
    cy.get(`[aria-label="${button}"]`).first().click();
  });
});

When('I expand the row {string}', (row: string) => {
  cy.contains('.datatable-body-row', row).first().find('.tc_expand-collapse').click();
});

/**
 * Selects any row on the datatable if it matches the given name
 */
When('I select a row {string}', (row: string) => {
  cy.get('cd-table .search input').first().clear().type(row);
  cy.contains(`datatable-body-row datatable-body-cell .datatable-body-cell-label`, row).click();
});

When('I select a row {string} in the expanded row', (row: string) => {
  cy.get('.datatable-row-detail').within(() => {
    cy.get('cd-table .search input').first().clear().type(row);
    cy.contains(`datatable-body-row datatable-body-cell .datatable-body-cell-label`, row).click();
  });
});

Then('I should see a row with {string}', (row: string) => {
  cy.get('cd-table .search input').first().clear().type(row);
  cy.contains(`datatable-body-row datatable-body-cell .datatable-body-cell-label`, row).should(
    'exist'
  );
});

Then('I should not see a row with {string}', (row: string) => {
  cy.get('cd-table .search input').first().clear().type(row);
  cy.contains(`datatable-body-row datatable-body-cell .datatable-body-cell-label`, row).should(
    'not.exist'
  );
});

Then('I should see a table in the expanded row', () => {
  cy.get('.datatable-row-detail').within(() => {
    cy.get('cd-table').should('exist');
    cy.get('datatable-scroller, .empty-row');
  });
});

Then('I should not see a row with {string} in the expanded row', (row: string) => {
  cy.get('.datatable-row-detail').within(() => {
    cy.get('cd-table .search input').first().clear().type(row);
    cy.contains(`datatable-body-row datatable-body-cell .datatable-body-cell-label`, row).should(
      'not.exist'
    );
  });
});

Then('I should see rows with following entries', (entries) => {
  entries.hashes().forEach((entry: any) => {
    cy.get('cd-table .search input').first().clear().type(entry.hostname);
    cy.contains(
      `datatable-body-row datatable-body-cell .datatable-body-cell-label`,
      entry.hostname
    ).should('exist');
  });
});

And('I should see row {string} have {string}', (row: string, options: string) => {
  if (options) {
    cy.get('cd-table .search input').first().clear().type(row);
    for (const option of options.split(',')) {
      cy.contains(
        `datatable-body-row datatable-body-cell .datatable-body-cell-label .badge`,
        option
      ).should('exist');
    }
  }
});

And('I should see row {string} of the expanded row to have a usage bar', (row: string) => {
  cy.get('.datatable-row-detail').within(() => {
    cy.get('cd-table .search input').first().clear().type(row);
    cy.contains(`datatable-body-row datatable-body-cell .datatable-body-cell-label`, row).should(
      'exist'
    );
    cy.get('.datatable-body-row .datatable-body-cell .datatable-body-cell-label .progress').should(
      'exist'
    );
  });
});

And('I should see row {string} does not have {string}', (row: string, options: string) => {
  if (options) {
    cy.get('cd-table .search input').first().clear().type(row);
    for (const option of options.split(',')) {
      cy.contains(
        `datatable-body-row datatable-body-cell .datatable-body-cell-label .badge`,
        option
      ).should('not.exist');
    }
  }
});

Then('I should see a row with {string} in the expanded row', (row: string) => {
  cy.get('.datatable-row-detail').within(() => {
    cy.get('cd-table .search input').first().clear().type(row);
    cy.contains(`datatable-body-row datatable-body-cell .datatable-body-cell-label`, row).should(
      'exist'
    );
  });
});

And('I should see row {string} have {string} on this tab', (row: string, options: string) => {
  if (options) {
    cy.get('cd-table').should('exist');
    cy.get('datatable-scroller, .empty-row');
    cy.get('.datatable-row-detail').within(() => {
      cy.get('cd-table .search input').first().clear().type(row);
      for (const option of options.split(',')) {
        cy.contains(
          `datatable-body-row datatable-body-cell .datatable-body-cell-label span`,
          option
        ).should('exist');
      }
    });
  }
});

Then('I should see an alert {string} in the expanded row', (alert: string) => {
  cy.get('.datatable-row-detail').within(() => {
    cy.get('.alert-panel-text').contains(alert);
  });
});