Skip to content

Commit 8234e3f

Browse files
committed
[form] WIP: Add content component test
1 parent 0c8cdf5 commit 8234e3f

File tree

8 files changed

+810
-122
lines changed

8 files changed

+810
-122
lines changed

mkfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ f/:
4141
pnpm run check
4242
t:
4343
pnpm run test $@
44+
tui:
45+
pnpm run test:ui
4446
popd
4547

4648
docs/:

packages/form/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"scripts": {
3030
"dev": "vite",
3131
"test": "vitest run --exclude '.svelte-kit/**'",
32+
"test:ui": "vitest --ui --exclude '.svelte-kit/**'",
3233
"build": "svelte-package && publint",
3334
"check": "svelte-check --tsconfig ./tsconfig.json"
3435
},
@@ -44,10 +45,14 @@
4445
"devDependencies": {
4546
"@sveltejs/package": "catalog:",
4647
"@sveltejs/vite-plugin-svelte": "catalog:",
48+
"@testing-library/jest-dom": "^6.6.3",
49+
"@testing-library/svelte": "^5.2.6",
4750
"@tsconfig/svelte": "catalog:",
4851
"@types/json-schema": "^7.0.15",
4952
"@types/json-schema-merge-allof": "^0.6.5",
53+
"@vitest/ui": "^3.0.4",
5054
"deep-freeze-es6": "^4.0.0",
55+
"jsdom": "^26.0.0",
5156
"svelte": "catalog:",
5257
"svelte-check": "catalog:",
5358
"vite": "catalog:",
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { it } from "vitest";
2+
import { render, screen } from "@testing-library/svelte";
3+
4+
import type { Schema } from "@/core/index.js";
5+
import { theme } from "@/basic-theme/index.js";
6+
import { createValidator } from "@/fake-validator.js";
7+
import { translation } from "@/translations/en.js";
8+
9+
import { FORM_CONTEXT } from "./context/index.js";
10+
import { createForm3 } from "./create-form.svelte.js";
11+
import Content from "./content.svelte";
12+
13+
it("should preserve multi select field state in array", () => {
14+
const schema: Schema = {
15+
type: "array",
16+
title: "Array",
17+
items: {
18+
anyOf: [
19+
{
20+
properties: {
21+
foo: {
22+
type: "string",
23+
},
24+
},
25+
},
26+
{
27+
properties: {
28+
bar: {
29+
type: "string",
30+
},
31+
},
32+
},
33+
],
34+
},
35+
};
36+
37+
const validator = createValidator();
38+
39+
const form = createForm3({
40+
...theme,
41+
validator,
42+
translation,
43+
schema,
44+
initialValue: [{}, {}],
45+
});
46+
47+
render(Content, {
48+
context: new Map([[FORM_CONTEXT, form.context]]),
49+
props: { form }
50+
})
51+
});

packages/form/src/form/context/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface FormContext {
5959
>;
6060
}
6161

62-
const FORM_CONTEXT = Symbol("form-context");
62+
export const FORM_CONTEXT = Symbol("form-context");
6363

6464
export function getFormContext(): FormContext {
6565
return getContext(FORM_CONTEXT);

packages/form/vite.config.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import { resolve } from "node:path";
33

44
import { defineConfig } from "vite";
55
import { svelte } from "@sveltejs/vite-plugin-svelte";
6+
import { svelteTesting } from "@testing-library/svelte/vite";
67

78
// https://vitejs.dev/config/
89
export default defineConfig({
9-
test: {},
10-
plugins: [svelte()],
10+
test: {
11+
environment: "jsdom",
12+
setupFiles: ['./vitest-setup.ts']
13+
},
14+
plugins: [svelte(), svelteTesting()],
1115
resolve: {
12-
conditions: process.env.VITEST
13-
? ["browser"]
14-
: ["module", "browser", "development|production"],
1516
alias: {
1617
"@": resolve(__dirname, "src"),
1718
},

packages/form/vitest-setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom/vitest'

0 commit comments

Comments
 (0)