test: add release v2 browser QA campaign

This commit is contained in:
ajnart committed 2026-09-01 01:03:27 +02:00
1 parent f57a660088
commit ec95d18245
83 files changed
+20922 -19

No files matched your search

@@ -0,0 +1,94 @@
import { NextRequest } from "next/server";
import { describe, expect, it } from "vitest";
import { createI18nMiddleware } from "./middleware";
const createRewrittenRequest = (response: Response) => {
const destination = response.headers.get("x-middleware-rewrite");
const overriddenHeaderNames = response.headers.get("x-middleware-override-headers")?.split(",") ?? [];
const headers = new Headers();
for (const name of overriddenHeaderNames) {
const value = response.headers.get(`x-middleware-request-${name}`);
if (value !== null) {
headers.set(name, value);
}
}
if (destination === null) {
throw new Error("Expected middleware to rewrite the request");
}
return new NextRequest(destination, { headers });
};
describe("createI18nMiddleware", () => {
it("canonicalizes a prefixed path when the locale header is supplied externally", () => {
const middleware = createI18nMiddleware("en");
const request = new NextRequest("http://localhost/en/auth/login", {
headers: {
cookie: "homarr.locale=fr",
"x-next-intl-locale": "en",
},
});
const response = middleware(request);
expect(response.headers.get("x-middleware-next")).toBeNull();
expect(response.headers.get("location")).toBe("http://localhost/auth/login");
expect(response.headers.get("set-cookie")).toContain("homarr.locale=en");
});
it("continues a valid internal locale handoff across middleware instances", () => {
const firstPassMiddleware = createI18nMiddleware("en");
const publicRequest = new NextRequest("http://localhost/auth/login");
const rewriteResponse = firstPassMiddleware(publicRequest);
expect(rewriteResponse.headers.get("x-middleware-rewrite")).toBe("http://localhost/en/auth/login");
const localizedRequest = createRewrittenRequest(rewriteResponse);
const secondPassMiddleware = createI18nMiddleware("en");
const handoffResponse = secondPassMiddleware(localizedRequest);
expect(handoffResponse.headers.get("x-middleware-next")).toBe("1");
expect(handoffResponse.headers.get("location")).toBeNull();
expect(handoffResponse.headers.get("x-middleware-override-headers")).toBe("x-next-intl-locale");
});
it.each([
{
name: "unsupported locale",
pathname: "/en/auth/login",
locale: "xx",
},
{
name: "locale that does not match the path",
pathname: "/fr/auth/login",
locale: "en",
},
])("does not continue an internal handoff with a $name", ({ pathname, locale }) => {
const middleware = createI18nMiddleware("en");
const rewriteResponse = middleware(new NextRequest("http://localhost/auth/login"));
const rewrittenRequest = createRewrittenRequest(rewriteResponse);
rewrittenRequest.headers.set("x-next-intl-locale", locale);
const request = new NextRequest(`http://localhost${pathname}`, {
headers: rewrittenRequest.headers,
});
const response = middleware(request);
expect(response.headers.get("x-middleware-next")).toBeNull();
expect(response.headers.get("location")).toBe("http://localhost/auth/login");
});
it("canonicalizes a directly requested prefixed path and synchronizes its locale", () => {
const middleware = createI18nMiddleware("en");
const request = new NextRequest("http://localhost/fr/auth/login");
const response = middleware(request);
expect(response.headers.get("x-middleware-next")).toBeNull();
expect(response.headers.get("location")).toBe("http://localhost/auth/login");
expect(response.headers.get("set-cookie")).toContain("homarr.locale=fr");
});
});
+26 -2
View File
@@ -1,11 +1,35 @@
import createMiddleware from "next-intl/middleware";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import type { SupportedLanguage } from ".";
import { supportedLanguages } from "./languages";
import { createRouting } from "./routing";
export const createI18nMiddleware = (defaultLocale: SupportedLanguage) =>
createMiddleware(createRouting(defaultLocale));
// next-intl carries request headers through its rewrite. Keep the random value
// module-private so a client-supplied locale header cannot impersonate that handoff.
const localeHandoffHeader = "x-homarr-locale-handoff";
const localeHandoffMarker = crypto.randomUUID();
export const createI18nMiddleware = (defaultLocale: SupportedLanguage) => {
const middleware = createMiddleware(createRouting(defaultLocale));
return (request: NextRequest) => {
const requestLocale = request.headers.get("x-next-intl-locale");
const pathLocale = request.nextUrl.pathname.split("/")[1];
const isSupportedLocale = supportedLanguages.includes(requestLocale as SupportedLanguage);
const isInternalHandoff = request.headers.get(localeHandoffHeader) === localeHandoffMarker;
if (isInternalHandoff && isSupportedLocale && requestLocale === pathLocale) {
const headers = new Headers(request.headers);
headers.delete(localeHandoffHeader);
return NextResponse.next({ request: { headers } });
}
request.headers.set(localeHandoffHeader, localeHandoffMarker);
return middleware(request);
};
};
export const config = {
// Match only internationalized pathnames
+4 -3
View File
@@ -15,6 +15,7 @@ import { formatWeatherDate, WeatherDescription } from "./icon";
import { getCompactWeatherLayout } from "./layout";
interface CompactWeatherProps {
displayScale: number;
height: number;
isEditMode: boolean;
options: WidgetProps<"weather">["options"];
@@ -22,13 +23,13 @@ interface CompactWeatherProps {
width: number;
}
export const CompactWeather = ({ height, isEditMode, options, weather, width }: CompactWeatherProps) => {
export const CompactWeather = ({ displayScale, height, isEditMode, options, weather, width }: CompactWeatherProps) => {
const locale = useCurrentIntlLocale();
const t = useI18n("widget.weather");
const tCommon = useI18n("common");
const layout = useMemo(
() => getCompactWeatherLayout(width, height, options.hasForecast, options.forecastDayCount),
[height, options.forecastDayCount, options.hasForecast, width],
() => getCompactWeatherLayout(width, height, options.hasForecast, options.forecastDayCount, displayScale),
[displayScale, height, options.forecastDayCount, options.hasForecast, width],
);
const today = weather.daily[0];
const speedUnit = options.useImperialSpeed
@@ -53,6 +53,18 @@ describe("weather layout", () => {
expect(getCompactWeatherLayout(640, 360, false, 7).forecastDays).toBe(0);
});
it("uses the rendered dimensions when a responsive board scales the widget", () => {
expect(getCompactWeatherLayout(320, 180, true, 7).tier).toBe("standard");
expect(getCompactWeatherLayout(320, 180, true, 7, 0.5)).toEqual({
tier: "micro",
forecastDays: 0,
showCity: false,
showCondition: false,
showHighLow: false,
showSecondary: false,
});
});
it("adapts the advanced view to mobile and desktop surfaces", () => {
expect(getAdvancedWeatherLayout(374, 624)).toMatchObject({
dailyColumns: 2,
+9 -1
View File
@@ -18,6 +18,7 @@ export default function WeatherWidget({
width,
height,
displayMode,
displayScale = 1,
}: WidgetComponentProps<"weather">) {
const input = {
latitude: options.location.latitude,
@@ -35,7 +36,14 @@ export default function WeatherWidget({
{displayMode === "advanced" ? (
<AdvancedWeather height={height} options={options} weather={weather} width={width} />
) : (
<CompactWeather height={height} isEditMode={isEditMode} options={options} weather={weather} width={width} />
<CompactWeather
displayScale={displayScale}
height={height}
isEditMode={isEditMode}
options={options}
weather={weather}
width={width}
/>
)}
</Box>
</Box>
+12 -4
View File
@@ -21,9 +21,17 @@ export const getCompactWeatherLayout = (
height: number,
hasForecast: boolean,
configuredDays: number,
displayScale = 1,
): CompactWeatherLayout => {
let responsiveWidth = width;
let responsiveHeight = height;
if (Number.isFinite(displayScale) && displayScale > 0) {
responsiveWidth *= displayScale;
responsiveHeight *= displayScale;
}
const breakpoint = compactWeatherBreakpoints.find(
({ minHeight, minWidth }) => width >= minWidth && height >= minHeight,
({ minHeight, minWidth }) => responsiveWidth >= minWidth && responsiveHeight >= minHeight,
);
const tier = breakpoint?.tier ?? "micro";
@@ -41,15 +49,15 @@ export const getCompactWeatherLayout = (
if (tier === "compact") {
return {
tier: "compact",
forecastDays: hasForecast ? Math.min(configuredDays, Math.max(1, Math.floor(width / 92))) : 0,
showCity: width >= 220,
forecastDays: hasForecast ? Math.min(configuredDays, Math.max(1, Math.floor(responsiveWidth / 92))) : 0,
showCity: responsiveWidth >= 220,
showCondition: true,
showHighLow: true,
showSecondary: false,
};
}
const availableForecastWidth = Math.max(0, width - 24);
const availableForecastWidth = Math.max(0, responsiveWidth - 24);
return {
tier,
forecastDays: hasForecast ? Math.min(configuredDays, Math.max(1, Math.floor(availableForecastWidth / 64))) : 0,