[GH-866] add unit test for viewHeaderGroupByMenu (#1403)

* --wip-- [skip ci]

* chore[#866]: add unit test for viewHeaderGroupByMenu

* fix: review test and add testUtils

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
Julien Fabre 2021-10-04 20:01:54 +02:00 committed by GitHub
parent 20933183b7
commit 7123311902
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 406 additions and 0 deletions

View file

@ -0,0 +1,313 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/viewHeader/viewHeaderGroupByMenu return groupBy menu 1`] = `
<div>
<div
aria-label="menuwrapper"
class="MenuWrapper"
role="button"
>
<button
class="Button "
type="button"
>
<span>
Group by:
<span
id="groupByLabel"
>
Status
</span>
</span>
</button>
<div
class="Menu noselect bottom"
>
<div
class="menu-contents"
>
<div
class="menu-options"
>
<div
aria-label="Status"
class="MenuOption TextOption menu-option"
role="button"
>
<div
class="noicon"
/>
<div
class="menu-name"
>
Status
</div>
<div
class="noicon"
/>
</div>
<div
aria-label="Property 1"
class="MenuOption TextOption menu-option"
role="button"
>
<div
class="noicon"
/>
<div
class="menu-name"
>
Property 1
</div>
<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>
<div
aria-label="Property 2"
class="MenuOption TextOption menu-option"
role="button"
>
<div
class="noicon"
/>
<div
class="menu-name"
>
Property 2
</div>
<div
class="noicon"
/>
</div>
<div
aria-label="Property 3"
class="MenuOption TextOption menu-option"
role="button"
>
<div
class="noicon"
/>
<div
class="menu-name"
>
Property 3
</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>
`;
exports[`components/viewHeader/viewHeaderGroupByMenu return groupBy menu and groupBy Status 1`] = `
<div>
<div
aria-label="menuwrapper"
class="MenuWrapper"
role="button"
>
<button
class="Button "
type="button"
>
<span>
Group by:
<span
id="groupByLabel"
>
Status
</span>
</span>
</button>
</div>
</div>
`;
exports[`components/viewHeader/viewHeaderGroupByMenu return groupBy menu and ungroup in viewType table 1`] = `
<div>
<div
aria-label="menuwrapper"
class="MenuWrapper"
role="button"
>
<button
class="Button "
type="button"
>
<span>
Group by:
<span
id="groupByLabel"
>
Status
</span>
</span>
</button>
<div
class="Menu noselect bottom"
>
<div
class="menu-contents"
>
<div
class="menu-options"
>
<div
aria-label="Ungroup"
class="MenuOption TextOption menu-option"
role="button"
>
<div
class="noicon"
/>
<div
class="menu-name"
>
Ungroup
</div>
<div
class="noicon"
/>
</div>
<div
class="MenuOption MenuSeparator menu-separator"
/>
<div
aria-label="Status"
class="MenuOption TextOption menu-option"
role="button"
>
<div
class="noicon"
/>
<div
class="menu-name"
>
Status
</div>
<div
class="noicon"
/>
</div>
<div
aria-label="Property 1"
class="MenuOption TextOption menu-option"
role="button"
>
<div
class="noicon"
/>
<div
class="menu-name"
>
Property 1
</div>
<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>
<div
aria-label="Property 2"
class="MenuOption TextOption menu-option"
role="button"
>
<div
class="noicon"
/>
<div
class="menu-name"
>
Property 2
</div>
<div
class="noicon"
/>
</div>
<div
aria-label="Property 3"
class="MenuOption TextOption menu-option"
role="button"
>
<div
class="noicon"
/>
<div
class="menu-name"
>
Property 3
</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>
`;

View file

@ -0,0 +1,93 @@
// 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 {TestBlockFactory} from '../../test/testBlockFactory'
import mutator from '../../mutator'
import {wrapIntl, mockStateStore} from '../../testUtils'
import ViewHeaderGroupByMenu from './viewHeaderGroupByMenu'
jest.mock('../../mutator')
const mockedMutator = mocked(mutator, true)
const board = TestBlockFactory.createBoard()
const activeView = TestBlockFactory.createBoardView(board)
const propertyName = 'Status'
describe('components/viewHeader/viewHeaderGroupByMenu', () => {
const state = {
users: {
me: {
id: 'user-id-1',
username: 'username_1'},
},
}
const store = mockStateStore([], state)
beforeEach(() => {
jest.clearAllMocks()
})
test('return groupBy menu', () => {
const {container} = render(
wrapIntl(
<ReduxProvider store={store}>
<ViewHeaderGroupByMenu
activeView={activeView}
groupByPropertyName={propertyName}
properties={board.fields.cardProperties}
/>
</ReduxProvider>,
),
)
const buttonElement = screen.getByRole('button', {name: 'menuwrapper'})
userEvent.click(buttonElement)
expect(container).toMatchSnapshot()
})
test('return groupBy menu and groupBy Status', () => {
const {container} = render(
wrapIntl(
<ReduxProvider store={store}>
<ViewHeaderGroupByMenu
activeView={activeView}
groupByPropertyName={propertyName}
properties={board.fields.cardProperties}
/>
</ReduxProvider>,
),
)
const buttonElement = screen.getByRole('button', {name: 'menuwrapper'})
userEvent.click(buttonElement)
const buttonStatus = screen.getByRole('button', {name: 'Status'})
userEvent.click(buttonStatus)
expect(container).toMatchSnapshot()
expect(mockedMutator.changeViewGroupById).toBeCalledTimes(1)
})
test('return groupBy menu and ungroup in viewType table', () => {
activeView.fields.viewType = 'table'
const {container} = render(
wrapIntl(
<ReduxProvider store={store}>
<ViewHeaderGroupByMenu
activeView={activeView}
groupByPropertyName={propertyName}
properties={board.fields.cardProperties}
/>
</ReduxProvider>,
),
)
const buttonElement = screen.getByRole('button', {name: 'menuwrapper'})
userEvent.click(buttonElement)
expect(container).toMatchSnapshot()
const buttonStatus = screen.getByRole('button', {name: 'Ungroup'})
userEvent.click(buttonStatus)
expect(mockedMutator.changeViewGroupById).toBeCalledTimes(1)
})
})