Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cypress test to bulk select #1314

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 26 additions & 1 deletion cypress/utils/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,29 @@ function* cumulativeCombinations(arr, current = []) {
}
}

export { checkSorting, cypressApplyFilters, cumulativeCombinations };
function selectRandomEnabledRows({
rows,
numberOfRowsToSelect,
}) {
const enabledRows = Array.from(rows).filter(row => {
const checkbox = row.querySelector('input[type="checkbox"]');
if(!checkbox.hasAttribute('disabled')){
return true;
}
})
const rowCount = enabledRows.length

const randomIndices = [];
while (randomIndices.length < numberOfRowsToSelect) {
const randomIndex = Math.floor(Math.random() * rowCount);
if (!randomIndices.includes(randomIndex)) {
randomIndices.push(randomIndex);
}
}

randomIndices.forEach(index => {
enabledRows[index].querySelector('input[type="checkbox"]').click();
});
}

export { checkSorting, cypressApplyFilters, cumulativeCombinations, selectRandomEnabledRows };
60 changes: 54 additions & 6 deletions src/SmartComponents/SystemAdvisor/SystemAdvisor.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { BaseSystemAdvisor as SystemAdvisor } from './SystemAdvisor';
// eslint-disable-next-line rulesdir/disallow-fec-relative-imports
import {
checkTableHeaders,
PT_BULK_SELECT,
PT_BULK_SELECT_LIST,
SORTING_ORDERS,
TABLE,
TOOLBAR,
Expand All @@ -14,6 +16,7 @@ import { checkSorting } from '../../../cypress/utils/table';
import Wrapper from '../../Utilities/Wrapper';
import { INVENTORY_BASE_URL } from '../../AppConstants';
import systemProfile from '../../../cypress/fixtures/systemProfile.json';
import { selectRandomEnabledRows } from '../../../cypress/utils/table';

const TABLE_HEADERS = [
'Description',
Expand Down Expand Up @@ -70,11 +73,11 @@ describe('system rules table', () => {
cy.get(TOOLBAR).should('have.length', 1);
cy.get(TABLE).should('have.length', 1);
});

it('renders table headers', () => {
checkTableHeaders(TABLE_HEADERS);
});

// it('renders "First impacted" date correctly', () => {
// const {
// rule: { description },
Expand All @@ -85,7 +88,7 @@ describe('system rules table', () => {
// applyFilters({ description }, filtersConf);
// cy.get('td[data-label="First impacted"]').first().should('contain', date);
// });

it('request to kcs contains all required ids', () => {
cy.wait('@kcs')
.its('request.url')
Expand All @@ -94,7 +97,7 @@ describe('system rules table', () => {
fixtures.map(({ rule }) => rule.node_id).join('%20OR%20')
);
});

// it('link to kcs has correct title and url', () => {
// const {
// rule: { description, node_id },
Expand All @@ -107,7 +110,7 @@ describe('system rules table', () => {
// .should('include.text', kcsEntry?.publishedTitle)
// .should('have.attr', 'href', kcsEntry?.view_uri);
// });

describe('sorting', () => {
_.zip(
[
Expand Down Expand Up @@ -145,7 +148,8 @@ describe('system rules table', () => {
});
});
});



describe('Toolbar actions', () => {
it('Should show remediation button when host is of type edge', () => {
cy.get('.ins-c-primary-toolbar__first-action').contains('Remediation');
Expand All @@ -162,4 +166,48 @@ describe('system rules table', () => {
cy.get('.ins-c-primary-toolbar__first-action').should('not.exist');
});
});

describe('BulkSelector', () => {
it(`The Bulk selector shows the correct number of systems selected.`, () => {

// check that empty
cy.get(PT_BULK_SELECT).should('have.text', '');

// select a couple
// but only ones that can be selected
cy.get('.pf-v5-c-table__tbody').then(rows => {selectRandomEnabledRows({rows: rows, numberOfRowsToSelect: 3})});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cy.get('.pf-v5-c-table__tbody').then(rows => {selectRandomEnabledRows({rows: rows, numberOfRowsToSelect: 3})});
cy.get(TABLE).then(rows => selectRandomEnabledRows({rows: rows, numberOfRowsToSelect: 3}));

https://github.com/RedHatInsights/frontend-components/blob/master/packages/utils/src/TestingUtils/CypressUtils/selectors.js#L18

Copy link
Author

@opacut opacut Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one doesn't work - the test gets stuck


// check that it shows correct number
cy.get(PT_BULK_SELECT).should('have.text', '3 selected')

// Select None
cy.get(':nth-child(2) > .pf-v5-c-menu-toggle > .pf-v5-c-menu-toggle__controls').click();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use PT_BULK_SELECT from FEC to select the bulk select toggle

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PT_BULK_SELECT results in a flaky test. I think it's because it targets the pf-v5-c-menu-toggle element, instead of the pf-v5-c-menu-toggle__controls element. In some cases it then doesn't open the BS menu

cy.get(PT_BULK_SELECT_LIST).contains('Select none').click();

// check that none selected
cy.get(PT_BULK_SELECT).should('have.text', '')

// Select All
cy.get(':nth-child(2) > .pf-v5-c-menu-toggle > .pf-v5-c-menu-toggle__controls').click();
cy.get(PT_BULK_SELECT_LIST).contains('Select all').click();

// check that all selected
cy.get(PT_BULK_SELECT).should('have.text', '7 selected')

// click the BS
cy.get(PT_BULK_SELECT).click();

// check that none selected
cy.get(PT_BULK_SELECT).should('have.text', '')

// select some
cy.get('.pf-v5-c-table__tbody').then(rows => {selectRandomEnabledRows({rows: rows, numberOfRowsToSelect: 3})});

// click the BS
cy.get(PT_BULK_SELECT).click();

// check that all selected
cy.get(PT_BULK_SELECT).should('have.text', '7 selected')
});
});
});