mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-10-28 23:57:17 +09:00
## Description 1. What is this PR about (link the issue and add a short description) ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
83 lines
2.0 KiB
TypeScript
83 lines
2.0 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import type { Page, Pages } from "@webstudio-is/sdk";
|
|
import { $pages } from "~/shared/sync/data-stores";
|
|
import { registerContainers } from "~/shared/sync/sync-stores";
|
|
import { updateCurrentSystem } from "./system";
|
|
import { selectPage } from "./awareness";
|
|
|
|
registerContainers();
|
|
|
|
const getInitialPages = (page: Page): Pages => ({
|
|
folders: [
|
|
{
|
|
id: "rootId",
|
|
name: "",
|
|
slug: "",
|
|
children: ["homeId", "dynamicId"],
|
|
},
|
|
],
|
|
homePage: {
|
|
id: "homeId",
|
|
path: "",
|
|
name: "",
|
|
title: "",
|
|
meta: {},
|
|
rootInstanceId: "",
|
|
},
|
|
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: "",
|
|
})
|
|
);
|
|
selectPage("dynamicId");
|
|
updateCurrentSystem({
|
|
params: { date: "my-date", slug: "my-slug" },
|
|
});
|
|
expect($pages.get()?.pages[0].history).toEqual([
|
|
"/blog/my-date/post/my-slug",
|
|
]);
|
|
updateCurrentSystem({
|
|
params: { date: "another-date", slug: "another-slug" },
|
|
});
|
|
expect($pages.get()?.pages[0].history).toEqual([
|
|
"/blog/another-date/post/another-slug",
|
|
"/blog/my-date/post/my-slug",
|
|
]);
|
|
});
|
|
|
|
test("move existing path to the start", () => {
|
|
$pages.set(
|
|
getInitialPages({
|
|
id: "dynamicId",
|
|
path: "/blog/:date/post/:slug",
|
|
name: "",
|
|
title: "",
|
|
meta: {},
|
|
rootInstanceId: "",
|
|
history: [
|
|
"/blog/another-date/post/another-slug",
|
|
"/blog/my-date/post/my-slug",
|
|
],
|
|
})
|
|
);
|
|
selectPage("dynamicId");
|
|
updateCurrentSystem({
|
|
params: { date: "my-date", slug: "my-slug" },
|
|
});
|
|
expect($pages.get()?.pages[0].history).toEqual([
|
|
"/blog/my-date/post/my-slug",
|
|
"/blog/another-date/post/another-slug",
|
|
]);
|
|
});
|
|
});
|