-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: virtual scroll breaks on last chunk
- Loading branch information
Showing
2 changed files
with
146 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
const testArray = new Array(1000).fill(0).map((x, i) => ({ | ||
text: `Option ${i + 1}` | ||
})); | ||
|
||
const selectpickerConfigs = [{ | ||
title: 'Select option with line-height style', | ||
config: { | ||
html: ` | ||
<select class="selectpicker" data-virtual-scroll="true"> | ||
${testArray.map(({ text }) => | ||
`<option value="${text}" style="line-height: 1.6275;">${text}</option>` | ||
).join('')} | ||
</select> | ||
`, | ||
options: { | ||
virtualScroll: true | ||
} | ||
} | ||
}, { | ||
title: 'Select option with default style', | ||
config: { | ||
html: ` | ||
<select class="selectpicker" data-virtual-scroll="true"> | ||
${testArray.map(({ text }) => | ||
`<option value="${text}">${text}</option>` | ||
).join('')} | ||
</select> | ||
`, | ||
options: { | ||
virtualScroll: true | ||
} | ||
} | ||
}]; | ||
|
||
describe('Virtual scroll with custom select option style', () => { | ||
beforeEach(() => { | ||
cy.visit('/tests/index.html'); | ||
}); | ||
|
||
selectpickerConfigs.forEach(({title, config}) => { | ||
it(title, () => { | ||
cy.selectpicker(config).then(($select) => { | ||
const firstSelectOptionText = testArray.at(0).text; | ||
const lastSelectOptionText = testArray.at(-1).text; | ||
const button = `[data-id="${$select[0].id}"]`; | ||
|
||
cy.get(button).click(); | ||
const dropdownMenu = cy.get('.dropdown-menu [role="listbox"]'); | ||
|
||
dropdownMenu.type('{upArrow}'); | ||
cy.get('li').contains(lastSelectOptionText) | ||
.should('have.class', 'active'); | ||
|
||
dropdownMenu.type('{enter}'); | ||
cy.get(button).find('.filter-option-inner-inner') | ||
.should('contain', lastSelectOptionText); | ||
|
||
cy.get(button).click(); | ||
dropdownMenu.type('{downArrow}'); | ||
|
||
cy.get('li').contains(firstSelectOptionText) | ||
.should('have.class', 'active'); | ||
|
||
dropdownMenu.type('{enter}'); | ||
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; | ||
cy.get('li').contains(text) | ||
.should('have.class', 'active'); | ||
dropdownMenu.type('{downArrow}'); | ||
} | ||
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}'); | ||
cy.get('li').contains(text) | ||
.should('have.class', 'active'); | ||
} | ||
cy.get(button).click(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters