Skip to content

Commit

Permalink
ドクセル埋め込み対応 テスト追加
Browse files Browse the repository at this point in the history
  • Loading branch information
cm-dyoshikawa committed Sep 12, 2024
1 parent 6ed6868 commit 297f875
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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(
'<script async class="docswell-embed" src="https://www.docswell.com/assets/libs/docswell-embed/docswell-embed.min.js" data-src="https://www.docswell.com/slide/LK7J5V/embed" data-aspect="0.5625"></script><div class="docswell-link"></div>'
);
});

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を指定してください');
});
});
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});

0 comments on commit 297f875

Please sign in to comment.