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,53 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import { render, cleanup } from '@testing-library/svelte';
|
|
3
|
+
import DraftChip from '../../../src/client/components/DraftChip.svelte';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tests for the DraftChip component.
|
|
7
|
+
* Verifies that the correct text and CSS modifier classes are applied for each variant.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Explicit cleanup after each test prevents accumulated renders from bleeding
|
|
11
|
+
// into subsequent assertions when using container-scoped queries.
|
|
12
|
+
afterEach(() => cleanup());
|
|
13
|
+
|
|
14
|
+
describe('DraftChip', () => {
|
|
15
|
+
/*
|
|
16
|
+
//////////////////////////////
|
|
17
|
+
// draft variant
|
|
18
|
+
//////////////////////////////
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
it('renders "draft" text with chip--draft class when variant is draft', () => {
|
|
22
|
+
const { container } = render(DraftChip, { props: { variant: 'draft' } });
|
|
23
|
+
const chip = container.querySelector('.chip');
|
|
24
|
+
|
|
25
|
+
expect(chip).not.toBeNull();
|
|
26
|
+
expect(chip!.textContent?.trim()).toBe('draft');
|
|
27
|
+
expect(chip!.classList.contains('chip--draft')).toBe(true);
|
|
28
|
+
expect(chip!.classList.contains('chip--outdated')).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
//////////////////////////////
|
|
33
|
+
// outdated variant
|
|
34
|
+
//////////////////////////////
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
it('renders "outdated" text with chip--outdated class when variant is outdated', () => {
|
|
38
|
+
const { container } = render(DraftChip, { props: { variant: 'outdated' } });
|
|
39
|
+
const chip = container.querySelector('.chip');
|
|
40
|
+
|
|
41
|
+
expect(chip).not.toBeNull();
|
|
42
|
+
expect(chip!.textContent?.trim()).toBe('outdated');
|
|
43
|
+
expect(chip!.classList.contains('chip--outdated')).toBe(true);
|
|
44
|
+
expect(chip!.classList.contains('chip--draft')).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('renders a span element', () => {
|
|
48
|
+
const { container } = render(DraftChip, { props: { variant: 'draft' } });
|
|
49
|
+
const chip = container.querySelector('span.chip');
|
|
50
|
+
|
|
51
|
+
expect(chip).not.toBeNull();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
|
+
import { render, cleanup } from '@testing-library/svelte';
|
|
3
|
+
import MetadataForm from '../../../src/client/components/MetadataForm.svelte';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tests for the MetadataForm component.
|
|
7
|
+
* Mocks schema-utils and editor.svelte to control field lists without
|
|
8
|
+
* triggering Svelte 5 rune initialization in jsdom.
|
|
9
|
+
*
|
|
10
|
+
* MetadataForm delegates the actual field rendering to SchemaField, which in
|
|
11
|
+
* turn renders leaf input components. These tests verify that the correct
|
|
12
|
+
* fields are surfaced based on the active tab and schema structure.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// vi.hoisted ensures these declarations are available when vi.mock factories run,
|
|
16
|
+
// since vi.mock calls are hoisted to the top of the file by Vitest.
|
|
17
|
+
const { mockGetFieldsForTab, mockFormData } = vi.hoisted(() => ({
|
|
18
|
+
mockGetFieldsForTab: vi.fn(() => [] as string[]),
|
|
19
|
+
mockFormData: vi.fn(() => ({}) as Record<string, unknown>),
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
vi.mock('../../../src/client/js/utils/schema-utils', () => ({
|
|
23
|
+
getFieldsForTab: mockGetFieldsForTab,
|
|
24
|
+
resolveFieldType: vi.fn((schema: Record<string, unknown>) => {
|
|
25
|
+
if (schema['type'] === 'string') return { kind: 'string' };
|
|
26
|
+
if (schema['type'] === 'boolean') return { kind: 'boolean' };
|
|
27
|
+
if (schema['type'] === 'number') return { kind: 'number' };
|
|
28
|
+
return { kind: 'unknown' };
|
|
29
|
+
}),
|
|
30
|
+
createDefaultValue: vi.fn(() => ''),
|
|
31
|
+
getByPath: vi.fn(),
|
|
32
|
+
setByPath: vi.fn(),
|
|
33
|
+
getProperties: vi.fn(
|
|
34
|
+
(schema: Record<string, unknown>) =>
|
|
35
|
+
schema['properties'] as Record<string, unknown> | undefined,
|
|
36
|
+
),
|
|
37
|
+
getRequiredFields: vi.fn((schema: Record<string, unknown>) =>
|
|
38
|
+
Array.isArray(schema['required']) ? schema['required'] : [],
|
|
39
|
+
),
|
|
40
|
+
isReadOnly: vi.fn(() => false),
|
|
41
|
+
isNullable: vi.fn(() => false),
|
|
42
|
+
getLabel: vi.fn((schema: Record<string, unknown>, name: string) =>
|
|
43
|
+
typeof schema['title'] === 'string' ? schema['title'] : name,
|
|
44
|
+
),
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
vi.mock('../../../src/client/js/editor/editor.svelte', () => ({
|
|
48
|
+
editor: {
|
|
49
|
+
get data() {
|
|
50
|
+
return mockFormData();
|
|
51
|
+
},
|
|
52
|
+
get tab() {
|
|
53
|
+
return 'metadata';
|
|
54
|
+
},
|
|
55
|
+
get originalFilename() {
|
|
56
|
+
return '';
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
updateFormField: vi.fn(),
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
// Prevent accumulated renders from bleeding between tests
|
|
63
|
+
afterEach(() => cleanup());
|
|
64
|
+
|
|
65
|
+
/** Builds a minimal schema with string and boolean fields. */
|
|
66
|
+
const sampleSchema = {
|
|
67
|
+
type: 'object',
|
|
68
|
+
properties: {
|
|
69
|
+
title: { type: 'string', title: 'Title' },
|
|
70
|
+
description: { type: 'string', title: 'Description' },
|
|
71
|
+
published: { type: 'boolean', title: 'Published' },
|
|
72
|
+
},
|
|
73
|
+
required: ['title'],
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
describe('MetadataForm', () => {
|
|
77
|
+
/*
|
|
78
|
+
//////////////////////////////
|
|
79
|
+
// Field rendering
|
|
80
|
+
//////////////////////////////
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
it('renders a field for each property returned by getFieldsForTab', () => {
|
|
84
|
+
mockGetFieldsForTab.mockReturnValue(['title', 'description']);
|
|
85
|
+
mockFormData.mockReturnValue({ title: 'Hello', description: 'World' });
|
|
86
|
+
|
|
87
|
+
const { container } = render(MetadataForm, {
|
|
88
|
+
props: { schema: sampleSchema },
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// SchemaField renders a label element for each field
|
|
92
|
+
const labels = container.querySelectorAll('label');
|
|
93
|
+
expect(labels.length).toBeGreaterThanOrEqual(2);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('renders an empty form when getFieldsForTab returns no fields', () => {
|
|
97
|
+
mockGetFieldsForTab.mockReturnValue([]);
|
|
98
|
+
mockFormData.mockReturnValue({});
|
|
99
|
+
|
|
100
|
+
const { container } = render(MetadataForm, {
|
|
101
|
+
props: { schema: sampleSchema },
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const form = container.querySelector('.metadata-form');
|
|
105
|
+
expect(form).not.toBeNull();
|
|
106
|
+
// No fields rendered
|
|
107
|
+
const inputs = container.querySelectorAll('input');
|
|
108
|
+
expect(inputs.length).toBe(0);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('renders only fields for the active tab', () => {
|
|
112
|
+
// Only the title field is in the seo tab
|
|
113
|
+
mockGetFieldsForTab.mockImplementation(
|
|
114
|
+
(_schema: unknown, tab: string | null) =>
|
|
115
|
+
tab === 'seo' ? ['title'] : ['title', 'description'],
|
|
116
|
+
);
|
|
117
|
+
mockFormData.mockReturnValue({ title: '', description: '' });
|
|
118
|
+
|
|
119
|
+
const { container } = render(MetadataForm, {
|
|
120
|
+
props: { schema: sampleSchema, tab: 'seo' },
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Only "title" (string) is rendered for the seo tab
|
|
124
|
+
const inputs = container.querySelectorAll('input[type="text"]');
|
|
125
|
+
expect(inputs.length).toBe(1);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
/*
|
|
129
|
+
//////////////////////////////
|
|
130
|
+
// Container structure
|
|
131
|
+
//////////////////////////////
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
it('renders the metadata-form wrapper element', () => {
|
|
135
|
+
mockGetFieldsForTab.mockReturnValue([]);
|
|
136
|
+
mockFormData.mockReturnValue({});
|
|
137
|
+
|
|
138
|
+
const { container } = render(MetadataForm, {
|
|
139
|
+
props: { schema: sampleSchema },
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
expect(container.querySelector('.metadata-form')).not.toBeNull();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
/*
|
|
146
|
+
//////////////////////////////
|
|
147
|
+
// Required field passthrough
|
|
148
|
+
//////////////////////////////
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
it('passes required fields down to SchemaField', () => {
|
|
152
|
+
mockGetFieldsForTab.mockReturnValue(['title']);
|
|
153
|
+
mockFormData.mockReturnValue({ title: '' });
|
|
154
|
+
|
|
155
|
+
const { container } = render(MetadataForm, {
|
|
156
|
+
props: { schema: sampleSchema },
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// StringField renders a .field-required span (the * marker) for required fields
|
|
160
|
+
// rather than adding the `required` attribute to the input element
|
|
161
|
+
const requiredMarker = container.querySelector('.field-required');
|
|
162
|
+
expect(requiredMarker).not.toBeNull();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { render, cleanup } from '@testing-library/svelte';
|
|
3
|
+
import DeleteDraftDialog from '../../../../src/client/components/dialogs/DeleteDraftDialog.svelte';
|
|
4
|
+
import { stubDialogMethods } from './dialog-stubs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Tests for the DeleteDraftDialog component.
|
|
8
|
+
* The component uses a native <dialog> element with showModal() — jsdom does not
|
|
9
|
+
* implement showModal(), so it is stubbed on HTMLDialogElement.prototype before each test.
|
|
10
|
+
*
|
|
11
|
+
* jsdom treats <dialog> as hidden from the accessibility tree when the `open` attribute
|
|
12
|
+
* is absent. Since our showModal stub doesn't set `open`, we query buttons via
|
|
13
|
+
* container.querySelector instead of getByRole to avoid hidden-element failures.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// Prevent accumulated renders from bleeding between tests
|
|
17
|
+
afterEach(() => cleanup());
|
|
18
|
+
|
|
19
|
+
describe('DeleteDraftDialog', () => {
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
stubDialogMethods();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('renders the dialog with title and message', () => {
|
|
25
|
+
const { container } = render(DeleteDraftDialog, {
|
|
26
|
+
props: { onConfirm: vi.fn(), onCancel: vi.fn() },
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
expect(container.querySelector('.dialog__title')?.textContent?.trim()).toBe(
|
|
30
|
+
'Delete Draft?',
|
|
31
|
+
);
|
|
32
|
+
expect(
|
|
33
|
+
container.querySelector('.dialog__message')?.textContent?.trim(),
|
|
34
|
+
).toBe('This cannot be undone.');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('renders Cancel and Delete buttons', () => {
|
|
38
|
+
const { container } = render(DeleteDraftDialog, {
|
|
39
|
+
props: { onConfirm: vi.fn(), onCancel: vi.fn() },
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const buttons = container.querySelectorAll('button');
|
|
43
|
+
const labels = Array.from(buttons).map((b) => b.textContent?.trim());
|
|
44
|
+
expect(labels).toContain('Cancel');
|
|
45
|
+
expect(labels).toContain('Delete');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('calls onConfirm when the Delete button is clicked', async () => {
|
|
49
|
+
const { fireEvent } = await import('@testing-library/svelte');
|
|
50
|
+
const onConfirm = vi.fn();
|
|
51
|
+
const onCancel = vi.fn();
|
|
52
|
+
|
|
53
|
+
const { container } = render(DeleteDraftDialog, {
|
|
54
|
+
props: { onConfirm, onCancel },
|
|
55
|
+
});
|
|
56
|
+
const deleteBtn = Array.from(container.querySelectorAll('button')).find(
|
|
57
|
+
(b) => b.textContent?.trim() === 'Delete',
|
|
58
|
+
)!;
|
|
59
|
+
|
|
60
|
+
await fireEvent.click(deleteBtn);
|
|
61
|
+
|
|
62
|
+
expect(onConfirm).toHaveBeenCalledOnce();
|
|
63
|
+
expect(onCancel).not.toHaveBeenCalled();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('calls onCancel when the Cancel button is clicked', async () => {
|
|
67
|
+
const { fireEvent } = await import('@testing-library/svelte');
|
|
68
|
+
const onConfirm = vi.fn();
|
|
69
|
+
const onCancel = vi.fn();
|
|
70
|
+
|
|
71
|
+
const { container } = render(DeleteDraftDialog, {
|
|
72
|
+
props: { onConfirm, onCancel },
|
|
73
|
+
});
|
|
74
|
+
const cancelBtn = Array.from(container.querySelectorAll('button')).find(
|
|
75
|
+
(b) => b.textContent?.trim() === 'Cancel',
|
|
76
|
+
)!;
|
|
77
|
+
|
|
78
|
+
await fireEvent.click(cancelBtn);
|
|
79
|
+
|
|
80
|
+
expect(onCancel).toHaveBeenCalledOnce();
|
|
81
|
+
expect(onConfirm).not.toHaveBeenCalled();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('calls showModal on the dialog element on mount', () => {
|
|
85
|
+
render(DeleteDraftDialog, {
|
|
86
|
+
props: { onConfirm: vi.fn(), onCancel: vi.fn() },
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
expect(HTMLDialogElement.prototype.showModal).toHaveBeenCalled();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { render, cleanup, fireEvent } from '@testing-library/svelte';
|
|
3
|
+
import FilenameDialog from '../../../../src/client/components/dialogs/FilenameDialog.svelte';
|
|
4
|
+
import { stubDialogMethods } from './dialog-stubs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Tests for the FilenameDialog component.
|
|
8
|
+
* Mocks slugify so tests are not sensitive to the slug implementation.
|
|
9
|
+
* The component uses a native <dialog> element — showModal/close are stubbed before each test.
|
|
10
|
+
*
|
|
11
|
+
* jsdom treats <dialog> as hidden from the accessibility tree when `open` is absent.
|
|
12
|
+
* Since our showModal stub does not set `open`, buttons are queried via
|
|
13
|
+
* container.querySelector instead of getByRole to avoid hidden-element failures.
|
|
14
|
+
*/
|
|
15
|
+
vi.mock('../../../../src/client/js/utils/slug', () => ({
|
|
16
|
+
slugify: vi.fn((s: string) => s.toLowerCase().replace(/\s+/g, '-')),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
// Prevent accumulated renders from bleeding between tests
|
|
20
|
+
afterEach(() => cleanup());
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Finds the first button in a container whose trimmed text matches the given label.
|
|
24
|
+
* @param {HTMLElement} container - The DOM container to search within
|
|
25
|
+
* @param {string} label - The button text to match
|
|
26
|
+
* @return {HTMLButtonElement | null} The matching button, or null if not found
|
|
27
|
+
*/
|
|
28
|
+
function getButton(
|
|
29
|
+
container: HTMLElement,
|
|
30
|
+
label: string,
|
|
31
|
+
): HTMLButtonElement | null {
|
|
32
|
+
return (
|
|
33
|
+
(Array.from(container.querySelectorAll('button')).find(
|
|
34
|
+
(b) => b.textContent?.trim() === label,
|
|
35
|
+
) as HTMLButtonElement | undefined) ?? null
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('FilenameDialog', () => {
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
stubDialogMethods();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('renders with the slug pre-filled from the title prop', () => {
|
|
45
|
+
const { container } = render(FilenameDialog, {
|
|
46
|
+
props: {
|
|
47
|
+
title: 'My Post',
|
|
48
|
+
existingFilenames: [],
|
|
49
|
+
onConfirm: vi.fn(),
|
|
50
|
+
onCancel: vi.fn(),
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const input = container.querySelector(
|
|
55
|
+
'input[type="text"]',
|
|
56
|
+
) as HTMLInputElement;
|
|
57
|
+
expect(input).not.toBeNull();
|
|
58
|
+
// slugify mock lowercases and replaces spaces with hyphens
|
|
59
|
+
expect(input.value).toBe('my-post');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('renders the .md extension label', () => {
|
|
63
|
+
const { container } = render(FilenameDialog, {
|
|
64
|
+
props: {
|
|
65
|
+
title: 'Hello',
|
|
66
|
+
existingFilenames: [],
|
|
67
|
+
onConfirm: vi.fn(),
|
|
68
|
+
onCancel: vi.fn(),
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
expect(container.querySelector('.extension')?.textContent?.trim()).toBe(
|
|
73
|
+
'.md',
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('shows an error when the filename matches an existing one', () => {
|
|
78
|
+
const { container } = render(FilenameDialog, {
|
|
79
|
+
props: {
|
|
80
|
+
title: 'hello',
|
|
81
|
+
existingFilenames: ['hello.md'],
|
|
82
|
+
onConfirm: vi.fn(),
|
|
83
|
+
onCancel: vi.fn(),
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// The slug mock produces "hello" from "hello", so hello.md is a duplicate
|
|
88
|
+
expect(container.querySelector('.error')?.textContent?.trim()).toBe(
|
|
89
|
+
'A file with this name already exists',
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('shows an error when the slug is empty', () => {
|
|
94
|
+
const { container } = render(FilenameDialog, {
|
|
95
|
+
props: {
|
|
96
|
+
title: '',
|
|
97
|
+
existingFilenames: [],
|
|
98
|
+
onConfirm: vi.fn(),
|
|
99
|
+
onCancel: vi.fn(),
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
expect(container.querySelector('.error')?.textContent?.trim()).toBe(
|
|
104
|
+
'Filename cannot be empty',
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('disables the Confirm button when there is a validation error', () => {
|
|
109
|
+
const { container } = render(FilenameDialog, {
|
|
110
|
+
props: {
|
|
111
|
+
title: 'hello',
|
|
112
|
+
existingFilenames: ['hello.md'],
|
|
113
|
+
onConfirm: vi.fn(),
|
|
114
|
+
onCancel: vi.fn(),
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const confirmBtn = getButton(container, 'Confirm');
|
|
119
|
+
expect(confirmBtn?.disabled).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('enables the Confirm button when the filename is valid', () => {
|
|
123
|
+
const { container } = render(FilenameDialog, {
|
|
124
|
+
props: {
|
|
125
|
+
title: 'New Post',
|
|
126
|
+
existingFilenames: [],
|
|
127
|
+
onConfirm: vi.fn(),
|
|
128
|
+
onCancel: vi.fn(),
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const confirmBtn = getButton(container, 'Confirm');
|
|
133
|
+
expect(confirmBtn?.disabled).toBe(false);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('calls onConfirm with the full filename when Confirm is clicked', async () => {
|
|
137
|
+
const onConfirm = vi.fn();
|
|
138
|
+
|
|
139
|
+
const { container } = render(FilenameDialog, {
|
|
140
|
+
props: {
|
|
141
|
+
title: 'My Post',
|
|
142
|
+
existingFilenames: [],
|
|
143
|
+
onConfirm,
|
|
144
|
+
onCancel: vi.fn(),
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
await fireEvent.click(getButton(container, 'Confirm')!);
|
|
149
|
+
|
|
150
|
+
expect(onConfirm).toHaveBeenCalledWith('my-post.md');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('calls onCancel when the Cancel button is clicked', async () => {
|
|
154
|
+
const onCancel = vi.fn();
|
|
155
|
+
|
|
156
|
+
const { container } = render(FilenameDialog, {
|
|
157
|
+
props: {
|
|
158
|
+
title: 'My Post',
|
|
159
|
+
existingFilenames: [],
|
|
160
|
+
onConfirm: vi.fn(),
|
|
161
|
+
onCancel,
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
await fireEvent.click(getButton(container, 'Cancel')!);
|
|
166
|
+
|
|
167
|
+
expect(onCancel).toHaveBeenCalledOnce();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('does not call onConfirm when there is a validation error', async () => {
|
|
171
|
+
const onConfirm = vi.fn();
|
|
172
|
+
|
|
173
|
+
const { container } = render(FilenameDialog, {
|
|
174
|
+
props: {
|
|
175
|
+
title: 'hello',
|
|
176
|
+
existingFilenames: ['hello.md'],
|
|
177
|
+
onConfirm,
|
|
178
|
+
onCancel: vi.fn(),
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
await fireEvent.click(getButton(container, 'Confirm')!);
|
|
183
|
+
|
|
184
|
+
expect(onConfirm).not.toHaveBeenCalled();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('updates the slug when the input changes and calls onConfirm with the new value', async () => {
|
|
188
|
+
const onConfirm = vi.fn();
|
|
189
|
+
|
|
190
|
+
const { container } = render(FilenameDialog, {
|
|
191
|
+
props: {
|
|
192
|
+
title: 'My Post',
|
|
193
|
+
existingFilenames: [],
|
|
194
|
+
onConfirm,
|
|
195
|
+
onCancel: vi.fn(),
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const input = container.querySelector(
|
|
200
|
+
'input[type="text"]',
|
|
201
|
+
) as HTMLInputElement;
|
|
202
|
+
|
|
203
|
+
// Fire input event to update the bound slug value via Svelte's bind:value handler
|
|
204
|
+
await fireEvent.input(input, { target: { value: 'custom-slug' } });
|
|
205
|
+
await fireEvent.click(getButton(container, 'Confirm')!);
|
|
206
|
+
|
|
207
|
+
expect(onConfirm).toHaveBeenCalledWith('custom-slug.md');
|
|
208
|
+
});
|
|
209
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* Shared dialog test stubs for component tests.
|
|
2
|
+
*
|
|
3
|
+
* jsdom does not implement showModal() or close() on HTMLDialogElement.
|
|
4
|
+
* Components that render <dialog> elements need these methods stubbed
|
|
5
|
+
* before rendering. Call stubDialogMethods() in a beforeEach block.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { vi } from 'vitest';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Stubs showModal and close on HTMLDialogElement.prototype so that
|
|
12
|
+
* Svelte components using native <dialog> elements can mount without
|
|
13
|
+
* throwing in jsdom.
|
|
14
|
+
* @return {void}
|
|
15
|
+
*/
|
|
16
|
+
export function stubDialogMethods(): void {
|
|
17
|
+
HTMLDialogElement.prototype.showModal = vi.fn();
|
|
18
|
+
HTMLDialogElement.prototype.close = vi.fn();
|
|
19
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
|
+
import { render, cleanup } from '@testing-library/svelte';
|
|
3
|
+
import EditorPane from '../../../../src/client/components/editor/EditorPane.svelte';
|
|
4
|
+
import { makeEditorFile } from './fixtures';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Tests for the EditorPane component.
|
|
8
|
+
* Full editing behaviour (CodeMirror interactions, live text changes) is deferred to E2E tests.
|
|
9
|
+
* These tests verify that the component mounts and unmounts without error under
|
|
10
|
+
* common file states, and that the expected container elements are present in the DOM.
|
|
11
|
+
*
|
|
12
|
+
* @codemirror/* and @lezer/* imports are redirected to tests/stubs/codemirror.ts
|
|
13
|
+
* via the resolve.alias setting in vitest.config.ts (components project), so no
|
|
14
|
+
* explicit vi.mock calls are needed for those packages.
|
|
15
|
+
*
|
|
16
|
+
* editor.svelte is mocked to avoid Svelte 5 rune initialization in jsdom.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// vi.hoisted ensures these declarations are available when vi.mock factories run.
|
|
20
|
+
const { mockGetEditorFile } = vi.hoisted(() => ({
|
|
21
|
+
mockGetEditorFile: vi.fn(() => null),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
vi.mock('../../../../src/client/js/editor/editor.svelte', () => ({
|
|
25
|
+
getEditorFile: mockGetEditorFile,
|
|
26
|
+
updateBody: vi.fn(),
|
|
27
|
+
changeFileFormat: vi.fn(),
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
// FormatSelector imports schema.svelte which depends on virtual:collections
|
|
31
|
+
vi.mock('../../../../src/client/js/state/schema.svelte', () => ({
|
|
32
|
+
schema: { active: null },
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
// Prevent accumulated renders from bleeding between tests
|
|
36
|
+
afterEach(() => cleanup());
|
|
37
|
+
|
|
38
|
+
describe('EditorPane', () => {
|
|
39
|
+
/*
|
|
40
|
+
//////////////////////////////
|
|
41
|
+
// DOM structure
|
|
42
|
+
//////////////////////////////
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
it('renders the outer wrapper element', () => {
|
|
46
|
+
mockGetEditorFile.mockReturnValue(null);
|
|
47
|
+
|
|
48
|
+
const { container } = render(EditorPane, { props: {} });
|
|
49
|
+
expect(container.querySelector('.editor-wrapper')).not.toBeNull();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('renders the editor box element', () => {
|
|
53
|
+
mockGetEditorFile.mockReturnValue(null);
|
|
54
|
+
|
|
55
|
+
const { container } = render(EditorPane, { props: {} });
|
|
56
|
+
expect(container.querySelector('.editor-box')).not.toBeNull();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('renders the editor pane container element', () => {
|
|
60
|
+
mockGetEditorFile.mockReturnValue(null);
|
|
61
|
+
|
|
62
|
+
const { container } = render(EditorPane, { props: {} });
|
|
63
|
+
expect(container.querySelector('.editor-pane')).not.toBeNull();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/*
|
|
67
|
+
//////////////////////////////
|
|
68
|
+
// Mount/unmount without error
|
|
69
|
+
//////////////////////////////
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
it('mounts without error when no file is open', () => {
|
|
73
|
+
mockGetEditorFile.mockReturnValue(null);
|
|
74
|
+
|
|
75
|
+
expect(() => render(EditorPane, { props: {} })).not.toThrow();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('mounts without error when a file with body is open', () => {
|
|
79
|
+
mockGetEditorFile.mockReturnValue(
|
|
80
|
+
makeEditorFile({ body: '# Hello', filename: 'post.md' }),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
expect(() => render(EditorPane, { props: {} })).not.toThrow();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('mounts without error when body is not yet loaded', () => {
|
|
87
|
+
mockGetEditorFile.mockReturnValue(
|
|
88
|
+
makeEditorFile({ bodyLoaded: false, filename: 'post.md' }),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
expect(() => render(EditorPane, { props: {} })).not.toThrow();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('unmounts without error', () => {
|
|
95
|
+
mockGetEditorFile.mockReturnValue(null);
|
|
96
|
+
|
|
97
|
+
const { unmount } = render(EditorPane, { props: {} });
|
|
98
|
+
expect(() => unmount()).not.toThrow();
|
|
99
|
+
});
|
|
100
|
+
});
|