[GH-868]: add unit tests viewHeaderSearch (#1406)
* chore[#868]: add unit tests viewHeaderSearch * fix: review test and add testUtils
This commit is contained in:
parent
b02708173a
commit
cd261224c4
2 changed files with 99 additions and 0 deletions
|
@ -0,0 +1,35 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`components/viewHeader/ViewHeaderSearch return input after click on search button 1`] = `
|
||||||
|
<div>
|
||||||
|
<input
|
||||||
|
class="Editable undefined"
|
||||||
|
placeholder="Search text"
|
||||||
|
value=""
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`components/viewHeader/ViewHeaderSearch return search menu 1`] = `
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
class="Button "
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
Search
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`components/viewHeader/ViewHeaderSearch search text after input after click on search button and search text 1`] = `
|
||||||
|
<div>
|
||||||
|
<input
|
||||||
|
class="Editable undefined"
|
||||||
|
placeholder="Search text"
|
||||||
|
title="Hello"
|
||||||
|
value="Hello"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
`;
|
64
webapp/src/components/viewHeader/viewHeaderSearch.test.tsx
Normal file
64
webapp/src/components/viewHeader/viewHeaderSearch.test.tsx
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See LICENSE.txt for license information.
|
||||||
|
import React from 'react'
|
||||||
|
import {render, screen} from '@testing-library/react'
|
||||||
|
import {Provider as ReduxProvider} from 'react-redux'
|
||||||
|
|
||||||
|
import '@testing-library/jest-dom'
|
||||||
|
import userEvent from '@testing-library/user-event'
|
||||||
|
|
||||||
|
import {mockStateStore, wrapIntl} from '../../testUtils'
|
||||||
|
|
||||||
|
import ViewHeaderSearch from './viewHeaderSearch'
|
||||||
|
|
||||||
|
describe('components/viewHeader/ViewHeaderSearch', () => {
|
||||||
|
const state = {
|
||||||
|
users: {
|
||||||
|
me: {
|
||||||
|
id: 'user-id-1',
|
||||||
|
username: 'username_1'},
|
||||||
|
},
|
||||||
|
searchText: {
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const store = mockStateStore([], state)
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
})
|
||||||
|
test('return search menu', () => {
|
||||||
|
const {container} = render(
|
||||||
|
wrapIntl(
|
||||||
|
<ReduxProvider store={store}>
|
||||||
|
<ViewHeaderSearch/>
|
||||||
|
</ReduxProvider>,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
expect(container).toMatchSnapshot()
|
||||||
|
})
|
||||||
|
test('return input after click on search button', () => {
|
||||||
|
const {container} = render(
|
||||||
|
wrapIntl(
|
||||||
|
<ReduxProvider store={store}>
|
||||||
|
<ViewHeaderSearch/>
|
||||||
|
</ReduxProvider>,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
const buttonElement = screen.getByRole('button')
|
||||||
|
userEvent.click(buttonElement)
|
||||||
|
expect(container).toMatchSnapshot()
|
||||||
|
})
|
||||||
|
test('search text after input after click on search button and search text', () => {
|
||||||
|
const {container} = render(
|
||||||
|
wrapIntl(
|
||||||
|
<ReduxProvider store={store}>
|
||||||
|
<ViewHeaderSearch/>
|
||||||
|
</ReduxProvider>,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
userEvent.click(screen.getByRole('button'))
|
||||||
|
const elementSearchText = screen.getByPlaceholderText('Search text')
|
||||||
|
userEvent.type(elementSearchText, 'Hello')
|
||||||
|
expect(container).toMatchSnapshot()
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in a new issue