Spaces:
Sleeping
Sleeping
File size: 3,383 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 108 | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react'
import {fireEvent, render} from '@testing-library/react'
import '@testing-library/jest-dom'
import {wrapIntl} from '../../testUtils'
import 'isomorphic-fetch'
import {Constants} from '../../constants'
import mutator from '../../mutator'
import {TestBlockFactory} from '../../test/testBlockFactory'
import {FetchMock} from '../../test/fetchMock'
import TableHeaderMenu from './tableHeaderMenu'
global.fetch = FetchMock.fn
// import mutator from '../../mutator'
jest.mock('../../mutator', () => ({
changeViewSortOptions: jest.fn(),
insertPropertyTemplate: jest.fn(),
changeViewVisibleProperties: jest.fn(),
duplicatePropertyTemplate: jest.fn(),
deleteProperty: jest.fn(),
}))
beforeEach(() => {
jest.resetAllMocks()
FetchMock.fn.mockReset()
})
describe('components/table/TableHeaderMenu', () => {
const board = TestBlockFactory.createBoard()
const view = TestBlockFactory.createBoardView(board)
const view2 = TestBlockFactory.createBoardView(board)
view2.fields.sortOptions = []
test('should match snapshot, title column', async () => {
const component = wrapIntl(
<TableHeaderMenu
templateId={Constants.titleColumnId}
board={board}
activeView={view}
views={[view, view2]}
cards={[]}
/>,
)
const {container, getByText} = render(component)
let sort = getByText(/Sort ascending/i)
fireEvent.click(sort)
sort = getByText(/Sort descending/i)
fireEvent.click(sort)
expect(mutator.changeViewSortOptions).toHaveBeenCalledTimes(2)
let insert = getByText(/Insert left/i)
fireEvent.click(insert)
insert = getByText(/Insert right/i)
fireEvent.click(insert)
expect(mutator.insertPropertyTemplate).toHaveBeenCalledTimes(0)
expect(container).toMatchSnapshot()
})
test('should match snapshot, other column', async () => {
const component = wrapIntl(
<TableHeaderMenu
templateId={'property 1'}
board={board}
activeView={view}
views={[view, view2]}
cards={[]}
/>,
)
const {container, getByText} = render(component)
let sort = getByText(/Sort ascending/i)
fireEvent.click(sort)
sort = getByText(/Sort descending/i)
fireEvent.click(sort)
expect(mutator.changeViewSortOptions).toHaveBeenCalledTimes(2)
let insert = getByText(/Insert left/i)
fireEvent.click(insert)
insert = getByText(/Insert right/i)
fireEvent.click(insert)
expect(mutator.insertPropertyTemplate).toHaveBeenCalledTimes(2)
const hide = getByText(/Hide/i)
fireEvent.click(hide)
expect(mutator.changeViewVisibleProperties).toHaveBeenCalled()
const duplicate = getByText(/Duplicate/i)
fireEvent.click(duplicate)
expect(mutator.duplicatePropertyTemplate).toHaveBeenCalled()
const del = getByText(/Delete/i)
fireEvent.click(del)
expect(mutator.deleteProperty).toHaveBeenCalled()
expect(container).toMatchSnapshot()
})
})
|