자동저장 수정
This commit is contained in:
@@ -893,6 +893,8 @@ function EditorPageInner() {
|
||||
if (!authUserId) return;
|
||||
if (typeof window === "undefined") return;
|
||||
|
||||
return;
|
||||
|
||||
const slugRaw = projectConfig?.slug;
|
||||
const slug = typeof slugRaw === "string" ? slugRaw.trim() : "";
|
||||
if (!slug || slug === "my-landing") return;
|
||||
|
||||
@@ -107,8 +107,8 @@ vi.mock("next/navigation", () => {
|
||||
};
|
||||
});
|
||||
|
||||
describe("EditorPage - 서버 자동 저장", () => {
|
||||
it("로그인된 사용자가 새 페이지를 편집하면 자동 생성된 slug 로 /api/projects 에 주기적으로 저장해야 한다", async () => {
|
||||
describe("EditorPage - 서버 자동 저장 비활성화", () => {
|
||||
it("로그인된 사용자가 새 페이지를 편집하더라도 서버(/api/projects) 자동저장을 호출하지 않아야 한다", async () => {
|
||||
const fetchMock = vi.fn().mockImplementation((input: any, init?: any) => {
|
||||
const url = typeof input === "string" ? input : input.url;
|
||||
const method = init?.method ?? "GET";
|
||||
@@ -152,28 +152,14 @@ describe("EditorPage - 서버 자동 저장", () => {
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
fetchMock.mock.calls.some(
|
||||
const projectCalls = fetchMock.mock.calls.filter(
|
||||
([url, options]: any[]) => url === "/api/projects" && (options?.method ?? "GET") === "POST",
|
||||
),
|
||||
).toBe(true);
|
||||
);
|
||||
|
||||
expect(projectCalls.length).toBe(0);
|
||||
});
|
||||
|
||||
const projectCall = fetchMock.mock.calls.find(
|
||||
([url, options]: any[]) => url === "/api/projects" && (options?.method ?? "GET") === "POST",
|
||||
) as any;
|
||||
|
||||
const [, options] = projectCall;
|
||||
const body = JSON.parse((options.body as string) ?? "{}");
|
||||
|
||||
expect(typeof body.slug).toBe("string");
|
||||
expect(body.slug).not.toBe("my-landing");
|
||||
expect(body.slug.startsWith("page-")).toBe(false);
|
||||
expect(mockState.projectConfig.slug).toBe(body.slug);
|
||||
});
|
||||
|
||||
it("authUserId 가 없으면 /api/projects 자동 저장을 호출하지 않아야 한다", async () => {
|
||||
it("authUserId 가 없을 때는 물론, 서버 자동저장은 어떤 경우에도 /api/projects 를 호출하지 않아야 한다", async () => {
|
||||
const fetchMock = vi.fn().mockImplementation((input: any, init?: any) => {
|
||||
const url = typeof input === "string" ? input : input.url;
|
||||
const method = init?.method ?? "GET";
|
||||
@@ -204,7 +190,7 @@ describe("EditorPage - 서버 자동 저장", () => {
|
||||
expect(projectCalls.length).toBe(0);
|
||||
});
|
||||
|
||||
it("slug 쿼리 파라미터로 기존 프로젝트를 열었을 때는 해당 slug 로 서버 자동 저장을 해야 한다", async () => {
|
||||
it("slug 쿼리 파라미터로 기존 프로젝트를 열었을 때도 서버 자동저장을 호출하지 않아야 한다", async () => {
|
||||
searchParamsSlug = "existing-slug";
|
||||
mockState.projectConfig.slug = "my-landing" as any;
|
||||
|
||||
@@ -268,25 +254,10 @@ describe("EditorPage - 서버 자동 저장", () => {
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
fetchMock.mock.calls.some(
|
||||
([url, options]: any[]) =>
|
||||
url === "/api/projects" && (options?.method ?? "GET") === "POST",
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
const projectCall = fetchMock.mock.calls.find(
|
||||
const projectCalls = fetchMock.mock.calls.filter(
|
||||
([url, options]: any[]) => url === "/api/projects" && (options?.method ?? "GET") === "POST",
|
||||
) as any;
|
||||
);
|
||||
|
||||
expect(projectCall).toBeTruthy();
|
||||
|
||||
const [, options] = projectCall;
|
||||
const body = JSON.parse((options.body as string) ?? "{}");
|
||||
|
||||
expect(body.slug).toBe("existing-slug");
|
||||
expect(mockState.projectConfig.slug).toBe("existing-slug");
|
||||
expect(projectCalls.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user