diff --git a/webapp/src/components/Dialog/Dialog.test.tsx b/webapp/src/components/Dialog/Dialog.test.tsx new file mode 100644 index 000000000..392eff3ea --- /dev/null +++ b/webapp/src/components/Dialog/Dialog.test.tsx @@ -0,0 +1,33 @@ +import React from 'react'; + +import {render, RenderResult} from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; + +import {Dialog} from './Dialog.component'; + +const onCloseHandler = jest.fn(); +const onSubmitHandler = jest.fn(); + +const dialogProps = { + onCloseHandler, + onSubmitHandler, +}; + +let tree: RenderResult; + +describe('Dialog component', () => { + beforeEach(() => { + tree = render(); + }); + + it('Should render correctly', () => { + expect(tree).toMatchSnapshot(); + }); + + it('Should close the dialog on clicking close button', () => { + expect(tree.getAllByRole('button').length).toEqual(2); + + userEvent.click(tree.getAllByRole('button')[1]); + expect(onCloseHandler).toHaveBeenCalledTimes(1); + }); +}); diff --git a/webapp/src/components/Dialog/__snapshots__/Dialog.test.tsx.snap b/webapp/src/components/Dialog/__snapshots__/Dialog.test.tsx.snap new file mode 100644 index 000000000..243386d60 --- /dev/null +++ b/webapp/src/components/Dialog/__snapshots__/Dialog.test.tsx.snap @@ -0,0 +1,140 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Dialog component Should render correctly 1`] = ` +{ + "asFragment": [Function], + "baseElement": +