@@ -61,9 +63,9 @@ export const SummaryTooltip: FunctionComponent<{
diff --git a/flow-report/src/summary/summary.tsx b/flow-report/src/summary/summary.tsx
index 1d6c9b4fd7a6..8fc51283fa36 100644
--- a/flow-report/src/summary/summary.tsx
+++ b/flow-report/src/summary/summary.tsx
@@ -11,13 +11,13 @@ import {FlowSegment, FlowStepThumbnail, Separator} from '../common';
import {getModeDescription, useFlowResult} from '../util';
import {Util} from '../../../report/renderer/util';
import {SummaryCategory} from './category';
-import {useStringFormatter, useUIStrings} from '../i18n/i18n';
+import {useStringFormatter, useLocalizedStrings} from '../i18n/i18n';
const DISPLAYED_CATEGORIES = ['performance', 'accessibility', 'best-practices', 'seo'];
const THUMBNAIL_WIDTH = 50;
const SummaryNavigationHeader: FunctionComponent<{lhr: LH.Result}> = ({lhr}) => {
- const strings = useUIStrings();
+ const strings = useLocalizedStrings();
return (
@@ -50,7 +50,7 @@ export const SummaryFlowStep: FunctionComponent<{
hashIndex: number,
}> = ({lhr, label, hashIndex}) => {
const reportResult = useMemo(() => Util.prepareReportResult(lhr), [lhr]);
- const strings = useUIStrings();
+ const strings = useLocalizedStrings();
const modeDescription = getModeDescription(lhr.gatherMode, strings);
return (
@@ -107,7 +107,7 @@ const SummaryFlow: FunctionComponent = () => {
export const SummaryHeader: FunctionComponent = () => {
const flowResult = useFlowResult();
- const strings = useUIStrings();
+ const strings = useLocalizedStrings();
const str_ = useStringFormatter();
let numNavigation = 0;
@@ -151,7 +151,7 @@ const SummarySectionHeader: FunctionComponent = ({children}) => {
};
export const Summary: FunctionComponent = () => {
- const strings = useUIStrings();
+ const strings = useLocalizedStrings();
return (
diff --git a/flow-report/src/topbar.tsx b/flow-report/src/topbar.tsx
index 4ef27fed6b6b..dc5519a89bdf 100644
--- a/flow-report/src/topbar.tsx
+++ b/flow-report/src/topbar.tsx
@@ -9,7 +9,7 @@ import {useState} from 'preact/hooks';
import {HelpDialog} from './help-dialog';
import {getFilenamePrefix} from '../../report/generator/file-namer';
-import {useUIStrings} from './i18n/i18n';
+import {useLocalizedStrings} from './i18n/i18n';
import {HamburgerIcon} from './icons';
import {useFlowResult} from './util';
import {useReportRenderer} from './wrappers/report-renderer';
@@ -79,7 +79,7 @@ export const Topbar: FunctionComponent<{onMenuClick: JSX.MouseEventHandler {
const flowResult = useFlowResult();
const {dom} = useReportRenderer();
- const strings = useUIStrings();
+ const strings = useLocalizedStrings();
const [showHelpDialog, setShowHelpDialog] = useState(false);
return (
diff --git a/flow-report/src/util.ts b/flow-report/src/util.ts
index fabc740c2794..d46222219fcc 100644
--- a/flow-report/src/util.ts
+++ b/flow-report/src/util.ts
@@ -79,11 +79,6 @@ export function useFlowResult(): LH.FlowResult {
return flowResult;
}
-export function useLocale(): LH.Locale {
- const flowResult = useFlowResult();
- return flowResult.steps[0].lhr.configSettings.locale;
-}
-
export function useHashParam(param: string) {
const [paramValue, setParamValue] = useState(getHashParam(param));
diff --git a/flow-report/test/topbar-test.tsx b/flow-report/test/topbar-test.tsx
index bac5620b6e7d..87b301412b28 100644
--- a/flow-report/test/topbar-test.tsx
+++ b/flow-report/test/topbar-test.tsx
@@ -18,6 +18,7 @@ const flowResult = {
steps: [{lhr: {
fetchTime: '2021-09-14T22:24:22.462Z',
configSettings: {locale: 'en-US'},
+ i18n: {rendererFormattedStrings: {}},
}}],
} as any;
diff --git a/flow-report/test/wrappers/category-score-test.tsx b/flow-report/test/wrappers/category-score-test.tsx
new file mode 100644
index 000000000000..7087221a216e
--- /dev/null
+++ b/flow-report/test/wrappers/category-score-test.tsx
@@ -0,0 +1,88 @@
+/**
+ * @license Copyright 2021 The Lighthouse Authors. All Rights Reserved.
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
+ */
+
+import {FunctionComponent} from 'preact';
+import {render} from '@testing-library/preact';
+
+import {CategoryScore} from '../../src/wrappers/category-score';
+import {FlowResultContext} from '../../src/util';
+import {ReportRendererProvider} from '../../src/wrappers/report-renderer';
+import {I18nProvider} from '../../src/i18n/i18n';
+import {flowResult} from '../sample-flow';
+
+let wrapper: FunctionComponent;
+
+beforeEach(() => {
+ wrapper = ({children}) => (
+
+
+
+ {children}
+
+
+
+ );
+});
+
+describe('CategoryScore', () => {
+ it('renders score gauge', () => {
+ const category: any = {
+ id: 'seo',
+ score: 0.95,
+ auditRefs: [],
+ };
+ const root = render(
+ ,
+ {wrapper}
+ );
+
+ const link = root.getByRole('link') as HTMLAnchorElement;
+
+ expect(link.href).toEqual('file:///Users/example/report.html/#seo');
+ expect(root.getByText('95')).toBeTruthy();
+ expect(root.baseElement.querySelector('.lh-gauge__label')).toBeFalsy();
+ });
+
+ it('renders error gauge', () => {
+ const category: any = {
+ id: 'seo',
+ score: null,
+ auditRefs: [],
+ };
+ const root = render(
+ ,
+ {wrapper}
+ );
+
+ const link = root.getByRole('link') as HTMLAnchorElement;
+
+ expect(link.href).toEqual('file:///Users/example/report.html/#seo');
+ expect(root.getByText('?')).toBeTruthy();
+ });
+
+ it('renders category fraction', () => {
+ const category: any = {
+ id: 'seo',
+ auditRefs: [
+ {weight: 1, result: {score: 1, scoreDisplayMode: 'binary'}},
+ {weight: 1, result: {score: 1, scoreDisplayMode: 'binary'}},
+ {weight: 1, result: {score: 0, scoreDisplayMode: 'binary'}},
+ {weight: 1, result: {score: 0, scoreDisplayMode: 'binary'}},
+ ],
+ };
+ const root = render(
+ ,
+ {wrapper}
+ );
+
+ const link = root.getByRole('link') as HTMLAnchorElement;
+
+ expect(link.href).toEqual('file:///Users/example/report.html/#seo');
+ expect(root.getByText('2/4')).toBeTruthy();
+ expect(root.baseElement.querySelector('.lh-fraction__label')).toBeFalsy();
+ expect(root.baseElement.querySelector('.lh-fraction__background')).toBeFalsy();
+ });
+});
diff --git a/lighthouse-core/util-commonjs.js b/lighthouse-core/util-commonjs.js
index 1859136ba834..9af382901cef 100644
--- a/lighthouse-core/util-commonjs.js
+++ b/lighthouse-core/util-commonjs.js
@@ -170,6 +170,8 @@ class Util {
/**
* Convert a score to a rating label.
+ * TODO: Return `'error'` for `score === null && !scoreDisplayMode`.
+ *
* @param {number|null} score
* @param {string=} scoreDisplayMode
* @return {string}
diff --git a/report/renderer/util.js b/report/renderer/util.js
index 488911b3d283..cb12d1bff35f 100644
--- a/report/renderer/util.js
+++ b/report/renderer/util.js
@@ -167,6 +167,8 @@ export class Util {
/**
* Convert a score to a rating label.
+ * TODO: Return `'error'` for `score === null && !scoreDisplayMode`.
+ *
* @param {number|null} score
* @param {string=} scoreDisplayMode
* @return {string}