Skip to content

Commit

Permalink
[#2826]add test
Browse files Browse the repository at this point in the history
  • Loading branch information
megumiimai committed Sep 3, 2023
1 parent 44f6398 commit 98f76ea
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions cypress/integration/trim_values_before_search.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
describe('Trim values before search', () => {
beforeEach(() => {
cy.visit('/tests/index.html');
});

it('Matches even if there are leading and trailing spaces', () => {
cy.selectpicker({
html: `
<select class="selectpicker" data-live-search="true">
${[
'apple',
'pear',
'dragon fruit'
].map((value) =>
`<option value="${value}">${value}</option>`
).join('')}}
</select>
`
}).then(($select) => {
const button = `[data-id="${$select[0].id}"]`;
cy.get(button).click();
$select.on('fetched.bs.select', cy.stub().as('fetched'));
[{
searchValue: ' app ', // leading and trailing spaces
expectedContain: 'apple'
}, {
searchValue: '  pea', // both half and full space mixed
expectedContain: 'pear'
}, {
searchValue: ' ', // text with half-space also match
expectedContain: 'dragon fruit'
}].forEach((test) => {
cy.get('input').type(test.searchValue);
cy.get('.dropdown-menu').find('li').first().should(($el) => {
expect($el).to.have.class('active')
expect($el).to.contain(test.expectedContain);
});
cy.get('.dropdown-menu').find('li').first().click();
cy.get(button).contains(test.expectedContain).click();
});
});
});
});

0 comments on commit 98f76ea

Please sign in to comment.