feat(FN-3344): preserve history state in deep-link close
Fixes deep-link close to preserve browser history state and adds comprehensive integration tests for the navigation history feature, covering App component and useDeepLink hook behavior. Fusion-Task-Id: FN-3344
This commit is contained in:
@@ -936,7 +936,7 @@ describe("App deep link handling", () => {
|
||||
// Should have cleaned the task param from the URL via replaceState
|
||||
await waitFor(() => {
|
||||
expect(window.history.replaceState).toHaveBeenCalledWith(
|
||||
null,
|
||||
expect.any(Object),
|
||||
"",
|
||||
"/",
|
||||
);
|
||||
@@ -972,7 +972,7 @@ describe("App deep link handling", () => {
|
||||
// Should have removed only the task param, keeping project param
|
||||
await waitFor(() => {
|
||||
expect(window.history.replaceState).toHaveBeenCalledWith(
|
||||
null,
|
||||
expect.any(Object),
|
||||
"",
|
||||
"/?project=proj_456",
|
||||
);
|
||||
|
||||
@@ -142,11 +142,15 @@ describe("useDeepLink", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("cleans task query param when deep-linked modal closes", async () => {
|
||||
it("cleans task query param when deep-linked modal closes and preserves history state", async () => {
|
||||
Object.defineProperty(window, "location", {
|
||||
configurable: true,
|
||||
value: new URL("http://localhost:3000/?project=proj_123&task=FN-123"),
|
||||
});
|
||||
const replaceStateMock = window.history.replaceState as ReturnType<typeof vi.fn>;
|
||||
window.history.replaceState = originalReplaceState;
|
||||
window.history.replaceState({ navIndex: 2, existing: "value" }, "");
|
||||
window.history.replaceState = replaceStateMock;
|
||||
|
||||
const { result, closeTaskDetail } = renderUseDeepLink();
|
||||
|
||||
@@ -157,7 +161,7 @@ describe("useDeepLink", () => {
|
||||
result.current.handleDetailClose();
|
||||
|
||||
expect(window.history.replaceState).toHaveBeenCalledWith(
|
||||
null,
|
||||
{ navIndex: 2, existing: "value" },
|
||||
"",
|
||||
"/?project=proj_123",
|
||||
);
|
||||
|
||||
@@ -91,8 +91,9 @@ export function useDeepLink(options: UseDeepLinkOptions): UseDeepLinkResult {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
params.delete("task");
|
||||
const query = params.toString();
|
||||
const existingState = window.history.state ?? {};
|
||||
window.history.replaceState(
|
||||
null,
|
||||
existingState,
|
||||
"",
|
||||
query ? `${window.location.pathname}?${query}` : window.location.pathname,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user