From 65e60e2f07c1b5c40e015d0e89d495e2481ef997 Mon Sep 17 00:00:00 2001 From: cm-dyoshikawa Date: Tue, 17 Sep 2024 17:18:47 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom-syntax/embed/docswell.test.ts | 39 +++++++++++++------ .../__tests__/matchers/isDocswellUrl.test.ts | 19 +++++---- 2 files changed, 39 insertions(+), 19 deletions(-) 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 index ffe66190..003e98ca 100644 --- a/packages/zenn-markdown-html/__tests__/custom-syntax/embed/docswell.test.ts +++ b/packages/zenn-markdown-html/__tests__/custom-syntax/embed/docswell.test.ts @@ -2,19 +2,34 @@ 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( - '' - ); + describe('Docswellの埋め込み用URLの場合', () => { + test('Docswellのiframeを返すこと', () => { + 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('Docswellのembed用のURLを指定してください'); + describe('DocswellのスライドURLの場合', () => { + test('Docswellのiframeを返すこと', () => { + const html = markdownToHtml( + '@[docswell](https://www.docswell.com/slide/LK7J5V/embed)' + ); + expect(html).toContain( + '' + ); + }); + }); + + describe('DocswellのURLが不正な場合', () => { + test('エラーメッセージを返すこと', () => { + const html = markdownToHtml( + '@[docswell](https://www.docswell.com/invalid)' + ); + expect(html).toContain('DocswellのスライドURLが不正です'); + }); }); }); diff --git a/packages/zenn-markdown-html/__tests__/matchers/isDocswellUrl.test.ts b/packages/zenn-markdown-html/__tests__/matchers/isDocswellUrl.test.ts index 158c8887..22ec1f35 100644 --- a/packages/zenn-markdown-html/__tests__/matchers/isDocswellUrl.test.ts +++ b/packages/zenn-markdown-html/__tests__/matchers/isDocswellUrl.test.ts @@ -2,19 +2,24 @@ import { isDocswellUrl } from '../../src/utils/url-matcher'; import { describe, test, expect } from 'vitest'; describe('isDocswellUrlのテスト', () => { - describe('Docswellの埋め込み用URLのとき', () => { + describe('Docswellの埋め込み用URLの場合', () => { test('trueを返すこと', () => { const docswellEmbedUrl = 'https://www.docswell.com/slide/LK7J5V/embed'; expect(isDocswellUrl(docswellEmbedUrl)).toBe(true); }); }); - describe('Docswellの他の画面のURLのとき', () => { + describe('DocswellのスライドURLの場合', () => { + test('trueを返すこと', () => { + const docswellSlideUrl = + 'https://www.docswell.com/s/ku-suke/LK7J5V-hello-docswell'; + expect(isDocswellUrl(docswellSlideUrl)).toBe(true); + }); + }); + + describe('Docswellの他の画面のURLの場合', () => { test('falseを返すこと', () => { - const docswellUrls = [ - 'https://www.docswell.com/', - 'https://www.docswell.com/s/ku-suke/LK7J5V-hello-docswell', - ]; + const docswellUrls = ['https://www.docswell.com/']; docswellUrls.forEach((url) => { expect(isDocswellUrl(url)).toBe(false); @@ -22,7 +27,7 @@ describe('isDocswellUrlのテスト', () => { }); }); - describe('他のサイトのURLのとき', () => { + describe('他のサイトのURLの場合', () => { test('falseを返すこと', () => { const otherSiteUrls = ['https://zenn.dev/', 'https://github.com/'];