Skip to content

Commit

Permalink
add wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
MonPote committed Dec 18, 2023
1 parent f8ac4ed commit 0ec1e54
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { QueryClient, QueryClientProvider } from 'react-query';
import { getWrapper } from '../../testUtils';
describe('HealthSelector', () => {
it('should display correctly without any props and select first option', () => {
const { Wrapper } = getWrapper();
const { getByText } = render(
<QueryClientProvider client={new QueryClient()}>
<Wrapper>
<HealthSelector id="health" onChange={() => {}} />
</QueryClientProvider>,
</Wrapper>,
);
const input = screen.getByRole('textbox');

Expand All @@ -21,11 +23,12 @@ describe('HealthSelector', () => {
expect(healthyOption).toBeInTheDocument();
});
it('should call the onChange function when it change', () => {
const { Wrapper } = getWrapper();
const onChange = jest.fn();
const { getByText } = render(
<QueryClientProvider client={new QueryClient()}>
<Wrapper>
<HealthSelector id="health" onChange={onChange} />
</QueryClientProvider>,
</Wrapper>,
);
const input = screen.getByRole('textbox');
userEvent.click(input);
Expand All @@ -34,8 +37,9 @@ describe('HealthSelector', () => {
expect(onChange).toHaveBeenCalledWith('warning');
});
it('should not display hidden options', () => {
const { Wrapper } = getWrapper();
const { queryByText } = render(
<QueryClientProvider client={new QueryClient()}>
<Wrapper>
<HealthSelector
id="health"
onChange={() => {}}
Expand All @@ -46,7 +50,7 @@ describe('HealthSelector', () => {
optionsDefaultConfiguration.unknown,
]}
/>
</QueryClientProvider>,
</Wrapper>,
);

// open the menu
Expand Down
18 changes: 18 additions & 0 deletions src/lib/testUtils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { QueryClient, QueryClientProvider } from 'react-query';
import { ThemeProvider } from 'styled-components';
import { coreUIAvailableThemes } from './style/theme';

export const getWrapper = () => {
const queryClient = new QueryClient();
const Wrapper = ({ children }: { children: React.ReactNode }) => {
return (
<ThemeProvider theme={coreUIAvailableThemes.darkRebrand}>
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
</ThemeProvider>
);
};

return { Wrapper: Wrapper, queryClient: queryClient };
};

0 comments on commit 0ec1e54

Please sign in to comment.