Skip to content

Commit

Permalink
テスト修正
Browse files Browse the repository at this point in the history
  • Loading branch information
cm-dyoshikawa committed Sep 17, 2024
1 parent 454eb98 commit 65e60e2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<span class="embed-block embed-docswell"><iframe src="https://www.docswell.com/slide/LK7J5V/embed" allowfullscreen="true" width="620" style="border:1px solid #ccc;display:block;margin:0px auto;padding:0px;aspect-ratio:620/349"></iframe></span>'
);
describe('Docswellの埋め込み用URLの場合', () => {
test('Docswellのiframeを返すこと', () => {
const html = markdownToHtml(
'@[docswell](https://www.docswell.com/slide/LK7J5V/embed)'
);
expect(html).toContain(
'<span class="embed-block embed-docswell"><iframe src="https://www.docswell.com/slide/LK7J5V/embed" allowfullscreen="true" width="620" style="border:1px solid #ccc;display:block;margin:0px auto;padding:0px;aspect-ratio:620/349"></iframe></span>'
);
});
});

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(
'<span class="embed-block embed-docswell"><iframe src="https://www.docswell.com/slide/LK7J5V/embed" allowfullscreen="true" width="620" style="border:1px solid #ccc;display:block;margin:0px auto;padding:0px;aspect-ratio:620/349"></iframe></span>'
);
});
});

describe('DocswellのURLが不正な場合', () => {
test('エラーメッセージを返すこと', () => {
const html = markdownToHtml(
'@[docswell](https://www.docswell.com/invalid)'
);
expect(html).toContain('DocswellのスライドURLが不正です');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,32 @@ 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);
});
});
});

describe('他のサイトのURLのとき', () => {
describe('他のサイトのURLの場合', () => {
test('falseを返すこと', () => {
const otherSiteUrls = ['https://zenn.dev/', 'https://github.com/'];

Expand Down

0 comments on commit 65e60e2

Please sign in to comment.