diff --git a/core/util.cjs b/core/util.cjs index c6a8acb4b014..dc5efface9a4 100644 --- a/core/util.cjs +++ b/core/util.cjs @@ -516,10 +516,12 @@ class Util { summary = cpuThrottling = networkThrottling = Util.i18n.strings.runtimeUnknown; } - const deviceEmulation = { - mobile: Util.i18n.strings.runtimeMobileEmulation, - desktop: Util.i18n.strings.runtimeDesktopEmulation, - }[settings.formFactor] || Util.i18n.strings.runtimeNoEmulation; + let deviceEmulation = Util.i18n.strings.runtimeMobileEmulation; + if (settings.screenEmulation.disabled) { + deviceEmulation = Util.i18n.strings.runtimeNoEmulation; + } else if (!settings.screenEmulation.mobile) { + deviceEmulation = Util.i18n.strings.runtimeDesktopEmulation; + } const screenEmulation = settings.screenEmulation.disabled ? undefined : diff --git a/flow-report/test/sidebar/sidebar-test.tsx b/flow-report/test/sidebar/sidebar-test.tsx index 66bdbca7c00d..92779ac32d19 100644 --- a/flow-report/test/sidebar/sidebar-test.tsx +++ b/flow-report/test/sidebar/sidebar-test.tsx @@ -58,11 +58,17 @@ describe('SidebarRuntimeSettings', () => { throughputKbps: 1.6 * 1024, rttMs: 150, }, - screenEmulation: {disabled: true}, + screenEmulation: { + disabled: false, + width: 200, + height: 200, + deviceScaleFactor: 3, + mobile: true, + }, } as any; const root = render(, {wrapper}); - expect(root.getByText('Emulated Moto G4')).toBeTruthy(); + expect(root.getByText('Emulated Moto G4 - 200x200, DPR 3')).toBeTruthy(); expect(root.queryByText('Emulated Moto G4 -')).toBeFalsy(); expect(root.getByText('Slow 4G throttling')).toBeTruthy(); expect(root.getByText('4x slowdown')); @@ -83,6 +89,7 @@ describe('SidebarRuntimeSettings', () => { screenEmulation: { width: 100, height: 100, + mobile: false, deviceScaleFactor: 2, }, } as any; @@ -92,4 +99,18 @@ describe('SidebarRuntimeSettings', () => { expect(root.getByText('Custom throttling')).toBeTruthy(); expect(root.getByText('1x slowdown')); }); + + it('displays runtime settings when screenEmulation disabled', async () => { + const settings = { + formFactor: 'mobile', + throttlingMethod: 'provided', + throttling: {}, + screenEmulation: {disabled: true}, + } as any; + const root = render(, {wrapper}); + + expect(root.getByText('No emulation')).toBeTruthy(); + expect(root.queryByText('Emulated Moto G4 -')).toBeFalsy(); + expect(root.getByText('Provided by environment')).toBeTruthy(); + }); }); diff --git a/report/renderer/util.js b/report/renderer/util.js index b958bcc0739f..b742fcf62348 100644 --- a/report/renderer/util.js +++ b/report/renderer/util.js @@ -512,10 +512,12 @@ class Util { summary = cpuThrottling = networkThrottling = Util.i18n.strings.runtimeUnknown; } - const deviceEmulation = { - mobile: Util.i18n.strings.runtimeMobileEmulation, - desktop: Util.i18n.strings.runtimeDesktopEmulation, - }[settings.formFactor] || Util.i18n.strings.runtimeNoEmulation; + let deviceEmulation = Util.i18n.strings.runtimeMobileEmulation; + if (settings.screenEmulation.disabled) { + deviceEmulation = Util.i18n.strings.runtimeNoEmulation; + } else if (!settings.screenEmulation.mobile) { + deviceEmulation = Util.i18n.strings.runtimeDesktopEmulation; + } const screenEmulation = settings.screenEmulation.disabled ? undefined : diff --git a/report/test/renderer/util-test.js b/report/test/renderer/util-test.js index 88b6dfb495d0..49d6aa5eda14 100644 --- a/report/test/renderer/util-test.js +++ b/report/test/renderer/util-test.js @@ -33,12 +33,13 @@ describe('util helpers', () => { }); it('builds device emulation string', () => { - const get = opts => Util.getEmulationDescriptions({ - ...opts, - screenEmulation: {disabled: true}, - }).deviceEmulation; - assert.equal(get({formFactor: 'mobile'}), 'Emulated Moto G4'); - assert.equal(get({formFactor: 'desktop'}), 'Emulated Desktop'); + const get = settings => Util.getEmulationDescriptions(settings).deviceEmulation; + /* eslint-disable max-len */ + assert.equal(get({formFactor: 'mobile', screenEmulation: {disabled: false, mobile: true}}), 'Emulated Moto G4'); + assert.equal(get({formFactor: 'mobile', screenEmulation: {disabled: true, mobile: true}}), 'No emulation'); + assert.equal(get({formFactor: 'desktop', screenEmulation: {disabled: false, mobile: false}}), 'Emulated Desktop'); + assert.equal(get({formFactor: 'desktop', screenEmulation: {disabled: true, mobile: false}}), 'No emulation'); + /* eslint-enable max-len */ }); it('builds throttling strings when provided', () => {