Skip to content

Commit

Permalink
add test for closing picker on outside click
Browse files Browse the repository at this point in the history
  • Loading branch information
joakbjerk committed Dec 1, 2023
1 parent 2f437ee commit bc2dc77
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import React from 'react'
import { axeComponent, loadScss, wait } from '../../../core/jest/jestSetup'
import userEvent from '@testing-library/user-event'
import DatePicker, { DatePickerProps } from '../DatePicker'

jest.setTimeout(30e3)
Expand Down Expand Up @@ -83,6 +84,40 @@ describe('DatePicker component', () => {
).not.toContain('dnb-date-picker--closed')
})

it('will close the picker on click outside', async () => {
render(<DatePicker {...defaultProps} />)

await userEvent.click(
document.querySelector('button.dnb-input__submit-button__button')
)

expect(
document
.querySelector('button.dnb-input__submit-button__button')

.getAttribute('aria-expanded')
).toBe('true')

expect(
document
.querySelector('.dnb-date-picker')

.getAttribute('class')
).toContain('dnb-date-picker--opened')

await userEvent.click(document.body)

expect(
document
.querySelector('button.dnb-input__submit-button__button')
.getAttribute('aria-expanded')
).toBe('false')

expect(
document.querySelector('.dnb-date-picker').getAttribute('class')
).not.toContain('dnb-date-picker--opened')
})

it('will close the picker after selection', () => {
const on_change = jest.fn()
const { rerender } = render(
Expand Down

0 comments on commit bc2dc77

Please sign in to comment.