nebula-cms 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +42 -0
- package/.github/workflows/ci.yml +31 -0
- package/.mcp.json +12 -0
- package/.prettierignore +5 -0
- package/.prettierrc.cjs +22 -0
- package/AGENTS.md +183 -0
- package/LICENSE +201 -0
- package/README.md +128 -0
- package/package.json +74 -0
- package/playground/.claude/settings.local.json +5 -0
- package/playground/astro.config.mjs +7 -0
- package/playground/node_modules/.bin/astro +21 -0
- package/playground/node_modules/.bin/rollup +21 -0
- package/playground/node_modules/.bin/tsc +21 -0
- package/playground/node_modules/.bin/tsserver +21 -0
- package/playground/node_modules/.bin/vite +21 -0
- package/playground/node_modules/.vite/_svelte_metadata.json +1 -0
- package/playground/node_modules/.vite/deps/@astrojs_svelte_client__js.js +80 -0
- package/playground/node_modules/.vite/deps/@astrojs_svelte_client__js.js.map +7 -0
- package/playground/node_modules/.vite/deps/_metadata.json +184 -0
- package/playground/node_modules/.vite/deps/astro___aria-query.js +6776 -0
- package/playground/node_modules/.vite/deps/astro___aria-query.js.map +7 -0
- package/playground/node_modules/.vite/deps/astro___axobject-query.js +3754 -0
- package/playground/node_modules/.vite/deps/astro___axobject-query.js.map +7 -0
- package/playground/node_modules/.vite/deps/astro___html-escaper.js +34 -0
- package/playground/node_modules/.vite/deps/astro___html-escaper.js.map +7 -0
- package/playground/node_modules/.vite/deps/chunk-AJXJMYAF.js +0 -0
- package/playground/node_modules/.vite/deps/chunk-AJXJMYAF.js.map +7 -0
- package/playground/node_modules/.vite/deps/chunk-ALJIOON6.js +1005 -0
- package/playground/node_modules/.vite/deps/chunk-ALJIOON6.js.map +7 -0
- package/playground/node_modules/.vite/deps/chunk-BUSYA2B4.js +8 -0
- package/playground/node_modules/.vite/deps/chunk-BUSYA2B4.js.map +7 -0
- package/playground/node_modules/.vite/deps/chunk-CNYJBM5F.js +21 -0
- package/playground/node_modules/.vite/deps/chunk-CNYJBM5F.js.map +7 -0
- package/playground/node_modules/.vite/deps/chunk-DBPNBGEI.js +223 -0
- package/playground/node_modules/.vite/deps/chunk-DBPNBGEI.js.map +7 -0
- package/playground/node_modules/.vite/deps/chunk-G3C2FXJT.js +204 -0
- package/playground/node_modules/.vite/deps/chunk-G3C2FXJT.js.map +7 -0
- package/playground/node_modules/.vite/deps/chunk-GKDKFWC5.js +27 -0
- package/playground/node_modules/.vite/deps/chunk-GKDKFWC5.js.map +7 -0
- package/playground/node_modules/.vite/deps/chunk-HNCLEOC5.js +4376 -0
- package/playground/node_modules/.vite/deps/chunk-HNCLEOC5.js.map +7 -0
- package/playground/node_modules/.vite/deps/chunk-JICYXBFU.js +688 -0
- package/playground/node_modules/.vite/deps/chunk-JICYXBFU.js.map +7 -0
- package/playground/node_modules/.vite/deps/chunk-KCUTL6DD.js +5099 -0
- package/playground/node_modules/.vite/deps/chunk-KCUTL6DD.js.map +7 -0
- package/playground/node_modules/.vite/deps/chunk-ZP4UNCSN.js +23 -0
- package/playground/node_modules/.vite/deps/chunk-ZP4UNCSN.js.map +7 -0
- package/playground/node_modules/.vite/deps/chunk-ZREFNRZZ.js +148 -0
- package/playground/node_modules/.vite/deps/chunk-ZREFNRZZ.js.map +7 -0
- package/playground/node_modules/.vite/deps/package.json +3 -0
- package/playground/node_modules/.vite/deps/smol-toml.js +843 -0
- package/playground/node_modules/.vite/deps/smol-toml.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte.js +55 -0
- package/playground/node_modules/.vite/deps/svelte.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte___clsx.js +9 -0
- package/playground/node_modules/.vite/deps/svelte___clsx.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_animate.js +57 -0
- package/playground/node_modules/.vite/deps/svelte_animate.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_attachments.js +15 -0
- package/playground/node_modules/.vite/deps/svelte_attachments.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_easing.js +67 -0
- package/playground/node_modules/.vite/deps/svelte_easing.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_events.js +11 -0
- package/playground/node_modules/.vite/deps/svelte_events.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_internal.js +5 -0
- package/playground/node_modules/.vite/deps/svelte_internal.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_internal_client.js +402 -0
- package/playground/node_modules/.vite/deps/svelte_internal_client.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_internal_disclose-version.js +10 -0
- package/playground/node_modules/.vite/deps/svelte_internal_disclose-version.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_internal_flags_async.js +8 -0
- package/playground/node_modules/.vite/deps/svelte_internal_flags_async.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_internal_flags_legacy.js +8 -0
- package/playground/node_modules/.vite/deps/svelte_internal_flags_legacy.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_internal_flags_tracing.js +8 -0
- package/playground/node_modules/.vite/deps/svelte_internal_flags_tracing.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_legacy.js +35 -0
- package/playground/node_modules/.vite/deps/svelte_legacy.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_motion.js +545 -0
- package/playground/node_modules/.vite/deps/svelte_motion.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_reactivity.js +29 -0
- package/playground/node_modules/.vite/deps/svelte_reactivity.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_reactivity_window.js +127 -0
- package/playground/node_modules/.vite/deps/svelte_reactivity_window.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_store.js +103 -0
- package/playground/node_modules/.vite/deps/svelte_store.js.map +7 -0
- package/playground/node_modules/.vite/deps/svelte_transition.js +208 -0
- package/playground/node_modules/.vite/deps/svelte_transition.js.map +7 -0
- package/playground/package.json +16 -0
- package/playground/pnpm-lock.yaml +3167 -0
- package/playground/src/content/authors/jane-doe.json +8 -0
- package/playground/src/content/config/build.toml +2 -0
- package/playground/src/content/courses/web-fundamentals.json +29 -0
- package/playground/src/content/docs/advanced.mdx +6 -0
- package/playground/src/content/docs/intro.md +6 -0
- package/playground/src/content/guides/getting-started.mdx +6 -0
- package/playground/src/content/posts/hello-world.md +7 -0
- package/playground/src/content/products/t-shirt.json +16 -0
- package/playground/src/content/recipes/pancakes.mdoc +8 -0
- package/playground/src/content/settings/site.yml +2 -0
- package/playground/src/content.config.ts +198 -0
- package/playground/src/env.d.ts +1 -0
- package/playground/src/pages/index.astro +11 -0
- package/playground/src/pages/nebula.astro +14 -0
- package/pnpm-workspace.yaml +2 -0
- package/scripts/subset-icons.mjs +178 -0
- package/src/astro/index.ts +295 -0
- package/src/client/Admin.svelte +283 -0
- package/src/client/components/BackendPicker.svelte +291 -0
- package/src/client/components/DraftChip.svelte +46 -0
- package/src/client/components/MetadataForm.svelte +56 -0
- package/src/client/components/ThemeToggle.svelte +18 -0
- package/src/client/components/dialogs/DeleteDraftDialog.svelte +51 -0
- package/src/client/components/dialogs/FilenameDialog.svelte +129 -0
- package/src/client/components/editor/EditorPane.svelte +227 -0
- package/src/client/components/editor/EditorTabs.svelte +81 -0
- package/src/client/components/editor/EditorToolbar.svelte +131 -0
- package/src/client/components/editor/FormatSelector.svelte +66 -0
- package/src/client/components/editor/Toolbar.svelte +17 -0
- package/src/client/components/fields/ArrayField.svelte +339 -0
- package/src/client/components/fields/ArrayItem.svelte +325 -0
- package/src/client/components/fields/BooleanField.svelte +114 -0
- package/src/client/components/fields/DateField.svelte +82 -0
- package/src/client/components/fields/EnumField.svelte +74 -0
- package/src/client/components/fields/FieldWrapper.svelte +96 -0
- package/src/client/components/fields/NumberField.svelte +99 -0
- package/src/client/components/fields/ObjectField.svelte +121 -0
- package/src/client/components/fields/SchemaField.svelte +107 -0
- package/src/client/components/fields/StringField.svelte +104 -0
- package/src/client/components/sidebar/AdminSidebar.svelte +339 -0
- package/src/client/components/sidebar/AdminSidebarSort.svelte +123 -0
- package/src/client/css/a11y.css +14 -0
- package/src/client/css/btn.css +113 -0
- package/src/client/css/dialog.css +29 -0
- package/src/client/css/field-input.css +39 -0
- package/src/client/css/reset.css +59 -0
- package/src/client/css/theme.css +77 -0
- package/src/client/index.ts +1 -0
- package/src/client/js/drafts/merge.svelte.ts +121 -0
- package/src/client/js/drafts/ops.svelte.ts +227 -0
- package/src/client/js/drafts/storage.ts +108 -0
- package/src/client/js/drafts/workers/diff.ts +40 -0
- package/src/client/js/editor/editor.svelte.ts +343 -0
- package/src/client/js/editor/languages.ts +98 -0
- package/src/client/js/editor/link-wrap.ts +45 -0
- package/src/client/js/editor/markdown-shortcuts.ts +261 -0
- package/src/client/js/handlers/admin.ts +246 -0
- package/src/client/js/state/dialogs.svelte.ts +35 -0
- package/src/client/js/state/router.svelte.ts +156 -0
- package/src/client/js/state/schema.svelte.ts +140 -0
- package/src/client/js/state/state.svelte.ts +334 -0
- package/src/client/js/state/theme.svelte.ts +173 -0
- package/src/client/js/storage/adapter.ts +102 -0
- package/src/client/js/storage/client.ts +150 -0
- package/src/client/js/storage/db.ts +36 -0
- package/src/client/js/storage/fsa.ts +110 -0
- package/src/client/js/storage/github.ts +297 -0
- package/src/client/js/storage/storage.ts +83 -0
- package/src/client/js/storage/workers/frontmatter.ts +320 -0
- package/src/client/js/storage/workers/storage.ts +177 -0
- package/src/client/js/storage/workers/toml-parser.ts +106 -0
- package/src/client/js/storage/workers/yaml-parser.ts +132 -0
- package/src/client/js/utils/file-types.ts +192 -0
- package/src/client/js/utils/format.ts +16 -0
- package/src/client/js/utils/frontmatter.ts +38 -0
- package/src/client/js/utils/schema-utils.ts +295 -0
- package/src/client/js/utils/slug.ts +18 -0
- package/src/client/js/utils/sort.ts +84 -0
- package/src/client/js/utils/stable-stringify.ts +27 -0
- package/src/client/js/utils/url-utils.ts +38 -0
- package/src/types.ts +25 -0
- package/src/virtual.d.ts +22 -0
- package/svelte.config.js +4 -0
- package/tests/astro/build.test.ts +63 -0
- package/tests/astro/index.test.ts +689 -0
- package/tests/client/components/Admin.test.ts +446 -0
- package/tests/client/components/BackendPicker.test.ts +239 -0
- package/tests/client/components/DraftChip.test.ts +53 -0
- package/tests/client/components/MetadataForm.test.ts +164 -0
- package/tests/client/components/dialogs/DeleteDraftDialog.test.ts +91 -0
- package/tests/client/components/dialogs/FilenameDialog.test.ts +209 -0
- package/tests/client/components/dialogs/dialog-stubs.ts +19 -0
- package/tests/client/components/editor/EditorPane.test.ts +100 -0
- package/tests/client/components/editor/EditorTabs.test.ts +253 -0
- package/tests/client/components/editor/EditorToolbar.test.ts +252 -0
- package/tests/client/components/editor/fixtures.ts +31 -0
- package/tests/client/components/fields/ArrayField.test.ts +197 -0
- package/tests/client/components/fields/BooleanField.test.ts +206 -0
- package/tests/client/components/fields/DateField.test.ts +210 -0
- package/tests/client/components/fields/EnumField.test.ts +246 -0
- package/tests/client/components/fields/NumberField.test.ts +240 -0
- package/tests/client/components/fields/ObjectField.test.ts +157 -0
- package/tests/client/components/fields/SchemaField.test.ts +190 -0
- package/tests/client/components/fields/StringField.test.ts +223 -0
- package/tests/client/components/sidebar/AdminSidebar.test.ts +285 -0
- package/tests/client/components/sidebar/AdminSidebarSort.test.ts +135 -0
- package/tests/client/components/sidebar/sort-mock.ts +23 -0
- package/tests/client/js/drafts/fixtures.ts +22 -0
- package/tests/client/js/drafts/merge.test.ts +282 -0
- package/tests/client/js/drafts/ops.test.ts +658 -0
- package/tests/client/js/drafts/storage.test.ts +200 -0
- package/tests/client/js/drafts/workers/diff.test.ts +165 -0
- package/tests/client/js/editor/editor.test.ts +616 -0
- package/tests/client/js/editor/link-wrap.test.ts +225 -0
- package/tests/client/js/editor/markdown-shortcuts.test.ts +370 -0
- package/tests/client/js/handlers/admin.test.ts +467 -0
- package/tests/client/js/state/router.test.ts +619 -0
- package/tests/client/js/state/schema.test.ts +266 -0
- package/tests/client/js/state/state.test.ts +328 -0
- package/tests/client/js/storage/adapter.test.ts +115 -0
- package/tests/client/js/storage/client.test.ts +250 -0
- package/tests/client/js/storage/db.test.ts +59 -0
- package/tests/client/js/storage/fsa.test.ts +284 -0
- package/tests/client/js/storage/github.test.ts +349 -0
- package/tests/client/js/storage/mock-port.ts +95 -0
- package/tests/client/js/storage/storage.test.ts +77 -0
- package/tests/client/js/storage/workers/frontmatter.test.ts +479 -0
- package/tests/client/js/storage/workers/storage.test.ts +299 -0
- package/tests/client/js/storage/workers/toml-parser.test.ts +169 -0
- package/tests/client/js/storage/workers/yaml-parser.test.ts +168 -0
- package/tests/client/js/utils/file-types.test.ts +268 -0
- package/tests/client/js/utils/frontmatter.test.ts +87 -0
- package/tests/client/js/utils/schema-utils.test.ts +318 -0
- package/tests/client/js/utils/slug.test.ts +58 -0
- package/tests/client/js/utils/sort.test.ts +276 -0
- package/tests/client/js/utils/stable-stringify.test.ts +68 -0
- package/tests/client/js/utils/url-utils.test.ts +70 -0
- package/tests/e2e/backend-connection.test.ts +301 -0
- package/tests/e2e/draft-lifecycle.test.ts +388 -0
- package/tests/e2e/editing.test.ts +355 -0
- package/tests/e2e/github-adapter.test.ts +330 -0
- package/tests/e2e/helpers/mock-adapter.ts +166 -0
- package/tests/e2e/helpers/test-app.ts +155 -0
- package/tests/e2e/navigation.test.ts +358 -0
- package/tests/e2e/publishing.test.ts +345 -0
- package/tests/e2e/unsaved-changes.test.ts +317 -0
- package/tests/setup.ts +2 -0
- package/tests/stubs/codemirror.ts +197 -0
- package/tsconfig.json +19 -0
- package/vitest.config.ts +178 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
|
+
import { render, cleanup, within, fireEvent } from '@testing-library/svelte';
|
|
3
|
+
import EnumField from '../../../../src/client/components/fields/EnumField.svelte';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tests for the EnumField component.
|
|
7
|
+
* Covers label derivation, options rendering, empty placeholder logic,
|
|
8
|
+
* onChange behavior, nullable handling, and read-only state.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// Prevent accumulated renders from bleeding between tests
|
|
12
|
+
afterEach(() => cleanup());
|
|
13
|
+
|
|
14
|
+
describe('EnumField', () => {
|
|
15
|
+
const options = ['draft', 'published', 'archived'];
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
//////////////////////////////
|
|
19
|
+
// Label rendering
|
|
20
|
+
//////////////////////////////
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
it('renders a label derived from the name', () => {
|
|
24
|
+
const { container } = render(EnumField, {
|
|
25
|
+
props: {
|
|
26
|
+
name: 'status',
|
|
27
|
+
schema: { type: 'string' },
|
|
28
|
+
value: 'draft',
|
|
29
|
+
options,
|
|
30
|
+
onchange: vi.fn(),
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
expect(within(container).getByText('Status')).toBeTruthy();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('renders the schema title as label when provided', () => {
|
|
38
|
+
const { container } = render(EnumField, {
|
|
39
|
+
props: {
|
|
40
|
+
name: 'status',
|
|
41
|
+
schema: { type: 'string', title: 'Publication Status' },
|
|
42
|
+
value: 'draft',
|
|
43
|
+
options,
|
|
44
|
+
onchange: vi.fn(),
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
expect(within(container).getByLabelText('Publication Status')).toBeTruthy();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('shows a required marker when required is true', () => {
|
|
52
|
+
const { container } = render(EnumField, {
|
|
53
|
+
props: {
|
|
54
|
+
name: 'status',
|
|
55
|
+
schema: { type: 'string' },
|
|
56
|
+
value: 'draft',
|
|
57
|
+
options,
|
|
58
|
+
required: true,
|
|
59
|
+
onchange: vi.fn(),
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(container.querySelector('.field-required')).not.toBeNull();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/*
|
|
67
|
+
//////////////////////////////
|
|
68
|
+
// Options rendering
|
|
69
|
+
//////////////////////////////
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
it('renders all provided options', () => {
|
|
73
|
+
const { container } = render(EnumField, {
|
|
74
|
+
props: {
|
|
75
|
+
name: 'status',
|
|
76
|
+
schema: { type: 'string' },
|
|
77
|
+
value: 'draft',
|
|
78
|
+
options,
|
|
79
|
+
onchange: vi.fn(),
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const select = container.querySelector('select')!;
|
|
84
|
+
const optionValues = Array.from(select.querySelectorAll('option')).map(
|
|
85
|
+
(o) => (o as HTMLOptionElement).value,
|
|
86
|
+
);
|
|
87
|
+
expect(optionValues).toContain('draft');
|
|
88
|
+
expect(optionValues).toContain('published');
|
|
89
|
+
expect(optionValues).toContain('archived');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('includes an empty placeholder option when not required', () => {
|
|
93
|
+
const { container } = render(EnumField, {
|
|
94
|
+
props: {
|
|
95
|
+
name: 'status',
|
|
96
|
+
schema: { type: 'string' },
|
|
97
|
+
value: 'draft',
|
|
98
|
+
options,
|
|
99
|
+
required: false,
|
|
100
|
+
onchange: vi.fn(),
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const select = container.querySelector('select')!;
|
|
105
|
+
const optionEls = Array.from(
|
|
106
|
+
select.querySelectorAll('option'),
|
|
107
|
+
) as HTMLOptionElement[];
|
|
108
|
+
expect(optionEls.some((o) => o.value === '')).toBe(true);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('includes an empty placeholder option when value is null even if required', () => {
|
|
112
|
+
const { container } = render(EnumField, {
|
|
113
|
+
props: {
|
|
114
|
+
name: 'status',
|
|
115
|
+
schema: { type: 'string' },
|
|
116
|
+
value: null,
|
|
117
|
+
options,
|
|
118
|
+
required: true,
|
|
119
|
+
onchange: vi.fn(),
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const select = container.querySelector('select')!;
|
|
124
|
+
const optionEls = Array.from(
|
|
125
|
+
select.querySelectorAll('option'),
|
|
126
|
+
) as HTMLOptionElement[];
|
|
127
|
+
expect(optionEls.some((o) => o.value === '')).toBe(true);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('omits the empty placeholder option when required and value is set', () => {
|
|
131
|
+
const { container } = render(EnumField, {
|
|
132
|
+
props: {
|
|
133
|
+
name: 'status',
|
|
134
|
+
schema: { type: 'string' },
|
|
135
|
+
value: 'draft',
|
|
136
|
+
options,
|
|
137
|
+
required: true,
|
|
138
|
+
onchange: vi.fn(),
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const select = container.querySelector('select')!;
|
|
143
|
+
const optionEls = Array.from(
|
|
144
|
+
select.querySelectorAll('option'),
|
|
145
|
+
) as HTMLOptionElement[];
|
|
146
|
+
expect(optionEls.some((o) => o.value === '')).toBe(false);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
/*
|
|
150
|
+
//////////////////////////////
|
|
151
|
+
// onChange behavior
|
|
152
|
+
//////////////////////////////
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
it('calls onchange with the selected string value', async () => {
|
|
156
|
+
const onchange = vi.fn();
|
|
157
|
+
|
|
158
|
+
const { container } = render(EnumField, {
|
|
159
|
+
props: {
|
|
160
|
+
name: 'status',
|
|
161
|
+
schema: { type: 'string' },
|
|
162
|
+
value: 'draft',
|
|
163
|
+
options,
|
|
164
|
+
onchange,
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const select = container.querySelector('select')!;
|
|
169
|
+
await fireEvent.change(select, { target: { value: 'published' } });
|
|
170
|
+
|
|
171
|
+
expect(onchange).toHaveBeenCalledWith('published');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('calls onchange with null when empty option is selected on nullable fields', async () => {
|
|
175
|
+
const onchange = vi.fn();
|
|
176
|
+
|
|
177
|
+
const { container } = render(EnumField, {
|
|
178
|
+
props: {
|
|
179
|
+
name: 'status',
|
|
180
|
+
schema: { type: 'string', _nullable: true },
|
|
181
|
+
value: 'draft',
|
|
182
|
+
options,
|
|
183
|
+
onchange,
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const select = container.querySelector('select')!;
|
|
188
|
+
await fireEvent.change(select, { target: { value: '' } });
|
|
189
|
+
|
|
190
|
+
expect(onchange).toHaveBeenCalledWith(null);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('calls onchange with empty string when empty option selected on non-nullable fields', async () => {
|
|
194
|
+
const onchange = vi.fn();
|
|
195
|
+
|
|
196
|
+
const { container } = render(EnumField, {
|
|
197
|
+
props: {
|
|
198
|
+
name: 'status',
|
|
199
|
+
schema: { type: 'string' },
|
|
200
|
+
value: 'draft',
|
|
201
|
+
options,
|
|
202
|
+
onchange,
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
const select = container.querySelector('select')!;
|
|
207
|
+
await fireEvent.change(select, { target: { value: '' } });
|
|
208
|
+
|
|
209
|
+
expect(onchange).toHaveBeenCalledWith('');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
/*
|
|
213
|
+
//////////////////////////////
|
|
214
|
+
// Deprecated / read-only
|
|
215
|
+
//////////////////////////////
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
it('applies the deprecated class when schema.deprecated is true', () => {
|
|
219
|
+
const { container } = render(EnumField, {
|
|
220
|
+
props: {
|
|
221
|
+
name: 'status',
|
|
222
|
+
schema: { type: 'string', deprecated: true },
|
|
223
|
+
value: 'draft',
|
|
224
|
+
options,
|
|
225
|
+
onchange: vi.fn(),
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
expect(container.querySelector('.field--deprecated')).not.toBeNull();
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('disables the select when schema.readOnly is true', () => {
|
|
233
|
+
const { container } = render(EnumField, {
|
|
234
|
+
props: {
|
|
235
|
+
name: 'status',
|
|
236
|
+
schema: { type: 'string', readOnly: true },
|
|
237
|
+
value: 'draft',
|
|
238
|
+
options,
|
|
239
|
+
onchange: vi.fn(),
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
const select = container.querySelector('select') as HTMLSelectElement;
|
|
244
|
+
expect(select.disabled).toBe(true);
|
|
245
|
+
});
|
|
246
|
+
});
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
|
+
import { render, cleanup, within, fireEvent } from '@testing-library/svelte';
|
|
3
|
+
import NumberField from '../../../../src/client/components/fields/NumberField.svelte';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tests for the NumberField component.
|
|
7
|
+
* Covers label derivation, input constraints, onChange behavior,
|
|
8
|
+
* nullable empty values, and constraint text rendering.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// Prevent accumulated renders from bleeding between tests
|
|
12
|
+
afterEach(() => cleanup());
|
|
13
|
+
|
|
14
|
+
describe('NumberField', () => {
|
|
15
|
+
/*
|
|
16
|
+
//////////////////////////////
|
|
17
|
+
// Label rendering
|
|
18
|
+
//////////////////////////////
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
it('renders a label derived from the name', () => {
|
|
22
|
+
const { container } = render(NumberField, {
|
|
23
|
+
props: {
|
|
24
|
+
name: 'count',
|
|
25
|
+
schema: { type: 'number' },
|
|
26
|
+
value: 0,
|
|
27
|
+
onchange: vi.fn(),
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
expect(within(container).getByText('Count')).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('renders the schema title as label when provided', () => {
|
|
35
|
+
const { container } = render(NumberField, {
|
|
36
|
+
props: {
|
|
37
|
+
name: 'count',
|
|
38
|
+
schema: { type: 'number', title: 'Item Count' },
|
|
39
|
+
value: 0,
|
|
40
|
+
onchange: vi.fn(),
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
expect(within(container).getByLabelText('Item Count')).toBeTruthy();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('shows a required marker when required is true', () => {
|
|
48
|
+
const { container } = render(NumberField, {
|
|
49
|
+
props: {
|
|
50
|
+
name: 'count',
|
|
51
|
+
schema: { type: 'number' },
|
|
52
|
+
value: 0,
|
|
53
|
+
required: true,
|
|
54
|
+
onchange: vi.fn(),
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(container.querySelector('.field-required')).not.toBeNull();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
//////////////////////////////
|
|
63
|
+
// Input rendering and value
|
|
64
|
+
//////////////////////////////
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
it('renders a number input with the provided value', () => {
|
|
68
|
+
const { container } = render(NumberField, {
|
|
69
|
+
props: {
|
|
70
|
+
name: 'count',
|
|
71
|
+
schema: { type: 'number' },
|
|
72
|
+
value: 42,
|
|
73
|
+
onchange: vi.fn(),
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Svelte 5 sets value as a DOM property, not an HTML attribute
|
|
78
|
+
const input = container.querySelector(
|
|
79
|
+
'input[type="number"]',
|
|
80
|
+
) as HTMLInputElement;
|
|
81
|
+
expect(input).not.toBeNull();
|
|
82
|
+
expect(input.value).toBe('42');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('applies min from schema.minimum', () => {
|
|
86
|
+
const { container } = render(NumberField, {
|
|
87
|
+
props: {
|
|
88
|
+
name: 'count',
|
|
89
|
+
schema: { type: 'number', minimum: 5 },
|
|
90
|
+
value: 10,
|
|
91
|
+
onchange: vi.fn(),
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const input = container.querySelector(
|
|
96
|
+
'input[type="number"]',
|
|
97
|
+
) as HTMLInputElement;
|
|
98
|
+
expect(Number(input.min)).toBe(5);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('applies max from schema.maximum', () => {
|
|
102
|
+
const { container } = render(NumberField, {
|
|
103
|
+
props: {
|
|
104
|
+
name: 'count',
|
|
105
|
+
schema: { type: 'number', maximum: 100 },
|
|
106
|
+
value: 10,
|
|
107
|
+
onchange: vi.fn(),
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const input = container.querySelector(
|
|
112
|
+
'input[type="number"]',
|
|
113
|
+
) as HTMLInputElement;
|
|
114
|
+
expect(Number(input.max)).toBe(100);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('applies step from schema.multipleOf', () => {
|
|
118
|
+
const { container } = render(NumberField, {
|
|
119
|
+
props: {
|
|
120
|
+
name: 'count',
|
|
121
|
+
schema: { type: 'number', multipleOf: 5 },
|
|
122
|
+
value: 10,
|
|
123
|
+
onchange: vi.fn(),
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const input = container.querySelector(
|
|
128
|
+
'input[type="number"]',
|
|
129
|
+
) as HTMLInputElement;
|
|
130
|
+
expect(Number(input.step)).toBe(5);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('renders constraint text in the help paragraph', () => {
|
|
134
|
+
const { container } = render(NumberField, {
|
|
135
|
+
props: {
|
|
136
|
+
name: 'count',
|
|
137
|
+
schema: { type: 'number', minimum: 0, maximum: 100 },
|
|
138
|
+
value: 10,
|
|
139
|
+
onchange: vi.fn(),
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
expect(within(container).getByText('min 0, max 100')).toBeTruthy();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
/*
|
|
147
|
+
//////////////////////////////
|
|
148
|
+
// onChange behavior
|
|
149
|
+
//////////////////////////////
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
it('calls onchange with a parsed float on input', async () => {
|
|
153
|
+
const onchange = vi.fn();
|
|
154
|
+
|
|
155
|
+
const { container } = render(NumberField, {
|
|
156
|
+
props: {
|
|
157
|
+
name: 'count',
|
|
158
|
+
schema: { type: 'number' },
|
|
159
|
+
value: 0,
|
|
160
|
+
onchange,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const input = container.querySelector('input[type="number"]')!;
|
|
165
|
+
await fireEvent.input(input, { target: { value: '3.14' } });
|
|
166
|
+
|
|
167
|
+
expect(onchange).toHaveBeenCalledWith(3.14);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('calls onchange with 0 for empty input on non-nullable fields', async () => {
|
|
171
|
+
const onchange = vi.fn();
|
|
172
|
+
|
|
173
|
+
const { container } = render(NumberField, {
|
|
174
|
+
props: {
|
|
175
|
+
name: 'count',
|
|
176
|
+
schema: { type: 'number' },
|
|
177
|
+
value: 5,
|
|
178
|
+
onchange,
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
const input = container.querySelector('input[type="number"]')!;
|
|
183
|
+
await fireEvent.input(input, { target: { value: '' } });
|
|
184
|
+
|
|
185
|
+
expect(onchange).toHaveBeenCalledWith(0);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('calls onchange with null for empty input on nullable fields', async () => {
|
|
189
|
+
const onchange = vi.fn();
|
|
190
|
+
|
|
191
|
+
const { container } = render(NumberField, {
|
|
192
|
+
props: {
|
|
193
|
+
name: 'count',
|
|
194
|
+
schema: { type: 'number', _nullable: true },
|
|
195
|
+
value: 5,
|
|
196
|
+
onchange,
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const input = container.querySelector('input[type="number"]')!;
|
|
201
|
+
await fireEvent.input(input, { target: { value: '' } });
|
|
202
|
+
|
|
203
|
+
expect(onchange).toHaveBeenCalledWith(null);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
/*
|
|
207
|
+
//////////////////////////////
|
|
208
|
+
// Deprecated / read-only
|
|
209
|
+
//////////////////////////////
|
|
210
|
+
*/
|
|
211
|
+
|
|
212
|
+
it('applies the deprecated class when schema.deprecated is true', () => {
|
|
213
|
+
const { container } = render(NumberField, {
|
|
214
|
+
props: {
|
|
215
|
+
name: 'count',
|
|
216
|
+
schema: { type: 'number', deprecated: true },
|
|
217
|
+
value: 0,
|
|
218
|
+
onchange: vi.fn(),
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
expect(container.querySelector('.field--deprecated')).not.toBeNull();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('renders the input as readonly when schema.readOnly is true', () => {
|
|
226
|
+
const { container } = render(NumberField, {
|
|
227
|
+
props: {
|
|
228
|
+
name: 'count',
|
|
229
|
+
schema: { type: 'number', readOnly: true },
|
|
230
|
+
value: 0,
|
|
231
|
+
onchange: vi.fn(),
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const input = container.querySelector(
|
|
236
|
+
'input[type="number"]',
|
|
237
|
+
) as HTMLInputElement;
|
|
238
|
+
expect(input.readOnly).toBe(true);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
|
+
import { render, cleanup, within, fireEvent } from '@testing-library/svelte';
|
|
3
|
+
import ObjectField from '../../../../src/client/components/fields/ObjectField.svelte';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tests for the ObjectField component.
|
|
7
|
+
* Covers fieldset vs. inline rendering, child field display,
|
|
8
|
+
* and change propagation for individual properties.
|
|
9
|
+
*
|
|
10
|
+
* Child field labels include an aria-hidden required marker (*) which causes
|
|
11
|
+
* getByLabelText exact-text matching to fail. We query inputs via their `id`
|
|
12
|
+
* attribute (which matches the schema property key) instead.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// Prevent accumulated renders from bleeding between tests
|
|
16
|
+
afterEach(() => cleanup());
|
|
17
|
+
|
|
18
|
+
describe('ObjectField', () => {
|
|
19
|
+
const schema = {
|
|
20
|
+
type: 'object',
|
|
21
|
+
title: 'Address',
|
|
22
|
+
properties: {
|
|
23
|
+
street: { type: 'string', title: 'Street' },
|
|
24
|
+
city: { type: 'string', title: 'City' },
|
|
25
|
+
},
|
|
26
|
+
required: ['street'],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
//////////////////////////////
|
|
31
|
+
// Fieldset rendering (default)
|
|
32
|
+
//////////////////////////////
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
it('renders a fieldset with a legend derived from the schema title', () => {
|
|
36
|
+
const { container } = render(ObjectField, {
|
|
37
|
+
props: {
|
|
38
|
+
name: 'address',
|
|
39
|
+
schema,
|
|
40
|
+
value: { street: '123 Main St', city: 'Springfield' },
|
|
41
|
+
onchange: vi.fn(),
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
expect(container.querySelector('fieldset.object-field')).not.toBeNull();
|
|
46
|
+
expect(within(container).getByText('Address')).toBeTruthy();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('shows a required marker on the legend when required is true', () => {
|
|
50
|
+
const { container } = render(ObjectField, {
|
|
51
|
+
props: {
|
|
52
|
+
name: 'address',
|
|
53
|
+
schema,
|
|
54
|
+
value: {},
|
|
55
|
+
required: true,
|
|
56
|
+
onchange: vi.fn(),
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(container.querySelector('.object-field__required')).not.toBeNull();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('renders child fields for each schema property', () => {
|
|
64
|
+
const { container } = render(ObjectField, {
|
|
65
|
+
props: {
|
|
66
|
+
name: 'address',
|
|
67
|
+
schema,
|
|
68
|
+
value: { street: '123 Main St', city: 'Springfield' },
|
|
69
|
+
onchange: vi.fn(),
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Query by `id` which is set to the property key by SchemaField -> StringField
|
|
74
|
+
expect(container.querySelector('#street')).not.toBeNull();
|
|
75
|
+
expect(container.querySelector('#city')).not.toBeNull();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('populates child fields with the corresponding values', () => {
|
|
79
|
+
const { container } = render(ObjectField, {
|
|
80
|
+
props: {
|
|
81
|
+
name: 'address',
|
|
82
|
+
schema,
|
|
83
|
+
value: { street: '123 Main St', city: 'Springfield' },
|
|
84
|
+
onchange: vi.fn(),
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Svelte 5 sets value as a DOM property, not an HTML attribute
|
|
89
|
+
const streetInput = container.querySelector('#street') as HTMLInputElement;
|
|
90
|
+
const cityInput = container.querySelector('#city') as HTMLInputElement;
|
|
91
|
+
expect(streetInput.value).toBe('123 Main St');
|
|
92
|
+
expect(cityInput.value).toBe('Springfield');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
/*
|
|
96
|
+
//////////////////////////////
|
|
97
|
+
// Inline rendering
|
|
98
|
+
//////////////////////////////
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
it('renders without a fieldset when inline is true', () => {
|
|
102
|
+
const { container } = render(ObjectField, {
|
|
103
|
+
props: {
|
|
104
|
+
name: 'address',
|
|
105
|
+
schema,
|
|
106
|
+
value: { street: '1 Road', city: 'Town' },
|
|
107
|
+
onchange: vi.fn(),
|
|
108
|
+
inline: true,
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
expect(container.querySelector('fieldset')).toBeNull();
|
|
113
|
+
expect(container.querySelector('.object-field--inline')).not.toBeNull();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
/*
|
|
117
|
+
//////////////////////////////
|
|
118
|
+
// onChange behavior
|
|
119
|
+
//////////////////////////////
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
it('calls onchange with the full updated object when a child field changes', async () => {
|
|
123
|
+
const onchange = vi.fn();
|
|
124
|
+
|
|
125
|
+
const { container } = render(ObjectField, {
|
|
126
|
+
props: {
|
|
127
|
+
name: 'address',
|
|
128
|
+
schema,
|
|
129
|
+
value: { street: '123 Main St', city: 'Springfield' },
|
|
130
|
+
onchange,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const streetInput = container.querySelector('#street')!;
|
|
135
|
+
await fireEvent.input(streetInput, { target: { value: '456 Oak Ave' } });
|
|
136
|
+
|
|
137
|
+
expect(onchange).toHaveBeenCalledWith({
|
|
138
|
+
street: '456 Oak Ave',
|
|
139
|
+
city: 'Springfield',
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('defaults to an empty object when value is null', () => {
|
|
144
|
+
const { container } = render(ObjectField, {
|
|
145
|
+
props: {
|
|
146
|
+
name: 'address',
|
|
147
|
+
schema,
|
|
148
|
+
value: null,
|
|
149
|
+
onchange: vi.fn(),
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Inputs should render with empty values when value defaults to {}
|
|
154
|
+
const streetInput = container.querySelector('#street') as HTMLInputElement;
|
|
155
|
+
expect(streetInput.value).toBe('');
|
|
156
|
+
});
|
|
157
|
+
});
|