Skip to content

Commit

Permalink
test(@dpc-sdp/ripple-ui-core): ✅ adds tests for debounced input
Browse files Browse the repository at this point in the history
  • Loading branch information
dylankelly committed Aug 2, 2023
1 parent 2badcc4 commit 4473c85
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/ripple-ui-core/cypress/support/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ const RplAppWrapper = {

Cypress.Commands.add('mount', (component: any, options = {}) => {
return mount(() => {
return h(RplAppWrapper, null, () => h(component, { ...options.props }))
return h(RplAppWrapper, null, () =>
h(component, { ...options.props }, { ...options.slots })
)
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,59 @@ describe('RplSearchBar', () => {
cy.get('input#1234').click()
cy.get('#1234__menu').should('exist')
})

it('suggestion slot', () => {
cy.mount(RplSearchBar, {
props: {
...baseProps,
[`onUpdate:inputValue`]: () => {
console.log('testest')
}
},
slots: {
suggestion: (props) => `test - ${props.option.option}`
}
})
cy.get('input#1234').click()
cy.get('#rip').should('contain.text', `test - rip`)
})
it('updates', () => {
const onChangeSpy = cy.spy().as('onChangeSpy')
cy.mount(RplSearchBar, {
props: {
...baseProps,
[`onUpdate:inputValue`]: onChangeSpy
}
})
cy.get('input#1234').type('rip', { delay: 100 })
cy.get('@onChangeSpy').should('have.been.calledWith', 'rip')
})
it('debounces input', () => {
const onChangeSpy = cy.spy().as('onChangeSpy1')
cy.mount(RplSearchBar, {
props: {
...baseProps,
debounce: 1000,
[`onUpdate:inputValue`]: onChangeSpy
}
})
cy.get('input#1234').type('rip', { delay: 100 })
cy.wait(1500)
cy.get('input#1234').type('ple', { delay: 100 })
cy.get('@onChangeSpy1').should('have.callCount', 2)
})
it('doesnt debounce when turned off', () => {
const onChangeSpy = cy.spy().as('onChangeSpy1')
cy.mount(RplSearchBar, {
props: {
...baseProps,
debounce: 0,
[`onUpdate:inputValue`]: onChangeSpy
}
})
cy.get('input#1234').type('rip', { delay: 100 })
cy.wait(1500)
cy.get('input#1234').type('ple', { delay: 100 })
cy.get('@onChangeSpy1').should('have.callCount', 6)
})
})

0 comments on commit 4473c85

Please sign in to comment.