-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* chore[GH-#830]: Add unit tests for dialog * fix: snapshot Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`components/dialog should match snapshot 1`] = ` | ||
<div> | ||
<div | ||
class="Dialog dialog-back undefined" | ||
> | ||
<div | ||
class="wrapper" | ||
> | ||
<div | ||
class="dialog" | ||
> | ||
<div | ||
class="toolbar" | ||
> | ||
<button | ||
aria-label="Close dialog" | ||
class="Button IconButton IconButton--large" | ||
title="Close dialog" | ||
type="button" | ||
> | ||
<i | ||
class="CompassIcon icon-close CloseIcon" | ||
/> | ||
</button> | ||
</div> | ||
<div | ||
id="test" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`components/dialog should return dialog and click on cancel button 1`] = ` | ||
<div> | ||
<div | ||
class="Dialog dialog-back undefined" | ||
> | ||
<div | ||
class="wrapper" | ||
> | ||
<div | ||
class="dialog" | ||
> | ||
<div | ||
class="toolbar" | ||
> | ||
<button | ||
aria-label="Close dialog" | ||
class="Button IconButton IconButton--large" | ||
title="Close dialog" | ||
type="button" | ||
> | ||
<i | ||
class="CompassIcon icon-close CloseIcon" | ||
/> | ||
</button> | ||
<div | ||
aria-label="menuwrapper" | ||
class="MenuWrapper" | ||
role="button" | ||
> | ||
<button | ||
class="Button IconButton IconButton--large" | ||
type="button" | ||
> | ||
<i | ||
class="CompassIcon icon-dots-horizontal OptionsIcon" | ||
/> | ||
</button> | ||
</div> | ||
</div> | ||
<div | ||
id="test" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( | ||
<Dialog | ||
onClose={jest.fn()} | ||
> | ||
<div id='test'/> | ||
</Dialog>, | ||
)) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
test('should return dialog and click onClose button', () => { | ||
const onCloseMethod = jest.fn() | ||
render(wrapDNDIntl( | ||
<Dialog | ||
onClose={onCloseMethod} | ||
> | ||
<div id='test'/> | ||
</Dialog>, | ||
)) | ||
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( | ||
<Dialog | ||
onClose={onCloseMethod} | ||
> | ||
<Menu position='left'> | ||
<Menu.Text | ||
id='test' | ||
icon={<OptionsIcon/>} | ||
name='Test' | ||
onClick={async () => { | ||
jest.fn() | ||
}} | ||
/> | ||
</Menu> | ||
</Dialog>, | ||
)) | ||
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( | ||
<Dialog | ||
onClose={jest.fn()} | ||
toolsMenu={<Menu position='left'> | ||
<Menu.Text | ||
id='test' | ||
icon={<OptionsIcon/>} | ||
name='Test' | ||
onClick={async () => { | ||
onTest() | ||
}} | ||
/> | ||
</Menu>} | ||
> | ||
<div id='test'/> | ||
</Dialog>, | ||
)) | ||
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( | ||
<Dialog | ||
onClose={jest.fn()} | ||
toolsMenu={<Menu position='left'> | ||
<Menu.Text | ||
id='test' | ||
icon={<OptionsIcon/>} | ||
name='Test' | ||
onClick={async () => { | ||
jest.fn() | ||
}} | ||
/> | ||
</Menu>} | ||
> | ||
<div id='test'/> | ||
</Dialog>, | ||
)) | ||
const buttonMenu = screen.getByRole('button', {name: 'menuwrapper'}) | ||
userEvent.click(buttonMenu) | ||
const buttonTest = screen.getByRole('button', {name: 'Cancel'}) | ||
userEvent.click(buttonTest) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
}) |