Spaces:
Sleeping
Sleeping
File size: 3,654 Bytes
13555f3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react'
import {render, screen, fireEvent} from '@testing-library/react'
import RootInput from './rootInput'
describe('components/blocksEditor/rootInput', () => {
test('should match Display snapshot', async () => {
const {container} = render(
<RootInput
onChange={jest.fn()}
value='test-value'
onChangeType={jest.fn()}
onSave={jest.fn()}
/>,
)
expect(container).toMatchSnapshot()
})
test('should match Input snapshot', async () => {
const {container} = render(
<RootInput
onChange={jest.fn()}
value='test-value'
onChangeType={jest.fn()}
onSave={jest.fn()}
/>,
)
expect(container).toMatchSnapshot()
})
test('should match Input snapshot with menu open', async () => {
const {container} = render(
<RootInput
onChange={jest.fn()}
value=''
onChangeType={jest.fn()}
onSave={jest.fn()}
/>,
)
const input = screen.getByDisplayValue('')
fireEvent.change(input, {target: {value: '/'}})
expect(container).toMatchSnapshot()
})
test('should emit onChange event', async () => {
const onChange = jest.fn()
render(
<RootInput
onChange={onChange}
value='test-value'
onChangeType={jest.fn()}
onSave={jest.fn()}
/>,
)
expect(onChange).not.toBeCalled()
const input = screen.getByDisplayValue('test-value')
fireEvent.change(input, {target: {value: 'test-value-'}})
expect(onChange).toBeCalled()
})
test('should not emit onChangeType event when value is not empty and hit backspace', async () => {
const onChangeType = jest.fn()
render(
<RootInput
onChange={jest.fn()}
value='test-value'
onChangeType={onChangeType}
onSave={jest.fn()}
/>,
)
expect(onChangeType).not.toBeCalled()
const input = screen.getByDisplayValue('test-value')
fireEvent.keyDown(input, {key: 'Backspace'})
expect(onChangeType).not.toBeCalled()
})
test('should emit onSave event hit enter', async () => {
const onSave = jest.fn()
render(
<RootInput
onChange={jest.fn()}
value='test-value'
onChangeType={jest.fn()}
onSave={onSave}
/>,
)
expect(onSave).not.toBeCalled()
const input = screen.getByDisplayValue('test-value')
fireEvent.keyDown(input, {key: 'Enter'})
expect(onSave).toBeCalled()
})
test('should emit onChangeType event on menu option selected', async () => {
const onChangeType = jest.fn()
render(
<RootInput
onChange={jest.fn()}
value=''
onChangeType={onChangeType}
onSave={jest.fn()}
/>,
)
const input = screen.getByDisplayValue('')
fireEvent.change(input, {target: {value: '/'}})
const option = screen.getByText('/title Creates a new Title block.')
fireEvent.click(option)
expect(onChangeType).toBeCalledWith(expect.objectContaining({name: 'h1'}))
})
})
|