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
Changes from 1 commit
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
82 changes: 76 additions & 6 deletions src/SmartComponents/SystemAdvisor/SystemAdvisor.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,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 +85,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 +94,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 +107,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 +145,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 +163,73 @@ describe('system rules table', () => {
cy.get('.ins-c-primary-toolbar__first-action').should('not.exist');
});
});

describe('BulkSelector', () => {
function selectRandomEnabledRows({
opacut marked this conversation as resolved.
Show resolved Hide resolved
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();
});
}

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

// check that empty
cy.get(':nth-child(2) > .pf-v5-c-menu-toggle').should('have.text', '')
opacut marked this conversation as resolved.
Show resolved Hide resolved

// 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(':nth-child(2) > .pf-v5-c-menu-toggle').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('[data-ouia-component-id="BulkSelectList-0"] > .pf-v5-c-menu__item > .pf-v5-c-menu__item-main > .pf-v5-c-menu__item-text').click()
opacut marked this conversation as resolved.
Show resolved Hide resolved

// check that none selected
cy.get(':nth-child(2) > .pf-v5-c-menu-toggle').should('have.text', '')

// Select All
cy.get(':nth-child(2) > .pf-v5-c-menu-toggle > .pf-v5-c-menu-toggle__controls').click();
cy.get('[data-ouia-component-id="BulkSelectList-1"] > .pf-v5-c-menu__item > .pf-v5-c-menu__item-main > .pf-v5-c-menu__item-text').click()

// check that all selected
cy.get(':nth-child(2) > .pf-v5-c-menu-toggle').should('have.text', '7 selected')

// click the BS
cy.get('[data-ouia-component-id="BulkSelect"').click();

// check that none selected
cy.get(':nth-child(2) > .pf-v5-c-menu-toggle').should('have.text', '')

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

// click the BS
cy.get('[data-ouia-component-id="BulkSelect"').click();

// check that all selected
cy.get(':nth-child(2) > .pf-v5-c-menu-toggle').should('have.text', '7 selected')
});
});
});