mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-08 13:05:08 +09:00
Here improved history support. Now navigating with links from preview adds paths into page history. This will let to reach same page without switching to the list of posts.
66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
import { describe, expect, test } from "@jest/globals";
|
|
import type { Page, Pages } from "@webstudio-is/sdk";
|
|
import { $pages } from "~/shared/nano-states";
|
|
import { registerContainers } from "~/shared/sync";
|
|
import { savePathInHistory } from "./pages";
|
|
|
|
registerContainers();
|
|
|
|
const getInitialPages = (page: Page): Pages => ({
|
|
folders: [
|
|
{
|
|
id: "rootId",
|
|
name: "",
|
|
slug: "",
|
|
children: ["homeId", "dynamicId"],
|
|
},
|
|
],
|
|
homePage: {
|
|
id: "homeId",
|
|
path: "",
|
|
name: "",
|
|
title: "",
|
|
meta: {},
|
|
rootInstanceId: "",
|
|
systemDataSourceId: "",
|
|
},
|
|
pages: [page],
|
|
});
|
|
|
|
describe("history", () => {
|
|
test("add new path at the start", () => {
|
|
$pages.set(
|
|
getInitialPages({
|
|
id: "dynamicId",
|
|
path: "/blog/:date/post/:slug",
|
|
name: "",
|
|
title: "",
|
|
meta: {},
|
|
rootInstanceId: "",
|
|
systemDataSourceId: "",
|
|
})
|
|
);
|
|
savePathInHistory("dynamicId", "/path1");
|
|
expect($pages.get()?.pages[0].history).toEqual(["/path1"]);
|
|
savePathInHistory("dynamicId", "/path2");
|
|
expect($pages.get()?.pages[0].history).toEqual(["/path2", "/path1"]);
|
|
});
|
|
|
|
test("move existing path to the start", () => {
|
|
$pages.set(
|
|
getInitialPages({
|
|
id: "dynamicId",
|
|
path: "/blog/:date/post/:slug",
|
|
name: "",
|
|
title: "",
|
|
meta: {},
|
|
rootInstanceId: "",
|
|
systemDataSourceId: "",
|
|
history: ["/path2", "/path1"],
|
|
})
|
|
);
|
|
savePathInHistory("dynamicId", "/path1");
|
|
expect($pages.get()?.pages[0].history).toEqual(["/path1", "/path2"]);
|
|
});
|
|
});
|