-
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.
Browse files
Browse the repository at this point in the history
* Fix i18n default formats injection into en.json * Use snapshots for tests
- Loading branch information
1 parent
edc48a6
commit ff39ac1
Showing
4 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
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 @@ | ||
<p>{{ 'test-plugin.message-id' | i18n: { defaultMessage: 'Message text' } }}</p> |
64 changes: 64 additions & 0 deletions
64
src/dev/i18n/__snapshots__/extract_default_translations.test.js.snap
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,64 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`dev/i18n/extract_default_translations injects default formats into en.json 1`] = ` | ||
"{ | ||
formats: { | ||
number: { | ||
currency: { | ||
style: 'currency', | ||
}, | ||
percent: { | ||
style: 'percent', | ||
}, | ||
}, | ||
date: { | ||
short: { | ||
month: 'numeric', | ||
day: 'numeric', | ||
year: '2-digit', | ||
}, | ||
medium: { | ||
month: 'short', | ||
day: 'numeric', | ||
year: 'numeric', | ||
}, | ||
long: { | ||
month: 'long', | ||
day: 'numeric', | ||
year: 'numeric', | ||
}, | ||
full: { | ||
weekday: 'long', | ||
month: 'long', | ||
day: 'numeric', | ||
year: 'numeric', | ||
}, | ||
}, | ||
time: { | ||
short: { | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
}, | ||
medium: { | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
second: 'numeric', | ||
}, | ||
long: { | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
second: 'numeric', | ||
timeZoneName: 'short', | ||
}, | ||
full: { | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
second: 'numeric', | ||
timeZoneName: 'short', | ||
}, | ||
}, | ||
}, | ||
'test-plugin.message-id': 'Message text', | ||
} | ||
" | ||
`; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { resolve } from 'path'; | ||
import fs from 'fs'; | ||
import { promisify } from 'util'; | ||
|
||
import { extractDefaultTranslations } from './extract_default_translations'; | ||
|
||
const readFileAsync = promisify(fs.readFile); | ||
const removeDirAsync = promisify(fs.rmdir); | ||
const unlinkAsync = promisify(fs.unlink); | ||
|
||
const PLUGIN_PATH = resolve(__dirname, '__fixtures__', 'test_plugin'); | ||
|
||
describe('dev/i18n/extract_default_translations', () => { | ||
it('injects default formats into en.json', async () => { | ||
await extractDefaultTranslations(PLUGIN_PATH); | ||
|
||
const extractedJSONBuffer = await readFileAsync( | ||
resolve(PLUGIN_PATH, 'translations', 'en.json') | ||
); | ||
|
||
await unlinkAsync(resolve(PLUGIN_PATH, 'translations', 'en.json')); | ||
await removeDirAsync(resolve(PLUGIN_PATH, 'translations')); | ||
|
||
expect(extractedJSONBuffer.toString()).toMatchSnapshot(); | ||
}); | ||
}); |