From 297f875295921a8e258dabf41a80f1d6a4ae614f Mon Sep 17 00:00:00 2001 From: cm-dyoshikawa Date: Thu, 12 Sep 2024 17:05:23 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=89=E3=82=AF=E3=82=BB=E3=83=AB=E5=9F=8B?= =?UTF-8?q?=E3=82=81=E8=BE=BC=E3=81=BF=E5=AF=BE=E5=BF=9C=20=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom-syntax/embed/docswell.test.ts | 20 +++++++++++ .../__tests__/matchers/isDocswellUrl.test.ts | 34 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 packages/zenn-markdown-html/__tests__/custom-syntax/embed/docswell.test.ts create mode 100644 packages/zenn-markdown-html/__tests__/matchers/isDocswellUrl.test.ts 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); + }); + }); + }); +});