Files
Oleg Isonen dcdac0eaa7 feat: Project settings dialog accessible from dashboard (#5514)
## 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
2025-12-15 17:23:16 +01:00

66 lines
2.1 KiB
TypeScript

import { expect, test } from "vitest";
import { setEnv } from "@webstudio-is/feature-flags";
import { renderData, ws } from "@webstudio-is/template";
import { createDefaultPages } from "@webstudio-is/project-build";
import type { Project } from "@webstudio-is/project";
import { registerContainers } from "../sync/sync-stores";
import { $instances, $pages, $project } from "../nano-states";
import { $awareness } from "../awareness";
import { html } from "./plugin-html";
setEnv("*");
registerContainers();
test("paste html fragment", async () => {
const data = renderData(
<ws.element ws:tag="body" ws:id="bodyId">
<ws.element ws:tag="div" ws:id="divId"></ws.element>
</ws.element>
);
$project.set({ id: "" } as Project);
$instances.set(data.instances);
$pages.set(
createDefaultPages({ rootInstanceId: "bodyId", homePageId: "pageId" })
);
$awareness.set({ pageId: "pageId", instanceSelector: ["divId", "bodyId"] });
expect(
await html.onPaste?.(`
<section>
<h1>It works</h1>
</section>
`)
).toEqual(true);
const [_bodyId, _divId, sectionId, headingId] = $instances.get().keys();
expect(sectionId).toBeTruthy();
expect(headingId).toBeTruthy();
expect($instances.get()).toEqual(
renderData(
<ws.element ws:tag="body" ws:id="bodyId">
<ws.element ws:tag="div" ws:id="divId">
<ws.element ws:tag="section" ws:id={sectionId}>
<ws.element ws:tag="h1" ws:id={headingId}>
It works
</ws.element>
</ws.element>
</ws.element>
</ws.element>
).instances
);
});
test("ignore html without any tags", async () => {
const data = renderData(
<ws.element ws:tag="body" ws:id="bodyId">
<ws.element ws:tag="div" ws:id="divId"></ws.element>
</ws.element>
);
$project.set({ id: "" } as Project);
$instances.set(data.instances);
$pages.set(
createDefaultPages({ rootInstanceId: "bodyId", homePageId: "pageId" })
);
$awareness.set({ pageId: "pageId", instanceSelector: ["divId", "bodyId"] });
expect(await html.onPaste?.(`It works`)).toEqual(false);
expect($instances.get()).toEqual(data.instances);
});