Bug 1896681 - Home and newtab adding region control for weather widget r=home-newtab-reviewers,amy

Differential Revision: https://phabricator.services.mozilla.com/D211146
This commit is contained in:
scottdowne 2024-05-23 14:42:32 +00:00
Родитель 50b5db7d13
Коммит e72395f2d5
4 изменённых файлов: 47 добавлений и 12 удалений

Просмотреть файл

@ -1696,12 +1696,13 @@ pref("browser.partnerlink.campaign.topsites", "amzn_2020_a1");
pref("browser.newtab.preload", true);
// Weather widget for newtab
pref("browser.newtabpage.activity-stream.system.showWeather", false);
pref("browser.newtabpage.activity-stream.showWeather", true);
pref("browser.newtabpage.activity-stream.weather.query", "");
pref("browser.newtabpage.activity-stream.weather.locationSearchEnabled", false);
pref("browser.newtabpage.activity-stream.weather.temperatureUnits", "f");
pref("browser.newtabpage.activity-stream.weather.display", "simple");
// List of regions that get weather by default.
pref("browser.newtabpage.activity-stream.discoverystream.region-weather-config", "");
// Preference to enable wallpaper selection in the Customize Menu of new tab page
pref("browser.newtabpage.activity-stream.newtabWallpapers.enabled", false);

Просмотреть файл

@ -58,11 +58,14 @@ function showSpocs({ geo }) {
return spocsGeo.includes(geo);
}
function showWeather() {
return (
lazy.NimbusFeatures.pocketNewtab.getVariable("newtabWeatherEnabled") ||
false
);
function showWeather({ geo }) {
const weatherGeoString =
lazy.NimbusFeatures.pocketNewtab.getVariable("regionWeatherConfig") || "";
const weatherGeo = weatherGeoString
.split(",")
.map(s => s.trim())
.filter(item => item);
return weatherGeo.includes(geo);
}
// Configure default Activity Stream prefs with a plain `value` or a `getValue`

Просмотреть файл

@ -311,6 +311,38 @@ describe("ActivityStream", () => {
);
});
});
describe("discoverystream.region-weather-config", () => {
let getVariableStub;
beforeEach(() => {
getVariableStub = sandbox.stub(
global.NimbusFeatures.pocketNewtab,
"getVariable"
);
sandbox.stub(global.Region, "home").get(() => "CA");
});
it("should turn off weather system pref if no region weather config is set and no geo is set", () => {
getVariableStub.withArgs("regionWeatherConfig").returns("");
sandbox.stub(global.Region, "home").get(() => "");
as._updateDynamicPrefs();
assert.isFalse(PREFS_CONFIG.get("system.showWeather").value);
});
it("should turn on weather system pref based on region weather config pref", () => {
getVariableStub.withArgs("regionWeatherConfig").returns("CA");
as._updateDynamicPrefs();
assert.isTrue(PREFS_CONFIG.get("system.showWeather").value);
});
it("should turn off weather system pref if no region weather config is set", () => {
getVariableStub.withArgs("regionWeatherConfig").returns("");
as._updateDynamicPrefs();
assert.isFalse(PREFS_CONFIG.get("system.showWeather").value);
});
});
describe("_updateDynamicPrefs topstories default value", () => {
let getVariableStub;
let getBoolPrefStub;

Просмотреть файл

@ -851,12 +851,6 @@ pocketNewtab:
pref: browser.newtabpage.activity-stream.newtabWallpapers.enabled
description: >-
Turns on and off wallpaper support.
newtabWeatherEnabled:
type: boolean
description: >-
Turns on and off the weather widget in home and newtab
fallbackPref: >-
browser.newtabpage.activity-stream.system.showWeather
recsPersonalized:
type: boolean
fallbackPref: >-
@ -939,6 +933,11 @@ pocketNewtab:
type: string
fallbackPref: >-
browser.newtabpage.activity-stream.discoverystream.region-spocs-config
regionWeatherConfig:
description: A comma-separated list of regions that get weather by default.
type: string
fallbackPref: >-
browser.newtabpage.activity-stream.discoverystream.region-weather-config
topSitesMaxSponsored:
# Defined under `pocketNewtab` as it needs to be used along with other variables
type: int