-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #837 from CruGlobal/white-flash
[no-Jira] Fix blank page on initial load
- Loading branch information
Showing
4 changed files
with
61 additions
and
13 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/components/User/Preferences/UserPreferenceProvider.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters