feat(FN-5521): derive secrets media parsing from hook query
Test coverage for mobile views: `MobileNavBar.test.tsx` now syncs its mock with the viewport constant, and `SecretsView.mobile.test.tsx` derives secrets media parsing from the hook query. Fusion-Task-Id: FN-5521 Fusion-Task-Lineage: eb37d760-ab67-49c5-9b57-2c14d648a98a Co-authored-by: Fusion (runfusion.ai) <noreply@runfusion.ai> Fusion-Task-Id: FN-5521
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { MobileNavBar } from "../MobileNavBar";
|
||||
import { MOBILE_MEDIA_QUERY } from "../../hooks/useViewportMode";
|
||||
|
||||
vi.mock("../../api", () => ({
|
||||
fetchScripts: vi.fn(),
|
||||
@@ -12,7 +13,7 @@ function mockViewport(mode: "mobile" | "desktop") {
|
||||
Object.defineProperty(window, "matchMedia", {
|
||||
writable: true,
|
||||
value: vi.fn().mockImplementation((query: string) => {
|
||||
const isMobileQuery = query === "(max-width: 768px)" || query === "(max-width: 768px), (max-height: 480px)";
|
||||
const isMobileQuery = query === MOBILE_MEDIA_QUERY || query.includes("max-width: 768px");
|
||||
const isTabletQuery = query === "(min-width: 769px) and (max-width: 1024px)";
|
||||
return {
|
||||
matches: mode === "mobile" ? isMobileQuery : false,
|
||||
|
||||
@@ -5,6 +5,7 @@ import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { loadAllAppCss, loadAllAppCssBaseOnly } from "../../test/cssFixture";
|
||||
import { SecretsView } from "../SecretsView";
|
||||
import { MOBILE_MEDIA_QUERY } from "../../hooks/useViewportMode";
|
||||
|
||||
type JsonResponse = {
|
||||
ok: boolean;
|
||||
@@ -40,9 +41,14 @@ function findRuleBodyContainingSelector(css: string, selector: string): string {
|
||||
return "";
|
||||
}
|
||||
|
||||
function escapeRegExp(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
function extractMobileMediaBlocks(content: string): string {
|
||||
const blocks: string[] = [];
|
||||
const regex = /@media[^{]*\(max-width: 768px\)[^{]*\{/g;
|
||||
const queryPattern = `${escapeRegExp(MOBILE_MEDIA_QUERY)}(?:\\s*,\\s*\\([^)]*\\))*`;
|
||||
const regex = new RegExp(`@media\\s*${queryPattern}\\s*\\{`, "g");
|
||||
let match: RegExpExecArray | null;
|
||||
|
||||
while ((match = regex.exec(content)) !== null) {
|
||||
@@ -110,7 +116,9 @@ describe("SecretsView mobile layout contracts", () => {
|
||||
|
||||
it("keeps SecretsView.css token-only", () => {
|
||||
const normalizedCss = secretsViewCss
|
||||
.replace(new RegExp(escapeRegExp(MOBILE_MEDIA_QUERY), "g"), "MOBILE_MEDIA_QUERY")
|
||||
.replace(/max-width:\s*768px/g, "max-width: MOBILE_BREAKPOINT")
|
||||
.replace(/max-height:\s*480px/g, "max-height: MOBILE_HEIGHT_BREAKPOINT")
|
||||
.replace(/\b0px\b/g, "0");
|
||||
|
||||
expect(normalizedCss).not.toMatch(/#[0-9a-fA-F]{3,8}\b/);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { setTimeout as delay } from "node:timers/promises";
|
||||
import type { AutoRecoverySettings } from "@fusion/core";
|
||||
import { createLogger, type Logger } from "../logger.js";
|
||||
import type { RunAuditor } from "../run-audit.js";
|
||||
@@ -84,7 +85,7 @@ export class MessageDeliveryAutoRecoveryHandler {
|
||||
}
|
||||
const delayMs = backoffs[Math.min(attempts - 1, backoffs.length - 1)];
|
||||
this.logger.warn(`message-delivery retrying ${attempt.correlation.kind} message for ${attempt.correlation.fromAgentId} attempt=${attempts + 1}`);
|
||||
await (this.deps.sleep ? this.deps.sleep(delayMs) : new Promise((resolve) => setTimeout(resolve, delayMs)));
|
||||
await (this.deps.sleep ? this.deps.sleep(delayMs) : delay(delayMs));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user