Skip to content

Commit

Permalink
core(i18n): always use formatted strings for extension popup (#5761)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish authored and brendankenny committed Aug 2, 2018
1 parent 7fa8ada commit 1fb885b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
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: 29 additions & 3 deletions lighthouse-extension/test/popup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ const puppeteer = require('../../node_modules/puppeteer/index.js');

const lighthouseExtensionPath = path.resolve(__dirname, '../dist');

const defaultCategoriesStub = [
{
id: 'performance',
title: 'Performance',
},
{
id: 'pwa',
title: 'Progressive Web App',
},
{
id: 'seo',
title: 'SEO',
},
];

describe('Lighthouse chrome popup', function() {
// eslint-disable-next-line no-console
console.log('\n✨ Be sure to have recently run this: yarn build-extension');
Expand All @@ -32,15 +47,15 @@ describe('Lighthouse chrome popup', function() {
});

page = await browser.newPage();
await page.evaluateOnNewDocument(() => {
await page.evaluateOnNewDocument((defaultCategoriesStub) => {
const backgroundMock = {
isRunning: () => false,
listenForStatus: () => {},
loadSettings: () => Promise.resolve({
selectedCategories: [],
useDevTools: false,
}),
getDefaultCategories: () => [],
getDefaultCategories: () => defaultCategoriesStub,
};

Object.defineProperty(chrome, 'tabs', {
Expand All @@ -59,7 +74,7 @@ describe('Lighthouse chrome popup', function() {
},
}),
});
});
}, defaultCategoriesStub);

page.on('pageerror', err => {
pageErrors.push(err);
Expand Down Expand Up @@ -92,4 +107,15 @@ describe('Lighthouse chrome popup', function() {
assert.equal(titleText, 'Lighthouse');
assert.equal(urlText, 'http://example.com');
});


it('should populate the category checkboxes correctly', async function() {
const checkboxTitles = await page.$$eval('li label', els => els.map(e => e.textContent));
const checkboxValues = await page.$$eval('li label input', els => els.map(e => e.value));

for (const {title, id} of defaultCategoriesStub) {
assert.ok(checkboxTitles.includes(title));
assert.ok(checkboxValues.includes(id));
}
});
});

0 comments on commit 1fb885b

Please sign in to comment.