chore[GH-#857]: Add unit tests for kanbanHiddenColumnItem (#1699)

This commit is contained in:
Julien Fabre 2021-11-01 06:27:49 +01:00 committed by GitHub
parent 7fa4c55473
commit 1b1d2b78a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 333 additions and 0 deletions

View file

@ -0,0 +1,231 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`src/components/kanban/kanbanHiddenColumnItem return kanbanHiddenColumnItem and click menuwrapper 1`] = `
<div>
<div
class="octo-board-hidden-item"
>
<div
aria-label="menuwrapper"
class="MenuWrapper"
role="button"
>
<span
class="Label propColorDefault "
>
propOption
</span>
<div
class="Menu noselect bottom"
>
<div
class="menu-contents"
>
<div
class="menu-options"
>
<div
aria-label="Show"
class="MenuOption TextOption menu-option"
role="button"
>
<svg
class="ShowIcon Icon"
viewBox="0 0 576 512"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M288 144a110.94 110.94 0 0 0-31.24 5 55.4 55.4 0 0 1 7.24 27 56 56 0 0 1-56 56 55.4 55.4 0 0 1-27-7.24A111.71 111.71 0 1 0 288 144zm284.52 97.4C518.29 135.59 410.93 64 288 64S57.68 135.64 3.48 241.41a32.35 32.35 0 0 0 0 29.19C57.71 376.41 165.07 448 288 448s230.32-71.64 284.52-177.41a32.35 32.35 0 0 0 0-29.19zM288 400c-98.65 0-189.09-55-237.93-144C98.91 167 189.34 112 288 112s189.09 55 237.93 144C477.1 345 386.66 400 288 400z"
/>
</svg>
<div
class="menu-name"
>
Show
</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>
<button
class="Button"
type="button"
>
<span>
1
</span>
</button>
</div>
</div>
`;
exports[`src/components/kanban/kanbanHiddenColumnItem return kanbanHiddenColumnItem, click menuwrapper and click show 1`] = `
<div>
<div
class="octo-board-hidden-item"
>
<div
aria-label="menuwrapper"
class="MenuWrapper"
role="button"
>
<span
class="Label propColorDefault "
>
propOption
</span>
<div
class="Menu noselect bottom"
>
<div
class="menu-contents"
>
<div
class="menu-options"
>
<div
aria-label="Show"
class="MenuOption TextOption menu-option"
role="button"
>
<svg
class="ShowIcon Icon"
viewBox="0 0 576 512"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M288 144a110.94 110.94 0 0 0-31.24 5 55.4 55.4 0 0 1 7.24 27 56 56 0 0 1-56 56 55.4 55.4 0 0 1-27-7.24A111.71 111.71 0 1 0 288 144zm284.52 97.4C518.29 135.59 410.93 64 288 64S57.68 135.64 3.48 241.41a32.35 32.35 0 0 0 0 29.19C57.71 376.41 165.07 448 288 448s230.32-71.64 284.52-177.41a32.35 32.35 0 0 0 0-29.19zM288 400c-98.65 0-189.09-55-237.93-144C98.91 167 189.34 112 288 112s189.09 55 237.93 144C477.1 345 386.66 400 288 400z"
/>
</svg>
<div
class="menu-name"
>
Show
</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>
<button
class="Button"
type="button"
>
<span>
1
</span>
</button>
</div>
</div>
`;
exports[`src/components/kanban/kanbanHiddenColumnItem should match snapshot 1`] = `
<div>
<div
class="octo-board-hidden-item"
>
<div
aria-label="menuwrapper"
class="MenuWrapper"
role="button"
>
<span
class="Label propColorDefault "
>
propOption
</span>
</div>
<button
class="Button"
type="button"
>
<span>
1
</span>
</button>
</div>
</div>
`;
exports[`src/components/kanban/kanbanHiddenColumnItem should match snapshot readonly 1`] = `
<div>
<div
class="octo-board-hidden-item"
>
<div
aria-label="menuwrapper"
class="MenuWrapper disabled"
role="button"
>
<span
class="Label propColorDefault "
>
propOption
</span>
</div>
<button
class="Button"
type="button"
>
<span>
1
</span>
</button>
</div>
</div>
`;

View file

@ -0,0 +1,102 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react'
import {render, screen, within} from '@testing-library/react'
import '@testing-library/jest-dom'
import userEvent from '@testing-library/user-event'
import {createIntl} from 'react-intl'
import {mocked} from 'ts-jest/utils'
import {wrapDNDIntl} from '../../testUtils'
import Mutator from '../../mutator'
import {TestBlockFactory} from '../../test/testBlockFactory'
import {IPropertyOption} from '../../blocks/board'
import KanbanHiddenColumnItem from './kanbanHiddenColumnItem'
jest.mock('../../mutator')
const mockedMutator = mocked(Mutator, true)
describe('src/components/kanban/kanbanHiddenColumnItem', () => {
const intl = createIntl({locale: 'en-us'})
const board = TestBlockFactory.createBoard()
const activeView = TestBlockFactory.createBoardView(board)
const card = TestBlockFactory.createCard(board)
const option:IPropertyOption = {
id: 'id1',
value: 'propOption',
color: 'propColorDefault',
}
beforeAll(() => {
console.error = jest.fn()
})
test('should match snapshot', () => {
const {container} = render(wrapDNDIntl(
<KanbanHiddenColumnItem
activeView={activeView}
group={{
option,
cards: [card],
}}
readonly={false}
onDrop={jest.fn()}
intl={intl}
/>,
))
expect(container).toMatchSnapshot()
})
test('should match snapshot readonly', () => {
const {container} = render(wrapDNDIntl(
<KanbanHiddenColumnItem
activeView={activeView}
group={{
option,
cards: [card],
}}
readonly={true}
onDrop={jest.fn()}
intl={intl}
/>,
))
expect(container).toMatchSnapshot()
})
test('return kanbanHiddenColumnItem and click menuwrapper', () => {
const {container} = render(wrapDNDIntl(
<KanbanHiddenColumnItem
activeView={activeView}
group={{
option,
cards: [card],
}}
readonly={false}
onDrop={jest.fn()}
intl={intl}
/>,
))
const buttonMenuWrapper = screen.getByRole('button', {name: 'menuwrapper'})
expect(buttonMenuWrapper).not.toBeNull()
userEvent.click(buttonMenuWrapper)
expect(container).toMatchSnapshot()
})
test('return kanbanHiddenColumnItem, click menuwrapper and click show', () => {
const {container} = render(wrapDNDIntl(
<KanbanHiddenColumnItem
activeView={activeView}
group={{
option,
cards: [card],
}}
readonly={false}
onDrop={jest.fn()}
intl={intl}
/>,
))
const buttonMenuWrapper = screen.getByRole('button', {name: 'menuwrapper'})
expect(buttonMenuWrapper).not.toBeNull()
userEvent.click(buttonMenuWrapper)
expect(container).toMatchSnapshot()
const buttonShow = within(buttonMenuWrapper).getByRole('button', {name: 'Show'})
userEvent.click(buttonShow)
expect(mockedMutator.unhideViewColumn).toBeCalledWith(activeView, option.id)
})
})