Skip to content

Commit

Permalink
refactor: optimize the performance of testing virtual scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-lai committed Nov 21, 2023
1 parent 30f3be4 commit 0b4eea4
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions cypress/e2e/virtual-scroll.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,33 +65,43 @@ describe('Virtual scroll with custom select option style', () => {
cy.get(button).find('.filter-option-inner-inner')
.should('contain', firstSelectOptionText);

// test the first 50 options
{
let n = 50;
let iterator = testArray.entries();
cy.get(button).click();
while (n--) {
const [, { text }] = iterator.next().value;
const n = 20;
const typeOptions = {
// Delay after each keypress (Default: 10)
delay: 0,
};

// Test the first n options.
let iterator = testArray.entries();
cy.get(button).click();

for (let i = 1; i <= n; i++) {
const [, { text }] = iterator.next().value;

// Sampling (testing every 5 typing actions)
if (i % 5 === 0) {
cy.get('li').contains(text)
.should('have.class', 'active');
dropdownMenu.type('{downArrow}');
}
cy.get(button).click();
dropdownMenu.type('{downArrow}', typeOptions);
}
cy.get(button).click();

// test the last 50 options
{
let n = 50;
let iterator = Array.from(testArray).reverse().entries();
cy.get(button).click();
while (n--) {
const [, { text }] = iterator.next().value;
dropdownMenu.type('{upArrow}');
// Test the last n select options.
iterator = Array.from(testArray).reverse().entries();
cy.get(button).click();

for (let i = 1; i <= n; i++) {
const [, { text }] = iterator.next().value;
dropdownMenu.type('{upArrow}', typeOptions);

// Sampling (testing every 5 typing actions)
if (i % 5 === 0) {
cy.get('li').contains(text)
.should('have.class', 'active');
}
cy.get(button).click();
}
cy.get(button).click();
});
});
});
Expand Down

0 comments on commit 0b4eea4

Please sign in to comment.