[GH-132] Add unit test to cover delete and name change event in propertyMenu component
This commit is contained in:
parent
080e5f8fe8
commit
26af2916c4
1 changed files with 41 additions and 4 deletions
|
@ -2,7 +2,7 @@
|
|||
// See LICENSE.txt for license information.
|
||||
|
||||
import React from 'react'
|
||||
import {render} from '@testing-library/react'
|
||||
import {fireEvent, render, screen} from '@testing-library/react'
|
||||
import '@testing-library/jest-dom'
|
||||
import {IntlProvider} from 'react-intl'
|
||||
|
||||
|
@ -16,8 +16,6 @@ describe('widgets/PropertyMenu', () => {
|
|||
})
|
||||
|
||||
test('should display the type of property', () => {
|
||||
const rootPortalDiv = document.createElement('div')
|
||||
rootPortalDiv.id = 'root-portal'
|
||||
const callback = jest.fn()
|
||||
|
||||
const {getByText} = render(
|
||||
|
@ -31,9 +29,48 @@ describe('widgets/PropertyMenu', () => {
|
|||
onDelete={callback}
|
||||
/>
|
||||
</IntlProvider>,
|
||||
{container: document.body.appendChild(rootPortalDiv)},
|
||||
)
|
||||
|
||||
expect(getByText('Type: Email')).toBeVisible()
|
||||
})
|
||||
|
||||
test('handles delete event', () => {
|
||||
const callback = jest.fn()
|
||||
|
||||
render(
|
||||
<IntlProvider locale='en'>
|
||||
<PropertyMenu
|
||||
propertyId={'id'}
|
||||
propertyName={'email of a person'}
|
||||
propertyType={'email'}
|
||||
onTypeChanged={callback}
|
||||
onNameChanged={callback}
|
||||
onDelete={callback}
|
||||
/>
|
||||
</IntlProvider>,
|
||||
)
|
||||
fireEvent.click(screen.getByText(/delete/i))
|
||||
expect(callback).toHaveBeenCalledWith('id')
|
||||
})
|
||||
|
||||
test('handles name change event', () => {
|
||||
const callback = jest.fn()
|
||||
|
||||
render(
|
||||
<IntlProvider locale='en'>
|
||||
<PropertyMenu
|
||||
propertyId={'id'}
|
||||
propertyName={'test-property'}
|
||||
propertyType={'text'}
|
||||
onTypeChanged={callback}
|
||||
onNameChanged={callback}
|
||||
onDelete={callback}
|
||||
/>
|
||||
</IntlProvider>,
|
||||
)
|
||||
const input = screen.getByDisplayValue(/test-property/i)
|
||||
fireEvent.change(input, {target: {value: 'changed name'}})
|
||||
fireEvent.blur(input)
|
||||
expect(callback).toHaveBeenCalledWith('changed name')
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue