1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-24 13:43:12 +02:00

chore: add tests unit on emptycardbutton (#1458)

This commit is contained in:
Julien Fabre 2021-10-06 21:09:43 +02:00 committed by GitHub
parent 85ccc051ec
commit 74a3c63ddc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 280 additions and 0 deletions

View File

@ -0,0 +1,192 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/viewHeader/emptyCardButton return EmptyCardButton 1`] = `
<div>
<div
aria-label="Empty card"
class="MenuOption TextOption menu-option bold-menu-text"
role="button"
>
<svg
class="CardIcon Icon"
viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg"
>
<rect
height="40"
rx="3"
ry="3"
width="60"
x="20"
y="30"
/>
</svg>
<div
class="menu-name"
>
Empty card
</div>
<div
aria-label="menuwrapper"
class="MenuWrapper"
role="button"
>
<div
class="Button IconButton"
role="button"
>
<i
class="CompassIcon icon-dots-horizontal OptionsIcon"
/>
</div>
</div>
</div>
</div>
`;
exports[`components/viewHeader/emptyCardButton return EmptyCardButton and Set Template 1`] = `
<div>
<div
aria-label="Empty card"
class="MenuOption TextOption menu-option bold-menu-text"
role="button"
>
<svg
class="CardIcon Icon"
viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg"
>
<rect
height="40"
rx="3"
ry="3"
width="60"
x="20"
y="30"
/>
</svg>
<div
class="menu-name"
>
Empty card
</div>
<div
aria-label="menuwrapper"
class="MenuWrapper"
role="button"
>
<div
class="Button IconButton"
role="button"
>
<i
class="CompassIcon icon-dots-horizontal OptionsIcon"
/>
</div>
<div
class="Menu noselect left"
>
<div
class="menu-contents"
>
<div
class="menu-options"
>
<div
aria-label="Set as default"
class="MenuOption TextOption menu-option"
role="button"
>
<svg
class="CheckIcon Icon"
viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg"
>
<polyline
points="20,60 40,80 80,40"
/>
</svg>
<div
class="menu-name"
>
Set as default
</div>
<div
class="noicon"
/>
</div>
</div>
<div
class="menu-spacer hideOnWidescreen"
/>
<div
class="menu-options hideOnWidescreen"
>
<div
aria-label="Cancel"
class="MenuOption TextOption menu-option menu-cancel"
role="button"
>
<div
class="noicon"
/>
<div
class="menu-name"
>
Cancel
</div>
<div
class="noicon"
/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
`;
exports[`components/viewHeader/emptyCardButton return EmptyCardButton and addCard 1`] = `
<div>
<div
aria-label="Empty card"
class="MenuOption TextOption menu-option bold-menu-text"
role="button"
>
<svg
class="CardIcon Icon"
viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg"
>
<rect
height="40"
rx="3"
ry="3"
width="60"
x="20"
y="30"
/>
</svg>
<div
class="menu-name"
>
Empty card
</div>
<div
aria-label="menuwrapper"
class="MenuWrapper"
role="button"
>
<div
class="Button IconButton"
role="button"
>
<i
class="CompassIcon icon-dots-horizontal OptionsIcon"
/>
</div>
</div>
</div>
</div>
`;

View File

@ -0,0 +1,88 @@
// 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 {mocked} from 'ts-jest/utils'
import {wrapIntl, mockStateStore} from '../../testUtils'
import {TestBlockFactory} from '../../test/testBlockFactory'
import mutator from '../../mutator'
import EmptyCardButton from './emptyCardButton'
const board = TestBlockFactory.createBoard()
const activeView = TestBlockFactory.createBoardView(board)
jest.mock('../../mutator')
const mockedMutator = mocked(mutator, true)
describe('components/viewHeader/emptyCardButton', () => {
const state = {
users: {
me: {
id: 'user-id-1',
username: 'username_1'},
},
views: {
current: 0,
views: [activeView],
},
}
const store = mockStateStore([], state)
const mockFunction = jest.fn()
beforeEach(() => {
jest.clearAllMocks()
})
test('return EmptyCardButton', () => {
const {container} = render(
wrapIntl(
<ReduxProvider store={store}>
<EmptyCardButton
addCard={mockFunction}
/>
</ReduxProvider>,
),
)
expect(container).toMatchSnapshot()
})
test('return EmptyCardButton and addCard', () => {
const {container} = render(
wrapIntl(
<ReduxProvider store={store}>
<EmptyCardButton
addCard={mockFunction}
/>
</ReduxProvider>,
),
)
expect(container).toMatchSnapshot()
const buttonEmpty = screen.getByRole('button', {name: 'Empty card'})
userEvent.click(buttonEmpty)
expect(mockFunction).toBeCalledTimes(1)
})
test('return EmptyCardButton and Set Template', () => {
const {container} = render(
wrapIntl(
<ReduxProvider store={store}>
<EmptyCardButton
addCard={mockFunction}
/>
</ReduxProvider>,
),
)
const buttonElement = screen.getByRole('button', {name: 'menuwrapper'})
userEvent.click(buttonElement)
expect(container).toMatchSnapshot()
const buttonDefault = screen.getByRole('button', {name: 'Set as default'})
userEvent.click(buttonDefault)
expect(mockedMutator.clearDefaultTemplate).toBeCalledTimes(1)
})
})