main

mattermost/focalboard

Last updated at: 29/12/2023 09:48

kanbanHiddenColumnItem.test.tsx

TLDR

This file is a test file for the KanbanHiddenColumnItem component in the Kanban component of the Demo Projects project. It contains tests for rendering snapshots and checking certain functionalities of the component.

Methods

There are no methods in this file.

Classes

There is no class in this file.

// 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 'jest-mock'

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 card2 = 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.boardId, activeView, option.id)
    })

    test('limited card check', () => {
        card.limited = true
        card2.limited = true
        option.id = 'hidden-card-group-id'
        const {container, getByTitle} = render(wrapDNDIntl(
            <KanbanHiddenColumnItem
                activeView={activeView}
                group={{
                    option,
                    cards: [card, card2],
                }}
                readonly={false}
                onDrop={jest.fn()}
                intl={intl}
            />,
        ))
        expect(getByTitle('hidden-card-count')).toHaveTextContent('2')
        expect(container).toMatchSnapshot()
    })
})