diff --git a/packages/zenn-markdown-html/__tests__/custom-syntax/embed/docswell.test.ts b/packages/zenn-markdown-html/__tests__/custom-syntax/embed/docswell.test.ts new file mode 100644 index 00000000..79707792 --- /dev/null +++ b/packages/zenn-markdown-html/__tests__/custom-syntax/embed/docswell.test.ts @@ -0,0 +1,20 @@ +import { describe, test, expect } from 'vitest'; +import markdownToHtml from '../../../src/index'; + +describe('Docswell', () => { + test('should generate docswell html', () => { + const html = markdownToHtml( + '@[docswell](https://www.docswell.com/slide/LK7J5V/embed)' + ); + expect(html).toContain( + '
' + ); + }); + + test('should not generate docswell html with invalid url', () => { + const html = markdownToHtml( + '@[docswell](https://www.docswell.com/s/ku-suke/LK7J5V-hello-docswell)' + ); + expect(html).toContain('Doscwellのembed用のURLを指定してください'); + }); +}); diff --git a/packages/zenn-markdown-html/__tests__/matchers/isDocswellUrl.test.ts b/packages/zenn-markdown-html/__tests__/matchers/isDocswellUrl.test.ts new file mode 100644 index 00000000..158c8887 --- /dev/null +++ b/packages/zenn-markdown-html/__tests__/matchers/isDocswellUrl.test.ts @@ -0,0 +1,34 @@ +import { isDocswellUrl } from '../../src/utils/url-matcher'; +import { describe, test, expect } from 'vitest'; + +describe('isDocswellUrlのテスト', () => { + describe('Docswellの埋め込み用URLのとき', () => { + test('trueを返すこと', () => { + const docswellEmbedUrl = 'https://www.docswell.com/slide/LK7J5V/embed'; + expect(isDocswellUrl(docswellEmbedUrl)).toBe(true); + }); + }); + + describe('Docswellの他の画面のURLのとき', () => { + test('falseを返すこと', () => { + const docswellUrls = [ + 'https://www.docswell.com/', + 'https://www.docswell.com/s/ku-suke/LK7J5V-hello-docswell', + ]; + + docswellUrls.forEach((url) => { + expect(isDocswellUrl(url)).toBe(false); + }); + }); + }); + + describe('他のサイトのURLのとき', () => { + test('falseを返すこと', () => { + const otherSiteUrls = ['https://zenn.dev/', 'https://github.com/']; + + otherSiteUrls.forEach((url) => { + expect(isDocswellUrl(url)).toBe(false); + }); + }); + }); +});