Skip to content

Commit 60484aa

Browse files
authored
Merge pull request #9691 from asirvadAbrahamVarghese/add-miq-data-table-commands
Add miq data table commands
2 parents ba85349 + 5a31ec4 commit 60484aa

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

cypress/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ ManageIQ implements the following cypress extensions:
3838
##### gtl
3939

4040
* `cy.gtl_error()` - check that error message is present.
41-
* `cy.gtl_no_record()` - check that `No Record` message is present.
4241
* `cy.gtlGetTable()` - returns GTL table.
4342
* `cy.gtlGetRows(columns)` - return GTL table row data in an array. `columns`: Array of 0-based indexes of the columns to read (e.g. [1, 2, 3] will return all row data from columns 1, 2, and 3).
4443
* `cy.gtlClickRow(columns)` - click on a row in a GTL table. `columns`: Array of `{ title: String, number: Integer }`. `title` is the string you want to find in the table to click on, `number` is the column that string is found in. (e.g. `[{title: 'Default', number: 1}, {title: 'Compute', number: 2}]` will click on a row in the GTL table with `Default` in column 1 and `Compute` in column 2. Using just `[{title: 'Default', number: 1}]` will click on the first row found in the GTL table with `Default` in column 1).
@@ -55,6 +54,7 @@ ManageIQ implements the following cypress extensions:
5554
##### miq_data_table_commands
5655

5756
* `cy.selectTableRowsByText({ textArray })` - selects table rows that contain any of the specified text values. Iterates through each text in the array and finds the corresponding row. If any text is not found in the table, it throws an error immediately. `textArray` is an array of text values to match against table rows. e.g. `cy.selectTableRowsByText({ textArray: ['Option 1', 'Option 2'] });`
57+
* `cy.clickTableRowByText({ text, columnIndex })` - clicks on a table row that contains the specified text. If columnIndex is provided, it will only look for the text in that specific column. `text` is the text to find in the table row. `columnIndex` is an optional 0-based index of the column to search in. e.g. `cy.clickTableRowByText({ text: 'My Service' });`, `cy.clickTableRowByText({ text: 'Active', columnIndex: 2 });`
5858

5959
##### tabs
6060

@@ -98,6 +98,7 @@ ManageIQ implements the following cypress extensions:
9898
#### Assertions
9999

100100
* `cy.expect_explorer_title(title)` - check that the title on an explorer screen matches the provided title. `title`: String for the title.
101+
* `cy.expect_gtl_no_records_with_text({ containsText })` - verifies that the GTL view displays a "no records" message. Checks that the specified text is visible within the GTL view container. `containsText` is the optional text to verify in the no records message (defaults to 'No records'). e.g. `cy.expect_gtl_no_records_with_text();`, `cy.expect_gtl_no_records_with_text({ containsText: 'No items found' });`
101102
* `cy.expect_no_search_box()` - check if no searchbox is present on the screen.
102103
* `cy.expect_rates_table(headers, rows)` - check the values in a chargeback rate table. `headers`: Array of strings representing the headers of the table. `rows`: Array of type `[String, [...String], [...String], [...String], [...String], String]` where each index of the array represents a column in the table. The arrays within the `rows` array can be any length and represent the values in each given column, e.g. an array of `[0.0, 100.0]` in the index for the `Range Start` column would verify that the column contains two range starts with values `0.0` and `100.0`.
103104
* `cy.expect_show_list_title(title)` - check the title on a show\_list screen matches the provided title. `title`: String for the title.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* eslint-disable no-undef */
2+
3+
/**
4+
* Command to verify that the GTL (Grid/Tile/List) view displays a "no records" message.
5+
* This assertion checks that the specified text is visible within the GTL view container.
6+
*
7+
* @param {Object} params - Parameters for the command
8+
* @param {string} [params.containsText='No records'] - The text to verify in the no records message
9+
* @returns {Cypress.Chainable} A Cypress chainable that asserts the text is visible
10+
* @example
11+
* // Check for default "No records" message
12+
* cy.expect_gtl_no_records_with_text();
13+
*
14+
* @example
15+
* // Check for custom message
16+
* cy.expect_gtl_no_records_with_text({ containsText: 'No items found' });
17+
*/
18+
Cypress.Commands.add(
19+
'expect_gtl_no_records_with_text',
20+
({ containsText = 'No records' } = {}) => {
21+
return cy.contains('#miq-gtl-view', containsText).should('be.visible');
22+
}
23+
);

cypress/support/commands/gtl.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ Cypress.Commands.add('gtl_error', () => {
44
return cy.get('#miq-gtl-view > #flash_msg_div').should('be.visible');
55
});
66

7-
Cypress.Commands.add('gtl_no_record', () => {
8-
return cy.get('#miq-gtl-view > div.no-record').should('be.visible');
9-
});
10-
117
Cypress.Commands.add('gtlGetTable', () => {
128
return cy.get('#miq-gtl-view > .miq-data-table > .miq-data-table > .bx--data-table-content > table');
139
});

cypress/support/commands/miq_data_table_commands.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,23 @@ Cypress.Commands.add('selectTableRowsByText', ({ textArray = [] }) => {
5353
});
5454
});
5555
});
56+
57+
/**
58+
* Command to click on a table row that contains the specified text.
59+
* If columnIndex is provided, it will only look for the text in that specific column.
60+
*
61+
* @param {Object} params - Parameters for the command
62+
* @param {string} params.text - Text to find in the table row
63+
* @param {number} [params.columnIndex] - Optional index of the column to search in (0-based)
64+
*/
65+
Cypress.Commands.add('clickTableRowByText', ({ text, columnIndex }) => {
66+
if (!text) {
67+
cy.logAndThrowError('text parameter is required');
68+
}
69+
70+
if (columnIndex || columnIndex === 0) {
71+
cy.contains(`.miq-data-table table tbody tr td:nth-child(${columnIndex + 1})`, text).click();
72+
} else {
73+
cy.contains('.miq-data-table table tbody tr td', text).click();
74+
}
75+
});

cypress/support/e2e.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import './assertions/expect_rates_table.js';
6363
import './assertions/expect_search_box.js';
6464
import './assertions/expect_text.js';
6565
import './assertions/expect_title.js';
66+
import './assertions/miq_data_table_assertions.js'
6667

6768
// cypress on rails setup:
6869
// ***********************************************************

0 commit comments

Comments
 (0)