From 9ff091bd39042bf6f12dce1f907c3d9cac0db08a Mon Sep 17 00:00:00 2001 From: b12f Date: Wed, 9 Oct 2024 15:38:26 +0200 Subject: [PATCH] test: fix @schlechtenburg core tests --- package-lock.json | 37 ++++++++++++++++--- package.json | 2 +- packages/heading/__tests__/heading.test.ts | 17 +++++++-- packages/image/__tests__/image.test.ts | 17 +++++++-- packages/layout/__tests__/layout.test.ts | 17 +++++++-- .../paragraph/__tests__/paragraph.test.ts | 13 ++++--- packages/rich-text/package.json | 1 - packages/standalone/__tests__/core.test.ts | 7 ---- .../standalone/__tests__/standalone.test.ts | 17 +++++++++ packages/standalone/lib/index.ts | 1 + vitest.config.ts | 3 +- 11 files changed, 98 insertions(+), 34 deletions(-) delete mode 100644 packages/standalone/__tests__/core.test.ts create mode 100644 packages/standalone/__tests__/standalone.test.ts diff --git a/package-lock.json b/package-lock.json index 7714468..e57883f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "packages/image", "packages/paragraph", "packages/layout", - "packages/standalone" + "packages/rich-text" ], "dependencies": { "lodash-es": "^4.17.21" @@ -751,7 +751,6 @@ "version": "7.25.7", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.25.7.tgz", "integrity": "sha512-FjoyLe754PMiYsFaN5C94ttGiOmBNYTf6pLr4xXHAT5uctHb092PBszndLDR5XA/jghQvn4n7JMHl7dmTgbm9w==", - "dev": true, "dependencies": { "regenerator-runtime": "^0.14.0" }, @@ -2995,8 +2994,8 @@ "resolved": "packages/paragraph", "link": true }, - "node_modules/@schlechtenburg/standalone": { - "resolved": "packages/standalone", + "node_modules/@schlechtenburg/rich-text": { + "resolved": "packages/rich-text", "link": true }, "node_modules/@sentry/core": { @@ -4579,6 +4578,19 @@ } } }, + "node_modules/@wordpress/escape-html": { + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/@wordpress/escape-html/-/escape-html-3.9.0.tgz", + "integrity": "sha512-+/SnVUXzzr+0pgfAqK3pocGveSDS3SHrgJ1BTgV7DA1l6y9mbjnqKgFQkNW/nzca92ZuYg2vjLcq1dqDGz4v1Q==", + "license": "GPL-2.0-or-later", + "dependencies": { + "@babel/runtime": "^7.16.0" + }, + "engines": { + "node": ">=18.12.0", + "npm": ">=8.19.2" + } + }, "node_modules/@yarnpkg/lockfile": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz", @@ -11619,8 +11631,7 @@ "node_modules/regenerator-runtime": { "version": "0.14.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", - "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", - "dev": true + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==" }, "node_modules/regex": { "version": "4.3.2", @@ -13919,9 +13930,23 @@ "vue": "^3.2.31" } }, + "packages/rich-text": { + "name": "@schlechtenburg/rich-text", + "version": "0.0.0", + "license": "GPL-3.0-or-later", + "dependencies": { + "@wordpress/escape-html": "^3.9.0" + }, + "devDependencies": { + "@vuedx/typecheck": "^0.6.3", + "@vuedx/typescript-plugin-vue": "^0.6.3", + "vue": "^3.2.31" + } + }, "packages/standalone": { "name": "@schlechtenburg/standalone", "version": "0.0.0", + "extraneous": true, "license": "GPL-3.0-or-later", "dependencies": { "@schlechtenburg/core": "^0.0.0" diff --git a/package.json b/package.json index 3f8afa9..aa1512d 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,6 @@ "packages/image", "packages/paragraph", "packages/layout", - "packages/standalone" + "packages/rich-text" ] } diff --git a/packages/heading/__tests__/heading.test.ts b/packages/heading/__tests__/heading.test.ts index a1f6534..d7bd4ee 100644 --- a/packages/heading/__tests__/heading.test.ts +++ b/packages/heading/__tests__/heading.test.ts @@ -1,7 +1,16 @@ -'use strict'; - -const heading = require('..'); +import { describe, expect, it } from 'vitest' +import { mount } from '@vue/test-utils'; +import SbHeadingEdit from '../lib/edit'; +import SbHeadingView from '../lib/view'; describe('@schlechtenburg/heading', () => { - it('needs tests'); + it('edit should render', () => { + const edit = mount(SbHeadingEdit); + expect(edit.find('p').element).toBeTruthy(); + expect(edit.find('div.sb-toolbar').element).toBeTruthy(); + }); + it('view should render', () => { + const edit = mount(SbHeadingView); + expect(edit.find('h1').element).toBeTruthy(); + }); }); diff --git a/packages/image/__tests__/image.test.ts b/packages/image/__tests__/image.test.ts index 9f8d0ee..d60ed77 100644 --- a/packages/image/__tests__/image.test.ts +++ b/packages/image/__tests__/image.test.ts @@ -1,7 +1,16 @@ -'use strict'; - -const image = require('..'); +import { describe, expect, it } from 'vitest' +import { mount } from '@vue/test-utils'; +import SbImageEdit from '../lib/edit'; +import SbImageView from '../lib/view'; describe('@schlechtenburg/image', () => { - it('needs tests'); + it('edit should render', () => { + const edit = mount(SbImageEdit); + expect(edit.find('figure').element).toBeTruthy(); + expect(edit.find('div.sb-toolbar').element).toBeTruthy(); + }); + it('view should render', () => { + const edit = mount(SbImageView); + expect(edit.find('img').element).toBeTruthy(); + }); }); diff --git a/packages/layout/__tests__/layout.test.ts b/packages/layout/__tests__/layout.test.ts index f0b815e..9d9bab2 100644 --- a/packages/layout/__tests__/layout.test.ts +++ b/packages/layout/__tests__/layout.test.ts @@ -1,7 +1,16 @@ -'use strict'; - -const layout = require('..'); +import { describe, expect, it } from 'vitest' +import { mount } from '@vue/test-utils'; +import SbLayoutEdit from '../lib/edit'; +import SbLayoutView from '../lib/view'; describe('@schlechtenburg/layout', () => { - it('needs tests'); + it('edit should render', () => { + const edit = mount(SbLayoutEdit); + expect(edit.find('div.sb-layout').element).toBeTruthy(); + expect(edit.find('div.sb-toolbar').element).toBeTruthy(); + }); + it('view should render', () => { + const edit = mount(SbLayoutView); + expect(edit.find('div.sb-layout').element).toBeTruthy(); + }); }); diff --git a/packages/paragraph/__tests__/paragraph.test.ts b/packages/paragraph/__tests__/paragraph.test.ts index c512db3..8ead040 100644 --- a/packages/paragraph/__tests__/paragraph.test.ts +++ b/packages/paragraph/__tests__/paragraph.test.ts @@ -1,15 +1,16 @@ import { describe, expect, it } from 'vitest' import { mount } from '@vue/test-utils'; -import { withSetup } from '../../../test'; -import SbParagraph from '../lib'; +import SbParagraphEdit from '../lib/edit'; +import SbParagraphView from '../lib/view'; describe('@schlechtenburg/paragraph', () => { it('edit should render', () => { - const edit = mount(SbParagraph.edit); - expect(edit.find('p')).toContain(); - edit.element + const edit = mount(SbParagraphEdit); + expect(edit.find('p').element).toBeTruthy(); + expect(edit.find('div.sb-toolbar').element).toBeTruthy(); }); it('view should render', () => { - mount(SbParagraph.view); + const edit = mount(SbParagraphView); + expect(edit.find('p').element).toBeTruthy(); }); }); diff --git a/packages/rich-text/package.json b/packages/rich-text/package.json index e9516c1..670780d 100644 --- a/packages/rich-text/package.json +++ b/packages/rich-text/package.json @@ -7,7 +7,6 @@ "license": "GPL-3.0-or-later", "main": "lib/index.ts", "directories": { - "doc": "docs", "lib": "lib" }, "files": [ diff --git a/packages/standalone/__tests__/core.test.ts b/packages/standalone/__tests__/core.test.ts deleted file mode 100644 index 1166901..0000000 --- a/packages/standalone/__tests__/core.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -const core = require('..'); - -describe('@schlechtenburg/core', () => { - it('needs tests'); -}); diff --git a/packages/standalone/__tests__/standalone.test.ts b/packages/standalone/__tests__/standalone.test.ts new file mode 100644 index 0000000..1408181 --- /dev/null +++ b/packages/standalone/__tests__/standalone.test.ts @@ -0,0 +1,17 @@ +import { describe, expect, it } from 'vitest' +import { startSchlechtenburg, SbMode } from '../lib'; +import exampleData from '../../../docs/example-data'; + +describe('@schlechtenburg/standalone', () => { + it('edit should render', async () => { + const wrapper = document.createElement('div'); + const sb = await startSchlechtenburg(wrapper, { + availableBlocks: [], + block: exampleData, + eventUpdate: () => {}, + mode: SbMode.View, + }); + expect(sb.getMode()).toBe(SbMode.View); + expect(sb.getBlock()).toBeTruthy(); + }); +}); diff --git a/packages/standalone/lib/index.ts b/packages/standalone/lib/index.ts index aad1ca8..c2dd68a 100644 --- a/packages/standalone/lib/index.ts +++ b/packages/standalone/lib/index.ts @@ -1 +1,2 @@ +export * from '@schlechtenburg/core'; export * from './main'; diff --git a/vitest.config.ts b/vitest.config.ts index ab864f5..cc15ea2 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,8 +1,9 @@ import { defineConfig } from 'vitest/config' import vue from '@vitejs/plugin-vue' +import vueJsx from '@vitejs/plugin-vue-jsx' export default defineConfig({ - plugins: [vue()], + plugins: [vue(), vueJsx()], test: { browser: { enabled: true,