feat: expand utility widgets (#6638)
This commit is contained in:
1 parent
53b518960c
commit
58a24569ce
86 files changed
+7660
-751
No files matched your search
@@ -1,26 +1,25 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { getPreferredTime, getPreferredUnit, getPreferredWindSpeed, getVisibleForecastDays } from "./component";
|
||||
import { reduceWidgetOptionsWithDefinition } from "../manifest";
|
||||
import { definition } from ".";
|
||||
import { getPreferredTime, getPreferredUnit, getPreferredWindSpeed } from "./format";
|
||||
import { formatWeatherDate } from "./icon";
|
||||
import { getAdvancedWeatherLayout, getCompactWeatherLayout } from "./layout";
|
||||
|
||||
describe("weather formatting", () => {
|
||||
it("preserves valid zero temperatures", () => {
|
||||
it("preserves valid zero values", () => {
|
||||
expect(getPreferredUnit(0)).toBe("0.0°C");
|
||||
expect(getPreferredUnit(0, true, true)).toBe("32°F");
|
||||
expect(getPreferredWindSpeed(0)).toBe("0.0");
|
||||
});
|
||||
|
||||
it("keeps zero wind speeds and missing forecast values truthful", () => {
|
||||
expect(getPreferredWindSpeed(0)).toBe("0.0");
|
||||
it("keeps missing and invalid values truthful", () => {
|
||||
expect(getPreferredUnit(null)).toBe("?");
|
||||
expect(getPreferredWindSpeed(undefined)).toBe("?");
|
||||
expect(getPreferredTime(undefined, "en-US")).toBe("?");
|
||||
expect(getPreferredTime("invalid", "en-US")).toBe("?");
|
||||
});
|
||||
|
||||
it("limits compact forecasts by both axes", () => {
|
||||
expect(getVisibleForecastDays(7, 120, 100)).toBe(2);
|
||||
expect(getVisibleForecastDays(7, 600, 100)).toBe(3);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["dddd, MMMM D", "Monday, August 3"],
|
||||
["dddd, D MMMM", "Monday, 3 August"],
|
||||
@@ -34,3 +33,61 @@ describe("weather formatting", () => {
|
||||
expect(formatWeatherDate("2026-08-03", "en-US", pattern)).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("weather layout", () => {
|
||||
it("keeps micro widgets focused on current temperature", () => {
|
||||
expect(getCompactWeatherLayout(120, 100, true, 7)).toEqual({
|
||||
tier: "micro",
|
||||
forecastDays: 0,
|
||||
showCity: false,
|
||||
showCondition: false,
|
||||
showHighLow: false,
|
||||
showSecondary: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("caps compact forecasts by size and saved preference", () => {
|
||||
expect(getCompactWeatherLayout(200, 200, true, 7).forecastDays).toBe(2);
|
||||
expect(getCompactWeatherLayout(424, 200, true, 3).forecastDays).toBe(3);
|
||||
expect(getCompactWeatherLayout(640, 360, true, 7).forecastDays).toBe(7);
|
||||
expect(getCompactWeatherLayout(640, 360, false, 7).forecastDays).toBe(0);
|
||||
});
|
||||
|
||||
it("adapts the advanced view to mobile and desktop surfaces", () => {
|
||||
expect(getAdvancedWeatherLayout(374, 624)).toMatchObject({
|
||||
dailyColumns: 2,
|
||||
hourlyTickStep: 6,
|
||||
showChartAxes: false,
|
||||
});
|
||||
expect(getAdvancedWeatherLayout(800, 560)).toMatchObject({
|
||||
chartHeight: 200,
|
||||
dailyColumns: 4,
|
||||
hourlyTickStep: 3,
|
||||
showChartAxes: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("weather defaults", () => {
|
||||
it("starts rich and static while preserving saved false values", () => {
|
||||
const options = definition.createOptions();
|
||||
expect(options.showCity.defaultValue).toBe(true);
|
||||
expect(options.hasForecast.defaultValue).toBe(true);
|
||||
expect(options.forecastDayCount.defaultValue).toBe(3);
|
||||
expect(options.animateIcons.defaultValue).toBe(false);
|
||||
expect(options.showHumidity.defaultValue).toBe(true);
|
||||
|
||||
const reduced = reduceWidgetOptionsWithDefinition(definition, {} as never, {
|
||||
showCity: false,
|
||||
hasForecast: false,
|
||||
showHumidity: false,
|
||||
isFormatFahrenheit: true,
|
||||
});
|
||||
expect(reduced).toMatchObject({
|
||||
showCity: false,
|
||||
hasForecast: false,
|
||||
showHumidity: false,
|
||||
isFormatFahrenheit: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user