From 0c07eccbd1ffc2c38e1049e3cd660e82eb13e7e4 Mon Sep 17 00:00:00 2001 From: JohnMark Sill Date: Fri, 18 Feb 2022 20:20:45 -0600 Subject: [PATCH] fix: added a test for the prompt and refactored the dialog test --- web/src/components/__tests__/Dialog.test.jsx | 19 ++-------- web/src/components/__tests__/Prompt.test.jsx | 38 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 web/src/components/__tests__/Prompt.test.jsx diff --git a/web/src/components/__tests__/Dialog.test.jsx b/web/src/components/__tests__/Dialog.test.jsx index 646f5a46d..7b303163a 100644 --- a/web/src/components/__tests__/Dialog.test.jsx +++ b/web/src/components/__tests__/Dialog.test.jsx @@ -16,23 +16,8 @@ describe('Dialog', () => { }); test('renders to a portal', async () => { - render(); - expect(screen.getByText('Tacos')).toBeInTheDocument(); + render(Sample); + expect(screen.getByText('Sample')).toBeInTheDocument(); expect(screen.getByRole('modal').closest('#dialogs')).not.toBeNull(); }); - - test('renders action buttons', async () => { - const handleClick = jest.fn(); - render( - - ); - fireEvent.click(screen.getByRole('button', { name: 'Okay' })); - expect(handleClick).toHaveBeenCalled(); - }); }); diff --git a/web/src/components/__tests__/Prompt.test.jsx b/web/src/components/__tests__/Prompt.test.jsx new file mode 100644 index 000000000..ae9f2503e --- /dev/null +++ b/web/src/components/__tests__/Prompt.test.jsx @@ -0,0 +1,38 @@ +import { h } from 'preact'; +import Prompt from '../Prompt'; +import { fireEvent, render, screen } from '@testing-library/preact'; + +describe('Prompt', () => { + let portal; + + beforeAll(() => { + portal = document.createElement('div'); + portal.id = 'dialogs'; + document.body.appendChild(portal); + }); + + afterAll(() => { + document.body.removeChild(portal); + }); + + test('renders to a portal', async () => { + render(); + expect(screen.getByText('Tacos')).toBeInTheDocument(); + expect(screen.getByRole('modal').closest('#dialogs')).not.toBeNull(); + }); + + test('renders action buttons', async () => { + const handleClick = jest.fn(); + render( + + ); + fireEvent.click(screen.getByRole('button', { name: 'Okay' })); + expect(handleClick).toHaveBeenCalled(); + }); +});