diff --git a/webapp/src/components/__snapshots__/dialog.test.tsx.snap b/webapp/src/components/__snapshots__/dialog.test.tsx.snap new file mode 100644 index 000000000..39f14b927 --- /dev/null +++ b/webapp/src/components/__snapshots__/dialog.test.tsx.snap @@ -0,0 +1,83 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`components/dialog should match snapshot 1`] = ` +
+
+
+
+
+ +
+
+
+
+
+
+`; + +exports[`components/dialog should return dialog and click on cancel button 1`] = ` +
+
+
+
+
+ + +
+
+
+
+
+
+`; diff --git a/webapp/src/components/dialog.test.tsx b/webapp/src/components/dialog.test.tsx new file mode 100644 index 000000000..264bf1572 --- /dev/null +++ b/webapp/src/components/dialog.test.tsx @@ -0,0 +1,116 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import '@testing-library/jest-dom' +import {render, screen} from '@testing-library/react' + +import React from 'react' + +import userEvent from '@testing-library/user-event' + +import {wrapDNDIntl} from '../testUtils' + +import Menu from '../widgets/menu' + +import OptionsIcon from '../widgets/icons/options' + +import Dialog from './dialog' + +describe('components/dialog', () => { + beforeEach(jest.clearAllMocks) + test('should match snapshot', () => { + const {container} = render(wrapDNDIntl( + +
+
, + )) + expect(container).toMatchSnapshot() + }) + test('should return dialog and click onClose button', () => { + const onCloseMethod = jest.fn() + render(wrapDNDIntl( + +
+
, + )) + const buttonClose = screen.getByRole('button', {name: 'Close dialog'}) + userEvent.click(buttonClose) + expect(onCloseMethod).toBeCalledTimes(1) + }) + test('should return dialog and click to close on wrapper', () => { + const onCloseMethod = jest.fn() + const {container} = render(wrapDNDIntl( + + + } + name='Test' + onClick={async () => { + jest.fn() + }} + /> + + , + )) + const buttonClose = container.querySelector('.wrapper')! + userEvent.click(buttonClose) + expect(onCloseMethod).toBeCalledTimes(1) + }) + + test('should return dialog and click on test button', () => { + const onTest = jest.fn() + render(wrapDNDIntl( + + } + name='Test' + onClick={async () => { + onTest() + }} + /> + } + > +
+
, + )) + const buttonMenu = screen.getByRole('button', {name: 'menuwrapper'}) + userEvent.click(buttonMenu) + const buttonTest = screen.getByRole('button', {name: 'Test'}) + userEvent.click(buttonTest) + expect(onTest).toBeCalledTimes(1) + }) + test('should return dialog and click on cancel button', () => { + const {container} = render(wrapDNDIntl( + + } + name='Test' + onClick={async () => { + jest.fn() + }} + /> + } + > +
+
, + )) + const buttonMenu = screen.getByRole('button', {name: 'menuwrapper'}) + userEvent.click(buttonMenu) + const buttonTest = screen.getByRole('button', {name: 'Cancel'}) + userEvent.click(buttonTest) + expect(container).toMatchSnapshot() + }) +})