Spaces:
Sleeping
Sleeping
File size: 3,565 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 | // 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 'jest-mock'
import {TestBlockFactory} from '../../test/testBlockFactory'
import {wrapIntl, mockStateStore} from '../../testUtils'
import {Archiver} from '../../archiver'
import {CsvExporter} from '../../csvExporter'
import ViewHeaderActionsMenu from './viewHeaderActionsMenu'
jest.mock('../../archiver')
jest.mock('../../csvExporter')
jest.mock('../../mutator')
const mockedArchiver = mocked(Archiver, true)
const mockedCsvExporter = mocked(CsvExporter, true)
const board = TestBlockFactory.createBoard()
const activeView = TestBlockFactory.createBoardView(board)
const card = TestBlockFactory.createCard(board)
describe('components/viewHeader/viewHeaderActionsMenu', () => {
const state = {
users: {
me: {
id: 'user-id-1',
username: 'username_1',
},
},
}
const store = mockStateStore([], state)
beforeEach(() => {
jest.clearAllMocks()
})
test('return menu', () => {
const {container} = render(
wrapIntl(
<ReduxProvider store={store}>
<ViewHeaderActionsMenu
board={board}
activeView={activeView}
cards={[card]}
/>
</ReduxProvider>,
),
)
const buttonElement = screen.getByRole('button', {
name: 'View header menu',
})
userEvent.click(buttonElement)
expect(container).toMatchSnapshot()
})
test('return menu and verify call to csv exporter', () => {
const {container} = render(
wrapIntl(
<ReduxProvider store={store}>
<ViewHeaderActionsMenu
board={board}
activeView={activeView}
cards={[card]}
/>
</ReduxProvider>,
),
)
const buttonElement = screen.getByRole('button', {name: 'View header menu'})
userEvent.click(buttonElement)
expect(container).toMatchSnapshot()
const buttonExportCSV = screen.getByRole('button', {name: 'Export to CSV'})
userEvent.click(buttonExportCSV)
expect(mockedCsvExporter.exportTableCsv).toBeCalledTimes(1)
})
test('return menu and verify call to board archive', () => {
const {container} = render(
wrapIntl(
<ReduxProvider store={store}>
<ViewHeaderActionsMenu
board={board}
activeView={activeView}
cards={[card]}
/>
</ReduxProvider>,
),
)
const buttonElement = screen.getByRole('button', {name: 'View header menu'})
userEvent.click(buttonElement)
expect(container).toMatchSnapshot()
const buttonExportBoardArchive = screen.getByRole('button', {name: 'Export board archive'})
userEvent.click(buttonExportBoardArchive)
expect(mockedArchiver.exportBoardArchive).toBeCalledTimes(1)
expect(mockedArchiver.exportBoardArchive).toBeCalledWith(board)
})
})
|