diff --git a/webapp/src/components/__snapshots__/addContentMenuItem.test.tsx.snap b/webapp/src/components/__snapshots__/addContentMenuItem.test.tsx.snap new file mode 100644 index 000000000..071958c71 --- /dev/null +++ b/webapp/src/components/__snapshots__/addContentMenuItem.test.tsx.snap @@ -0,0 +1,115 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`components/addContentMenuItem return a checkbox menu item 1`] = ` +
+ +`; + +exports[`components/addContentMenuItem return a divider menu item 1`] = ` +
+ +`; + +exports[`components/addContentMenuItem return a text menu item 1`] = ` +
+ +`; + +exports[`components/addContentMenuItem return an error and empty element from unknow type 1`] = `
`; + +exports[`components/addContentMenuItem return an image menu item 1`] = ` +
+ +`; diff --git a/webapp/src/components/addContentMenuItem.test.tsx b/webapp/src/components/addContentMenuItem.test.tsx new file mode 100644 index 000000000..61fbe5a81 --- /dev/null +++ b/webapp/src/components/addContentMenuItem.test.tsx @@ -0,0 +1,111 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import React, {ReactElement} from 'react' +import {render, screen, waitFor} from '@testing-library/react' + +import '@testing-library/jest-dom' +import {IntlProvider} from 'react-intl' + +import {mocked} from 'ts-jest/utils' + +import userEvent from '@testing-library/user-event' + +import mutator from '../mutator' + +import {TestBlockFactory} from '../test/testBlockFactory' + +import AddContentMenuItem from './addContentMenuItem' + +import './content/textElement' +import './content/imageElement' +import './content/dividerElement' +import './content/checkboxElement' + +const wrapIntl = (children: ReactElement) => ( + {children} +) +const board = TestBlockFactory.createBoard() +const card = TestBlockFactory.createCard(board) + +jest.mock('../mutator') +const mockedMutator = mocked(mutator, true) + +describe('components/addContentMenuItem', () => { + beforeEach(() => { + jest.clearAllMocks() + }) + test('return an image menu item', () => { + const {container} = render( + wrapIntl( + , + ), + ) + expect(container).toMatchSnapshot() + }) + + test('return a text menu item', async () => { + const {container} = render( + wrapIntl( + , + ), + ) + expect(container).toMatchSnapshot() + const buttonElement = screen.getByRole('button', {name: 'text'}) + userEvent.click(buttonElement) + await waitFor(() => expect(mockedMutator.performAsUndoGroup).toBeCalled()) + }) + + test('return a checkbox menu item', async () => { + const {container} = render( + wrapIntl( + , + ), + ) + expect(container).toMatchSnapshot() + const buttonElement = screen.getByRole('button', {name: 'checkbox'}) + userEvent.click(buttonElement) + await waitFor(() => expect(mockedMutator.performAsUndoGroup).toBeCalled()) + }) + + test('return a divider menu item', async () => { + const {container} = render( + wrapIntl( + , + ), + ) + expect(container).toMatchSnapshot() + const buttonElement = screen.getByRole('button', {name: 'divider'}) + userEvent.click(buttonElement) + await waitFor(() => expect(mockedMutator.performAsUndoGroup).toBeCalled()) + }) + + test('return an error and empty element from unknow type', () => { + const {container} = render( + wrapIntl( + , + ), + ) + expect(container).toMatchSnapshot() + }) +})