1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-15 09:14:11 +02:00

[GH-132] Clean up and refactoring

This commit is contained in:
Renjith 2021-03-19 14:01:31 -05:00
parent ef5e72ab7c
commit ddc357ed35

View File

@ -2,12 +2,14 @@
// See LICENSE.txt for license information.
import React from 'react'
import {fireEvent, render, screen} from '@testing-library/react'
import {fireEvent, render} from '@testing-library/react'
import '@testing-library/jest-dom'
import {IntlProvider} from 'react-intl'
import PropertyMenu from './propertyMenu'
const wrapIntl = (children: any) => <IntlProvider locale='en'>{children}</IntlProvider>
describe('widgets/PropertyMenu', () => {
beforeEach(() => {
// Quick fix to disregard console error when unmounting a component
@ -17,58 +19,51 @@ describe('widgets/PropertyMenu', () => {
test('should display the type of property', () => {
const callback = jest.fn()
const {getByText} = render(
<IntlProvider locale='en'>
<PropertyMenu
propertyId={'id'}
propertyName={'email of a person'}
propertyType={'email'}
onTypeChanged={callback}
onNameChanged={callback}
onDelete={callback}
/>
</IntlProvider>,
const component = wrapIntl(
<PropertyMenu
propertyId={'id'}
propertyName={'email of a person'}
propertyType={'email'}
onTypeChanged={callback}
onNameChanged={callback}
onDelete={callback}
/>,
)
const {getByText} = render(component)
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>,
const component = wrapIntl(
<PropertyMenu
propertyId={'id'}
propertyName={'email of a person'}
propertyType={'email'}
onTypeChanged={callback}
onNameChanged={callback}
onDelete={callback}
/>,
)
fireEvent.click(screen.getByText(/delete/i))
const {getByText} = render(component)
fireEvent.click(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 component = wrapIntl(
<PropertyMenu
propertyId={'id'}
propertyName={'test-property'}
propertyType={'text'}
onTypeChanged={callback}
onNameChanged={callback}
onDelete={callback}
/>,
)
const input = screen.getByDisplayValue(/test-property/i)
const {getByDisplayValue} = render(component)
const input = getByDisplayValue(/test-property/i)
fireEvent.change(input, {target: {value: 'changed name'}})
fireEvent.blur(input)
expect(callback).toHaveBeenCalledWith('changed name')
@ -76,22 +71,20 @@ describe('widgets/PropertyMenu', () => {
test('handles type 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 component = wrapIntl(
<PropertyMenu
propertyId={'id'}
propertyName={'test-property'}
propertyType={'text'}
onTypeChanged={callback}
onNameChanged={callback}
onDelete={callback}
/>,
)
const menuOpen = screen.getByText(/Type: Text/i)
const {getByText} = render(component)
const menuOpen = getByText(/Type: Text/i)
fireEvent.click(menuOpen)
fireEvent.click(screen.getByText('Select'))
fireEvent.click(getByText('Select'))
expect(callback).toHaveBeenCalledWith('select')
})
})