-
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 tests for default messages extraction tool (#21036)
* Add tests for default messages extraction tool * Update tests * Switch from Jade to PugJS * Resolve some issues * Fix bugs and refactor tests * Refactor utils.js tests * Change error messages style
- Loading branch information
1 parent
7f2a643
commit d787b64
Showing
27 changed files
with
955 additions
and
29 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_1/test_file_1.jsx
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,25 @@ | ||
/* eslint-disable */ | ||
|
||
// Angular service | ||
i18n('plugin_1.id_1', { defaultMessage: 'Message 1' }); | ||
|
||
// @kbn/i18n | ||
i18n.translate('plugin_1.id_2', { | ||
defaultMessage: 'Message 2', | ||
context: 'Message context', | ||
}); | ||
|
||
// React component. FormattedMessage, Intl.formatMessage() | ||
class Component extends PureComponent { | ||
render() { | ||
return ( | ||
<div> | ||
<FormattedMessage | ||
id="plugin_1.id_3" | ||
defaultMessage="Message 3" | ||
/> | ||
{intl.formatMessage({ id: 'plugin_1.id_4', defaultMessage: 'Message 4' })} | ||
</div> | ||
); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_1/test_file_2.pug
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,10 @@ | ||
extends ./chrome.pug | ||
|
||
block content | ||
.kibanaWelcomeView | ||
.kibanaLoaderWrap | ||
.kibanaLoader | ||
.kibanaWelcomeLogoCircle | ||
.kibanaWelcomeLogo | ||
.kibanaWelcomeText | ||
| #{i18n('plugin_1.id_5', { defaultMessage: 'Message 5' })} |
10 changes: 10 additions & 0 deletions
10
src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_1/test_file_3.hbs
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,10 @@ | ||
(function next() { | ||
var failure = function () { | ||
failure = function () {}; | ||
|
||
var err = document.createElement('h1'); | ||
err.innerText = '{{i18n 'plugin_1.id_6' '{"defaultMessage": "Message 6"}'}}'; | ||
|
||
document.body.innerHTML = err.outerHTML; | ||
} | ||
}()); |
8 changes: 8 additions & 0 deletions
8
src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_1/test_file_4.html
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,8 @@ | ||
<kbn-top-nav name="dashboard" config="topNavMenu"> | ||
<div data-transclude-slots> | ||
<div | ||
i18n-id="plugin_1.id_7" | ||
i18n-default-message="Message 7" | ||
></div> | ||
</div> | ||
</kbn-top-nav> |
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_3/test_file.jsx
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,8 @@ | ||
/* eslint-disable */ | ||
|
||
i18n('plugin_3.duplicate_id', { defaultMessage: 'Message 1' }); | ||
|
||
i18n.translate('plugin_3.duplicate_id', { | ||
defaultMessage: 'Message 2', | ||
context: 'Message context', | ||
}); |
31 changes: 31 additions & 0 deletions
31
src/dev/i18n/__snapshots__/extract_code_messages.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,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`extractCodeMessages extracts React, server-side and angular service default messages 1`] = ` | ||
Array [ | ||
Array [ | ||
"kbn.mgmt.id-1", | ||
Object { | ||
"context": undefined, | ||
"message": "Message text 1", | ||
}, | ||
], | ||
Array [ | ||
"kbn.mgmt.id-2", | ||
Object { | ||
"context": "Message context", | ||
"message": "Message text 2", | ||
}, | ||
], | ||
Array [ | ||
"kbn.mgmt.id-3", | ||
Object { | ||
"context": undefined, | ||
"message": "Message text 3", | ||
}, | ||
], | ||
] | ||
`; | ||
|
||
exports[`extractCodeMessages throws on empty id 1`] = `"Empty \\"id\\" value in i18n() or i18n.translate() is not allowed."`; | ||
|
||
exports[`extractCodeMessages throws on missing defaultMessage 1`] = `"Empty defaultMessage in intl.formatMessage() is not allowed (\\"message-id\\")."`; |
69 changes: 69 additions & 0 deletions
69
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
21 changes: 21 additions & 0 deletions
21
src/dev/i18n/__snapshots__/extract_handlebars_messages.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,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`dev/i18n/extract_handlebars_messages extracts handlebars default messages 1`] = ` | ||
Array [ | ||
Array [ | ||
"ui.id-1", | ||
Object { | ||
"context": "Message context", | ||
"message": "Message text", | ||
}, | ||
], | ||
] | ||
`; | ||
|
||
exports[`dev/i18n/extract_handlebars_messages throws on empty id 1`] = `"Empty id argument in Handlebars i18n is not allowed."`; | ||
|
||
exports[`dev/i18n/extract_handlebars_messages throws on missing defaultMessage property 1`] = `"Empty defaultMessage in Handlebars i18n is not allowed (\\"message-id\\")."`; | ||
|
||
exports[`dev/i18n/extract_handlebars_messages throws on wrong number of arguments 1`] = `"Wrong number of arguments for handlebars i18n call."`; | ||
|
||
exports[`dev/i18n/extract_handlebars_messages throws on wrong properties argument type 1`] = `"Properties string in Handlebars i18n should be a string literal (\\"ui.id-1\\")."`; |
31 changes: 31 additions & 0 deletions
31
src/dev/i18n/__snapshots__/extract_html_messages.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,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`dev/i18n/extract_html_messages extracts default messages from HTML 1`] = ` | ||
Array [ | ||
Array [ | ||
"kbn.dashboard.id-1", | ||
Object { | ||
"context": "Message context 1", | ||
"message": "Message text 1", | ||
}, | ||
], | ||
Array [ | ||
"kbn.dashboard.id-2", | ||
Object { | ||
"context": undefined, | ||
"message": "Message text 2", | ||
}, | ||
], | ||
Array [ | ||
"kbn.dashboard.id-3", | ||
Object { | ||
"context": "Message context 3", | ||
"message": "Message text 3", | ||
}, | ||
], | ||
] | ||
`; | ||
|
||
exports[`dev/i18n/extract_html_messages throws on empty i18n-id 1`] = `"Empty \\"i18n-id\\" value in angular directive is not allowed."`; | ||
|
||
exports[`dev/i18n/extract_html_messages throws on missing i18n-default-message attribute 1`] = `"Empty defaultMessage in angular directive is not allowed (\\"message-id\\")."`; |
29 changes: 29 additions & 0 deletions
29
src/dev/i18n/__snapshots__/extract_i18n_call_messages.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,29 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`extractI18nCallMessages extracts "i18n" and "i18n.translate" functions call message 1`] = ` | ||
Array [ | ||
"message-id-1", | ||
Object { | ||
"context": "Message context 1", | ||
"message": "Default message 1", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`extractI18nCallMessages extracts "i18n" and "i18n.translate" functions call message 2`] = ` | ||
Array [ | ||
"message-id-2", | ||
Object { | ||
"context": "Message context 2", | ||
"message": "Default message 2", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`extractI18nCallMessages throws if defaultMessage is not a string literal 1`] = `"defaultMessage value in i18n() or i18n.translate() should be a string literal (\\"message-id\\")."`; | ||
|
||
exports[`extractI18nCallMessages throws if message id value is not a string literal 1`] = `"Message id in i18n() or i18n.translate() should be a string literal."`; | ||
|
||
exports[`extractI18nCallMessages throws if properties object is not provided 1`] = `"Empty defaultMessage in i18n() or i18n.translate() is not allowed (\\"message-id\\")."`; | ||
|
||
exports[`extractI18nCallMessages throws on empty defaultMessage 1`] = `"Empty defaultMessage in i18n() or i18n.translate() is not allowed (\\"message-id\\")."`; |
15 changes: 15 additions & 0 deletions
15
src/dev/i18n/__snapshots__/extract_pug_messages.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,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`extractPugMessages extracts messages from pug template 1`] = ` | ||
Array [ | ||
"message-id", | ||
Object { | ||
"context": "Message context", | ||
"message": "Default message", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`extractPugMessages throws on empty id 1`] = `"Empty \\"id\\" value in i18n() or i18n.translate() is not allowed."`; | ||
|
||
exports[`extractPugMessages throws on missing default message 1`] = `"Empty defaultMessage in i18n() or i18n.translate() is not allowed (\\"message-id\\")."`; |
27 changes: 27 additions & 0 deletions
27
src/dev/i18n/__snapshots__/extract_react_messages.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,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`dev/i18n/extract_react_messages extractFormattedMessages extracts messages from "<FormattedMessage>" element 1`] = ` | ||
Array [ | ||
"message-id-2", | ||
Object { | ||
"context": "Message context 2", | ||
"message": "Default message 2", | ||
}, | ||
] | ||
`; | ||
exports[`dev/i18n/extract_react_messages extractIntlMessages extracts messages from "intl.formatMessage" function call 1`] = ` | ||
Array [ | ||
"message-id-1", | ||
Object { | ||
"context": "Message context 1", | ||
"message": "Default message 1", | ||
}, | ||
] | ||
`; | ||
exports[`dev/i18n/extract_react_messages extractIntlMessages throws if context value is not a string literal 1`] = `"context value should be a string literal (\\"message-id\\")."`; | ||
exports[`dev/i18n/extract_react_messages extractIntlMessages throws if defaultMessage value is not a string literal 1`] = `"defaultMessage value should be a string literal (\\"message-id\\")."`; | ||
exports[`dev/i18n/extract_react_messages extractIntlMessages throws if message id is not a string literal 1`] = `"Message id should be a string literal."`; |
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
Oops, something went wrong.