Files
pybricks-code/src/about/AboutDialog.test.tsx
T
David Lechner de7e046d31 avoid lambda props
This fixes the simple cases of callback props using lambda functions.
This will prevent rerendering in some cases since a new callback
function is not created on each call.
2022-03-12 15:19:50 -06:00

50 lines
1.4 KiB
TypeScript

// SPDX-License-Identifier: MIT
// Copyright (c) 2021-2022 The Pybricks Authors
import { getByLabelText, waitForElementToBeRemoved } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { testRender } from '../../test';
import AboutDialog from './AboutDialog';
it('should close when the button is clicked', () => {
const close = jest.fn();
const [dialog] = testRender(<AboutDialog isOpen={true} onClose={close} />);
userEvent.click(dialog.getByLabelText('Close'));
expect(close).toHaveBeenCalled();
});
it('should manage license dialog open/close', async () => {
const [dialog] = testRender(
<AboutDialog isOpen={true} onClose={() => undefined} />,
);
userEvent.click(dialog.getByText('Software Licenses'));
expect(
dialog.getByText(
`${process.env.REACT_APP_NAME} is built on open source software.`,
{
exact: false,
},
),
).toBeInTheDocument();
const licenseDialog = document.querySelector(
'.pb-license-dialog',
) as HTMLDivElement;
userEvent.click(getByLabelText(licenseDialog, 'Close'));
await waitForElementToBeRemoved(() =>
dialog.queryByText(
`${process.env.REACT_APP_NAME} is built on open source software.`,
{
exact: false,
},
),
);
});