Skip to content

Commit

Permalink
Add basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Dec 7, 2023
1 parent 9e346fb commit f830a9c
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/components/User/Preferences/UserPreferenceProvider.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { render } from '@testing-library/react';
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
import { useLocale } from 'src/hooks/useLocale';
import { GetUserQuery } from '../GetUser.generated';
import { UserPreferenceProvider } from './UserPreferenceProvider';

const Consumer: React.FC = () => {
const locale = useLocale();

return <p>Locale: {locale}</p>;
};

describe('UserPreferenceProvider', () => {
it('always renders children', () => {
const { getByText } = render(
<GqlMockedProvider>
<UserPreferenceProvider>Children</UserPreferenceProvider>
</GqlMockedProvider>,
);

expect(getByText('Children')).toBeInTheDocument();
});

it('provides locale', async () => {
const { getByText, findByText } = render(
<GqlMockedProvider<{ GetUser: GetUserQuery }>
mocks={{
GetUser: {
user: {
preferences: {
localeDisplay: 'es',
},
},
},
}}
>
<UserPreferenceProvider>
<Consumer />
</UserPreferenceProvider>
</GqlMockedProvider>,
);

// Initial default locale
expect(getByText('Locale: en-US')).toBeInTheDocument();

// Locale loaded from query
expect(await findByText('Locale: es')).toBeInTheDocument();
});
});

0 comments on commit f830a9c

Please sign in to comment.