From 26b3bcc4cbae09479fd863d1477c5d1b578128f8 Mon Sep 17 00:00:00 2001 From: CD Cabrera Date: Tue, 8 Oct 2019 17:44:22 -0400 Subject: [PATCH] fix(i18n): combine i18n integration and unit test * combined i18n tests to allow for easier snapshot updates --- .../__tests__/__snapshots__/i18n.test.js.snap | 72 ++++++++++++++++++ src/components/i18n/__tests__/i18n.test.js | 40 ++++++++++ tests/__snapshots__/i18n.test.js.snap | 73 ------------------- tests/i18n.test.js | 42 ----------- 4 files changed, 112 insertions(+), 115 deletions(-) delete mode 100644 tests/__snapshots__/i18n.test.js.snap delete mode 100644 tests/i18n.test.js diff --git a/src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap b/src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap index 91752bfd8..c4c78ac70 100644 --- a/src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap +++ b/src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap @@ -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`] = ` diff --git a/src/components/i18n/__tests__/i18n.test.js b/src/components/i18n/__tests__/i18n.test.js index d75c91c97..7c9b9dd3d 100644 --- a/src/components/i18n/__tests__/i18n.test.js +++ b/src/components/i18n/__tests__/i18n.test.js @@ -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' @@ -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'); + }); }); diff --git a/tests/__snapshots__/i18n.test.js.snap b/tests/__snapshots__/i18n.test.js.snap deleted file mode 100644 index adec2333a..000000000 --- a/tests/__snapshots__/i18n.test.js.snap +++ /dev/null @@ -1,73 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`i18n locale 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 locale should have locale keys that exist in the default language JSON: missing locale keys 1`] = `Array []`; diff --git a/tests/i18n.test.js b/tests/i18n.test.js deleted file mode 100644 index 7beec4a52..000000000 --- a/tests/i18n.test.js +++ /dev/null @@ -1,42 +0,0 @@ -const get = require('lodash/get'); -const { GettextExtractor, JsExtractors } = require('gettext-extractor'); -const enLocales = require('../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 locale', () => { - const getText = textExtractor(); - - 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'); - }); -});