Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(i18n): always use formatted strings for extension popup #5761

Merged
merged 3 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lighthouse-extension/app/src/lighthouse-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const RawProtocol = require('../../../lighthouse-core/gather/connections/raw');
const Runner = require('../../../lighthouse-core/runner');
const Config = require('../../../lighthouse-core/config/config');
const defaultConfig = require('../../../lighthouse-core/config/default-config.js');
const i18n = require('../../../lighthouse-core/lib/i18n');
const log = require('lighthouse-logger');

/** @typedef {import('../../../lighthouse-core/gather/connections/connection.js')} Connection */
Expand Down Expand Up @@ -65,7 +66,9 @@ function runLighthouseInWorker(port, url, options, categoryIDs) {
* @return {Array<{title: string, id: string}>}
*/
function getDefaultCategories() {
return Config.getCategories(defaultConfig);
const categories = Config.getCategories(defaultConfig);
categories.forEach(cat => cat.title = i18n.getFormatted(cat.title, 'en-US'));
return categories;
}

/** @param {(status: [string, string, string]) => void} listenCallback */
Expand Down
32 changes: 31 additions & 1 deletion lighthouse-extension/test/popup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,28 @@ describe('Lighthouse chrome popup', function() {
selectedCategories: [],
useDevTools: false,
}),
getDefaultCategories: () => [],
getDefaultCategories: () => [
{
id: 'performance',
title: 'Performance',
},
{
id: 'pwa',
title: 'Progressive Web App',
},
{
id: 'accessibility',
title: 'Accessibility',
},
{
id: 'best-practices',
title: 'Best Practices',
},
{
id: 'seo',
title: 'SEO',
},
],
};

Object.defineProperty(chrome, 'tabs', {
Expand Down Expand Up @@ -92,4 +113,13 @@ describe('Lighthouse chrome popup', function() {
assert.equal(titleText, 'Lighthouse');
assert.equal(urlText, 'http://example.com');
});


// Kinda lame as the mocked data is already good.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess a unit test (which would still be trivial but at least testing something) would be that the categories passed back are what are in the labels and values of the check boxes? So maybe keep the array passed back by the mocked getDefaultCategories in a top level variable and loop over it here to verify that all the members are there?

(rather than checking for the lack of ICU messages, which doesn't seem possible since the mock doesn't supply any of them)

// A real test would verify the switch happens in the background page's getDefaultCategories
it('should not have any ICU message IDs in the DOM', async function() {
const bodyText = await page.evaluate(() => document.body.textContent);
const hasIcuMessageInstanceIds = bodyText.includes(' | ') && bodyText.includes(' # ');
assert.ok(!hasIcuMessageInstanceIds, 'icu message ids found');
});
});