-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add real provider for i18nProvider mock (#181025)
## Summary Fix #180725
- Loading branch information
1 parent
7623720
commit 5f0b9f7
Showing
6 changed files
with
2,488 additions
and
640 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
packages/core/i18n/core-i18n-browser-mocks/src/i18n_context_mock.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,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { I18nProviderMock } from './i18n_context_mock'; | ||
import { shallow } from 'enzyme'; | ||
|
||
describe('I18nProviderMock', () => { | ||
it('interpolates to default message if present', () => { | ||
expect( | ||
shallow( | ||
<I18nProviderMock> | ||
<FormattedMessage id="id" defaultMessage="default message" /> | ||
</I18nProviderMock> | ||
).html() | ||
).toMatchInlineSnapshot(`"default message"`); | ||
}); | ||
|
||
it('interpolates to id if default message is not present', () => { | ||
expect( | ||
shallow( | ||
<I18nProviderMock> | ||
<FormattedMessage id="id" /> | ||
</I18nProviderMock> | ||
).html() | ||
).toMatchInlineSnapshot(`"id"`); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/core/i18n/core-i18n-browser-mocks/src/i18n_context_mock.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,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
// eslint-disable-next-line @kbn/eslint/module_migration | ||
import { IntlProvider } from 'react-intl'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
const emptyMessages = {}; | ||
|
||
export const I18nProviderMock: React.FC = ({ children }) => { | ||
return ( | ||
<IntlProvider | ||
locale={i18n.getLocale()} | ||
messages={emptyMessages} | ||
defaultLocale={i18n.getLocale()} | ||
formats={i18n.getFormats()} | ||
textComponent={React.Fragment} | ||
> | ||
{children} | ||
</IntlProvider> | ||
); | ||
}; |
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
258 changes: 214 additions & 44 deletions
258
...lays/core-overlays-browser-internal/src/flyout/__snapshots__/flyout_service.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.