Skip to content

Commit

Permalink
fix(i18n): combine i18n integration and unit test
Browse files Browse the repository at this point in the history
* combined i18n tests to allow for easier snapshot updates
  • Loading branch information
cdcabrera committed Oct 8, 2019
1 parent 8773880 commit 26b3bcc
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 115 deletions.
72 changes: 72 additions & 0 deletions src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,78 @@ Object {
}
`;

exports[`I18n Component should generate a predictable pot output snapshot: pot output 1`] = `
"msgid \\"\\"
msgstr \\"\\"
\\"Content-Type: text/plain; charset=UTF-8\\\\n\\"
#: src/components/rhelGraphCard/rhelGraphCard.js:80
msgid \\"curiosity-graph.legendSocketsLabel\\"
msgstr \\"\\"
#: src/components/rhelGraphCard/rhelGraphCard.js:87
msgid \\"curiosity-graph.legendSocketsThresholdLabel\\"
msgstr \\"\\"
#: src/common/graphHelpers.js:62
msgid \\"curiosity-graph.tooltipPreviousLabelDaily\\"
msgstr \\"\\"
#: src/common/graphHelpers.js:55
msgid \\"curiosity-graph.tooltipPreviousLabelMonthly\\"
msgstr \\"\\"
#: src/common/graphHelpers.js:58
msgid \\"curiosity-graph.tooltipPreviousLabelQuarterly\\"
msgstr \\"\\"
#: src/common/graphHelpers.js:52
msgid \\"curiosity-graph.tooltipPreviousLabelWeekly\\"
msgstr \\"\\"
#: src/components/rhelGraphCard/rhelGraphCard.js:61
msgid \\"curiosity-graph.tooltipSockets\\"
msgstr \\"\\"
#: src/components/rhelGraphCard/rhelGraphCard.js:62
msgid \\"curiosity-graph.tooltipSocketsThreshold\\"
msgstr \\"\\"
#: src/components/rhelGraphCard/rhelGraphCard.js:102
msgctxt \\"CPU socket usage\\"
msgid \\"curiosity-graph.heading\\"
msgstr \\"\\"
#: src/components/rhelGraphCard/rhelGraphCardTypes.js:7
msgctxt \\"Daily\\"
msgid \\"curiosity-graph.dropdownDaily\\"
msgstr \\"\\"
#: src/components/rhelGraphCard/rhelGraphCardTypes.js:9
msgctxt \\"Monthly\\"
msgid \\"curiosity-graph.dropdownMonthly\\"
msgstr \\"\\"
#: src/components/rhelGraphCard/rhelGraphCardTypes.js:10
msgctxt \\"Quarterly\\"
msgid \\"curiosity-graph.dropdownQuarterly\\"
msgstr \\"\\"
#: src/components/rhelGraphCard/rhelGraphCard.js:105
#: src/components/rhelGraphCard/rhelGraphCard.js:109
msgctxt \\"Select date range\\"
msgid \\"curiosity-graph.dropdownPlaceholder\\"
msgstr \\"\\"
#: src/components/rhelGraphCard/rhelGraphCardTypes.js:8
msgctxt \\"Weekly\\"
msgid \\"curiosity-graph.dropdownWeekly\\"
msgstr \\"\\"
"
`;

exports[`I18n Component should have locale keys that exist in the default language JSON: missing locale keys 1`] = `Array []`;

exports[`I18n Component should pass children: children 1`] = `"lorem ipsum"`;

exports[`I18n Component should render a basic component: basic 1`] = `
Expand Down
40 changes: 40 additions & 0 deletions src/components/i18n/__tests__/i18n.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import React from 'react';
import { mount, shallow } from 'enzyme';
import _get from 'lodash/get';
import { GettextExtractor, JsExtractors } from 'gettext-extractor';
import { I18n, translate } from '../i18n';
import enLocales from '../../../../public/locales/en-US';

const textExtractor = () => {
const extractor = new GettextExtractor();
extractor
.createJsParser([
JsExtractors.callExpression(['t', '[this].t', 'translate'], {
arguments: {
text: 0,
context: 1
}
})
])
.parseFilesGlob('./src/**/!(*.test|*.spec).@(js|jsx)');

return extractor;
};

describe('I18n Component', () => {
const getText = textExtractor();

it('should render a basic component', () => {
const props = {
locale: 'es'
Expand Down Expand Up @@ -36,4 +57,23 @@ describe('I18n Component', () => {
placeholder
}).toMatchSnapshot('translate');
});

it('should generate a predictable pot output snapshot', () => {
expect(getText.getPotString()).toMatchSnapshot('pot output');
});

it('should have locale keys that exist in the default language JSON', () => {
const messages = (getText.getMessages && getText.getMessages()) || [];
const missingKeys = [];

messages.forEach(value => {
const keyCheck = (value && value.text) || '';

if (keyCheck && !_get(enLocales, keyCheck, null)) {
missingKeys.push(keyCheck);
}
});

expect(missingKeys).toMatchSnapshot('missing locale keys');
});
});
73 changes: 0 additions & 73 deletions tests/__snapshots__/i18n.test.js.snap

This file was deleted.

42 changes: 0 additions & 42 deletions tests/i18n.test.js

This file was deleted.

0 comments on commit 26b3bcc

Please sign in to comment.