Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ TODO allow using {id:...} instead of string label for menu items, gtl items, tre

#### GTL

* `cy.gtl()` - return GTL
* `cy.gtl_error` - check that error message is present
* `cy.gtl_no_record` - check that `No data` message is present
* `cy.gtl_click('Name')` - click on a GTL
* `cy.gtlGetTable` - return GTL table
* `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)
* `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).

#### searchbox

Expand Down
95 changes: 22 additions & 73 deletions cypress/e2e/ui/Overview/Chargeback/rates.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ describe('Rates', () => {
});

it('Loads the default compute chargeback rate', () => {
cy.get('.clickable-row').then((rows) => {
const nums = [...Array(rows.length).keys()];
nums.forEach((index) => {
if (rows[index].children[1].innerText === 'Default' && rows[index].children[2].innerText === 'Compute') {
cy.get(rows[index]).click();
}
});
}).then(() => {
cy.gtlClickRow([{title: 'Default', number: 1}, {title: 'Compute', number: 2}]).then(() => {
cy.get(':nth-child(1) > .col-md-8 > .form-control-static').contains('Default');
cy.get(':nth-child(2) > .col-md-8 > .form-control-static').contains('Compute');

Expand Down Expand Up @@ -127,14 +120,7 @@ describe('Rates', () => {
});

it('Loads the default storage chargeback rate', () => {
cy.get('.clickable-row').then((rows) => {
const nums = [...Array(rows.length).keys()];
nums.forEach((index) => {
if (rows[index].children[1].innerText === 'Default' && rows[index].children[2].innerText === 'Storage') {
cy.get(rows[index]).click();
}
});
}).then(() => {
cy.gtlClickRow([{title: 'Default', number: 1}, {title: 'Storage', number: 2}]).then(() => {
cy.get(':nth-child(1) > .col-md-8 > .form-control-static').contains('Default');
cy.get(':nth-child(2) > .col-md-8 > .form-control-static').contains('Storage');

Expand Down Expand Up @@ -185,14 +171,7 @@ describe('Rates', () => {
});

it('Loads the default container image chargeback rate', () => {
cy.get('.clickable-row').then((rows) => {
const nums = [...Array(rows.length).keys()];
nums.forEach((index) => {
if (rows[index].children[1].innerText === 'Default Container Image Rate') {
cy.get(rows[index]).click();
}
});
}).then(() => {
cy.gtlClickRow([{title: 'Default Container Image Rate', number: 1}]).then(() => {
cy.get(':nth-child(1) > .col-md-8 > .form-control-static').contains('Default Container Image Rate');
cy.get(':nth-child(2) > .col-md-8 > .form-control-static').contains('Compute');

Expand Down Expand Up @@ -301,24 +280,17 @@ describe('Rates', () => {
});

it('Cancel button works on the form', () => {
const rates = [];
cy.get('.clickable-row').then((rows) => {
const nums = [...Array(rows.length).keys()];
nums.forEach((index) => {
rates.push(rows[index].children[1].innerText);
});
}).then(() => {
cy.gtlGetRows([1]).then((originalRates) => {
cy.get('#chargeback_rates_vmdb_choice').click();
cy.get(':nth-child(1) > .bx--overflow-menu-options__btn > div').click();
cy.get('[width="100%"] > tbody > tr > td > .btn-default').click();
cy.get('.miq-toolbar-group');
cy.url().should('include', 'chargeback_rate/show_list');
cy.get('.alert').contains('Add of new Chargeback Rate was cancelled by the user');
cy.get('.clickable-row').then((rows) => {
const nums = [...Array(rows.length).keys()];
nums.forEach((index) => {
expect(rates).to.include(rows[index].children[1].innerText);
rates.shift();
cy.gtlGetRows([1]).then((newRates) => {
newRates.forEach((newRate) => {
expect(originalRates).to.deep.include(newRate);
originalRates.shift();
});
});
});
Expand Down Expand Up @@ -360,14 +332,7 @@ describe('Rates', () => {

cy.get('.btn-primary').click();
cy.get('#gtl_div').contains('Cypress test compute chargeback rates');
cy.get('.clickable-row').then((rows) => {
const nums = [...Array(rows.length).keys()];
nums.forEach((index) => {
if (rows[index].children[1].innerText === 'Cypress test compute chargeback rates') {
cy.get(rows[index]).click();
}
});
}).then(() => {
cy.gtlClickRow([{title: 'Cypress test compute chargeback rates', number: 1}]).then(() => {
cy.get(':nth-child(1) > .col-md-8 > .form-control-static').contains('Cypress test compute chargeback rates');
cy.get(':nth-child(2) > .col-md-8 > .form-control-static').contains('Compute');

Expand Down Expand Up @@ -634,11 +599,10 @@ describe('Rates', () => {
}).then(() => {
cy.get('#chargeback_rate_vmdb_choice').click();
cy.get(':nth-child(3) > .bx--overflow-menu-options__btn').click();
cy.get('.clickable-row').then((rows) => {
const nums = [...Array(rows.length).keys()];
nums.forEach((index) => {
expect(rows[index].children[1].innerText).to.not.eq('Cypress test compute chargeback rates edit');
expect(rows[index].children[1].innerText).to.not.eq('Cypress test compute chargeback rates');
cy.gtlGetRows([1]).then((rows) => {
rows.forEach((row) => {
expect(row).to.not.eq('Cypress test compute chargeback rates edit');
expect(row).to.not.eq('Cypress test compute chargeback rates');
});
});
});
Expand Down Expand Up @@ -669,14 +633,7 @@ describe('Rates', () => {
cy.get('#rate_detail_row_3_0 > .action-cell > .btn').click();
cy.get('.btn-primary').click();
cy.get('#gtl_div').contains('Cypress test storage chargeback rates');
cy.get('.clickable-row').then((rows) => {
const nums = [...Array(rows.length).keys()];
nums.forEach((index) => {
if (rows[index].children[1].innerText === 'Cypress test storage chargeback rates') {
cy.get(rows[index]).click();
}
});
}).then(() => {
cy.gtlClickRow([{title: 'Cypress test storage chargeback rates', number: 1}]).then(() => {
cy.get(':nth-child(1) > .col-md-8 > .form-control-static').contains('Cypress test storage chargeback rates');
cy.get(':nth-child(2) > .col-md-8 > .form-control-static').contains('Storage');

Expand Down Expand Up @@ -809,24 +766,17 @@ describe('Rates', () => {
}).then(() => {
cy.get('#chargeback_rate_vmdb_choice').click();
cy.get(':nth-child(3) > .bx--overflow-menu-options__btn').click();
cy.get('.clickable-row').then((rows) => {
const nums = [...Array(rows.length).keys()];
nums.forEach((index) => {
expect(rows[index].children[1].innerText).to.not.eq('Cypress test storage chargeback rates edit');
expect(rows[index].children[1].innerText).to.not.eq('Cypress test storage chargeback rates');
cy.gtlGetRows([1]).then((rows) => {
rows.forEach((row) => {
expect(row).to.not.eq('Cypress test storage chargeback rates edit');
expect(row).to.not.eq('Cypress test storage chargeback rates');
});
});
});
});

it('Copy a chargeback rate', () => {
cy.get('.clickable-row').then((rows) => {
const nums = [...Array(rows.length).keys()];
nums.forEach((index) => {
if (rows[index].children[1].innerText === 'Default' && rows[index].children[2].innerText === 'Storage') {
cy.get(rows[index]).click();
}
});
cy.gtlClickRow([{title: 'Default', number: 1}, {title: 'Storage', number: 2}]).then(() => {
cy.get('#chargeback_rate_vmdb_choice').click();
cy.get(':nth-child(2) > .bx--overflow-menu-options__btn').click();
cy.get('.btn-primary').click();
Expand Down Expand Up @@ -879,10 +829,9 @@ describe('Rates', () => {

cy.get('#chargeback_rate_vmdb_choice').click();
cy.get(':nth-child(3) > .bx--overflow-menu-options__btn').click();
cy.get('.clickable-row').then((rows) => {
const nums = [...Array(rows.length).keys()];
nums.forEach((index) => {
expect(rows[index].children[1].innerText).to.not.eq('copy of default');
cy.gtlGetRows([1]).then((rows) => {
rows.forEach((row) => {
expect(row).to.not.eq('copy of default');
});
});
});
Expand Down
50 changes: 42 additions & 8 deletions cypress/support/commands/gtl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,49 @@ Cypress.Commands.add('gtl_no_record', () => {
return cy.get('#miq-gtl-view > div.no-record').should('be.visible');
});

Cypress.Commands.add('gtl', () => {
cy.get('#miq-gtl-view').then($gtlTile => {
if ($gtlTile.find('miq-tile-view').length > 0) {
return cy.get('div[pf-card-view] > .card-view-pf > .card');
}
return cy.get('#miq-gtl-view > miq-data-table > div > table');
Cypress.Commands.add('gtlGetTable', () => {
return cy.get('#miq-gtl-view > .miq-data-table > .miq-data-table > .bx--data-table-content > table');
});

// 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)
Cypress.Commands.add('gtlGetRows', (columns) => {
const rowsData = [];
cy.gtlGetTable().get('tr.clickable-row').then((rows) => {
const numRows = [...Array(rows.length).keys()];
numRows.forEach((index) => {
const rowData = [];
columns.forEach((column) => {
rowData.push(rows[index].children[column].innerText);
});
rowsData.push(rowData);
});
}).then(() => {
return rowsData;
});
});

Cypress.Commands.add('gtl_click', (name) => {
cy.gtl().contains(name).click();
// 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).
Cypress.Commands.add('gtlClickRow', (columns) => {
let rowToClick;

cy.gtlGetTable().get('tr.clickable-row').then((rows) => {
const numRows = [...Array(rows.length).keys()];
numRows.forEach((index) => {
let click = false;
columns.forEach((column) => {
if (rows[index].children[column.number].innerText === column.title) {
click = true;
} else {
click = false;
}
});
if (click) {
rowToClick = rows[index];
}
});
}).then(() => {
cy.get(rowToClick).click();
});
});