From 19dfeb22f1f03b6a81efa90191118bc984bd5be6 Mon Sep 17 00:00:00 2001 From: alvarosabu Date: Thu, 17 Oct 2024 14:18:33 +0200 Subject: [PATCH] chore: fix text types --- src/richtext.test.ts | 70 ++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/richtext.test.ts b/src/richtext.test.ts index 450f04d..2ebd0dc 100644 --- a/src/richtext.test.ts +++ b/src/richtext.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'; import { richTextResolver } from './richtext'; import { createTextVNode, h } from 'vue'; import type { VNode } from 'vue'; -import type { BlockTypes, MarkTypes, type Node, NodeResolver } from './types'; +import { BlockTypes, MarkTypes, StoryblokRichTextNode, StoryblokRichTextNodeResolver } from './types'; import { StoryblokComponent } from '@storyblok/vue'; describe('richtext', () => { @@ -18,7 +18,7 @@ describe('richtext', () => { }, ], }; - const html = render(paragraph as Node); + const html = render(paragraph as StoryblokRichTextNode); expect(html).toBe('

Hello, world!

'); }); @@ -36,7 +36,7 @@ describe('richtext', () => { }, ], }; - const html = render(heading as Node); + const html = render(heading as unknown as StoryblokRichTextNode); expect(html).toBe('

Headline 1

'); }); @@ -65,7 +65,7 @@ describe('richtext', () => { }, ], }; - const html = render(list as Node); + const html = render(list as StoryblokRichTextNode); expect(html).toBe('
  • Item 1
  • Item 2
'); }); @@ -95,7 +95,7 @@ describe('richtext', () => { }, ], }; - const html = render(list as Node); + const html = render(list as unknown as StoryblokRichTextNode); expect(html).toBe('
  1. Item 1
  2. Item 2
'); }); @@ -116,7 +116,7 @@ describe('richtext', () => { }, }, }; - const html = render(image as Node); + const html = render(image as unknown as StoryblokRichTextNode); expect(html).toBe('An image'); }); @@ -136,7 +136,7 @@ describe('richtext', () => { const node = { type: BlockTypes[type as keyof typeof BlockTypes], }; - const html = render(node as Node); + const html = render(node as StoryblokRichTextNode); expect(html).toBe(`<${tagMap[type]} key="${tagMap[type]}-${index + 1}" />`); }); @@ -150,7 +150,7 @@ describe('richtext', () => { emoji: '🚀', }, }; - const html = render(emoji as Node); + const html = render(emoji as unknown as StoryblokRichTextNode); expect(html).toBe('undefined'); }); @@ -165,7 +165,7 @@ describe('richtext', () => { }, ], }; - const html = render(code as Node); + const html = render(code as StoryblokRichTextNode); expect(html).toBe('
console.log("Hello, world!")
'); }); @@ -174,7 +174,7 @@ describe('richtext', () => { const hr = { type: 'horizontal_rule', }; - const html = render(hr as Node); + const html = render(hr as StoryblokRichTextNode); expect(html).toBe('
'); }); @@ -183,7 +183,7 @@ describe('richtext', () => { const br = { type: 'hard_break', }; - const html = render(br as Node); + const html = render(br as StoryblokRichTextNode); expect(html).toBe('
'); }); @@ -203,7 +203,7 @@ describe('richtext', () => { }, ], }; - const html = render(quote as Node); + const html = render(quote as unknown as StoryblokRichTextNode); expect(html).toBe('

Quote

'); }); }); @@ -221,7 +221,7 @@ describe('richtext', () => { }, ], }; - const html = render(text as Node); + const html = render(text as unknown as StoryblokRichTextNode); expect(html).toBe('

Bold and italic

'); }); @@ -237,7 +237,7 @@ describe('richtext', () => { }, ], }; - const html = render(text as Node); + const html = render(text as unknown as StoryblokRichTextNode); // Update the expected HTML to reflect the styles expect(html).toBe('

Bold and italic

'); }); @@ -258,7 +258,7 @@ describe('richtext', () => { }, ], }; - const html = render(link as Node); + const html = render(link as unknown as StoryblokRichTextNode); expect(html).toBe('External link'); }); @@ -278,7 +278,7 @@ describe('richtext', () => { }, ], }; - const html = render(link as Node); + const html = render(link as unknown as StoryblokRichTextNode); expect(html).toBe('Anchor link'); }); @@ -297,7 +297,7 @@ describe('richtext', () => { }, ], }; - const html = render(link as Node); + const html = render(link as unknown as StoryblokRichTextNode); expect(html).toBe('hola@alvarosaburido.dev'); }); @@ -319,7 +319,7 @@ describe('richtext', () => { }, ], }; - const html = render(link as Node); + const html = render(link as unknown as StoryblokRichTextNode); expect(html).toBe('Internal Link'); }); @@ -338,7 +338,7 @@ describe('richtext', () => { }, ], }; - const html = render(link as Node); + const html = render(link as unknown as StoryblokRichTextNode); expect(html).toBe('Asset link'); }); @@ -349,7 +349,7 @@ describe('richtext', () => { type: 'text', marks: [{ type: 'bold' }], }; - const html = render(bold as Node); + const html = render(bold as unknown as StoryblokRichTextNode); expect(html).toBe('Bold'); }); @@ -360,7 +360,7 @@ describe('richtext', () => { type: 'text', marks: [{ type: 'italic' }], }; - const html = render(italic as Node); + const html = render(italic as unknown as StoryblokRichTextNode); expect(html).toBe('Italic'); }); @@ -371,7 +371,7 @@ describe('richtext', () => { type: 'text', marks: [{ type: 'underline' }], }; - const html = render(underline as Node); + const html = render(underline as unknown as StoryblokRichTextNode); expect(html).toBe('Underline'); }); @@ -382,7 +382,7 @@ describe('richtext', () => { type: 'text', marks: [{ type: 'strike' }], }; - const html = render(strike as Node); + const html = render(strike as unknown as StoryblokRichTextNode); expect(html).toBe('Strike'); }); @@ -393,7 +393,7 @@ describe('richtext', () => { type: 'text', marks: [{ type: 'code' }], }; - const html = render(code as Node); + const html = render(code as unknown as StoryblokRichTextNode); expect(html).toBe('Code'); }); @@ -404,7 +404,7 @@ describe('richtext', () => { type: 'text', marks: [{ type: 'superscript' }], }; - const html = render(superscript as Node); + const html = render(superscript as unknown as StoryblokRichTextNode); expect(html).toBe('Superscript'); }); @@ -415,7 +415,7 @@ describe('richtext', () => { type: 'text', marks: [{ type: 'subscript' }], }; - const html = render(subscript as Node); + const html = render(subscript as unknown as StoryblokRichTextNode); expect(html).toBe('Subscript'); }); @@ -426,7 +426,7 @@ describe('richtext', () => { type: 'text', marks: [{ type: 'highlight' }], }; - const html = render(highlight as Node); + const html = render(highlight as unknown as StoryblokRichTextNode); expect(html).toBe('Highlight'); }); }); @@ -444,7 +444,7 @@ describe('richtext', () => { }, ], }; - const vnode = render(paragraph as Node); + const vnode = render(paragraph as StoryblokRichTextNode); expect(vnode.__v_isVNode).toBeTruthy(); expect(vnode.type).toBe('p'); }); @@ -462,7 +462,7 @@ describe('richtext', () => { }, ], }; - const vnode = render(paragraph as Node); + const vnode = render(paragraph as StoryblokRichTextNode); expect(vnode?.children[0].children).toBe('Hello, world!'); }); it('should overwrite a resolver', async () => { @@ -470,7 +470,7 @@ describe('richtext', () => { const { render } = richTextResolver({ resolvers: { - [MarkTypes.LINK]: (node: Node) => h(RouterLink, { + [MarkTypes.LINK]: (node: StoryblokRichTextNode) => h(RouterLink, { to: node.attrs?.href, target: node.attrs?.target, }, node.text), @@ -492,13 +492,13 @@ describe('richtext', () => { }, ], }; - const node = render(link as Node); + const node = render(link as unknown as StoryblokRichTextNode); expect(node.type).toBe('span'); - expect(node.props.to).toBe('/about'); + expect(node?.props?.to).toBe('/about'); }); it('should render a blok component', async () => { - const componentResolver: NodeResolver = (node: Node): VNode => { + const componentResolver: StoryblokRichTextNodeResolver = (node: StoryblokRichTextNode): VNode => { return h(StoryblokComponent, { blok: node?.attrs?.body[0], id: node.attrs?.id, @@ -531,8 +531,8 @@ describe('richtext', () => { ], }, }; - const vnode = render(paragraph as Node); - expect(vnode.props.blok.component).toBe('test-button'); + const vnode = render(paragraph as unknown as StoryblokRichTextNode); + expect(vnode?.props?.blok.component).toBe('test-button'); }); }); });