From 7b454ae4b61ddddee1a51a8fe14f4583bdce000a Mon Sep 17 00:00:00 2001 From: robertu <4065233+robertu7@users.noreply.github.com> Date: Mon, 11 Mar 2024 13:29:28 +0800 Subject: [PATCH 1/2] feat: add tests for normalizeCommentHTML --- package.json | 2 +- src/transformers/normalize.test.ts | 72 +++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 750bb11..5ff5148 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@matters/matters-editor", - "version": "0.2.3-alpha.0", + "version": "0.2.3-alpha.1", "description": "Editor for matters.news", "author": "https://github.com/thematters", "homepage": "https://github.com/thematters/matters-editor", diff --git a/src/transformers/normalize.test.ts b/src/transformers/normalize.test.ts index e47c019..f431407 100644 --- a/src/transformers/normalize.test.ts +++ b/src/transformers/normalize.test.ts @@ -1,16 +1,21 @@ import { describe, expect, test } from 'vitest' -import { normalizeArticleHTML } from './normalize' +import { normalizeArticleHTML, normalizeCommentHTML } from './normalize' const expectNormalizeArticleHTML = (input: string, output: string) => { const result = normalizeArticleHTML(input) expect(result.trim()).toBe(output) } +export const expectNormalizeCommentHTML = (input: string, output: string) => { + const result = normalizeCommentHTML(input) + expect(result.trim()).toBe(output) +} + /** * Tests */ -describe('Normalization', () => { +describe('Normalization: Article', () => { test('bolds', () => { expectNormalizeArticleHTML( '

abc

', @@ -279,3 +284,66 @@ describe('Normalization', () => { ) }) }) + +describe('Normalization: Comment', () => { + test('bolds is not supported', () => { + expectNormalizeCommentHTML('

abc

', '

abc

') + expectNormalizeCommentHTML('

abc

', '

abc

') + }) + + test('strikethrough is not supported', () => { + expectNormalizeCommentHTML('

abc

', '

abc

') + expectNormalizeCommentHTML('

abc

', '

abc

') + expectNormalizeCommentHTML('

abc

', '

abc

') + }) + + test('italic is not supported', () => { + expectNormalizeCommentHTML('

abc

', '

abc

') + + expectNormalizeCommentHTML('

abc

', '

abc

') + }) + + test('underline is not supported', () => { + expectNormalizeCommentHTML('

abc

', '

abc

') + }) + + test('self-closed tags', () => { + expectNormalizeCommentHTML('

', '

') + + expectNormalizeCommentHTML('

', '


') + + expectNormalizeCommentHTML('
', '

') + + // -> + expectNormalizeCommentHTML( + '
左:女反派。右:女主。
', + '

左:女反派。右:女主。

', + ) + + // + expectNormalizeCommentHTML( + '
', + '

', + ) + }) +}) From a32f702311cd5f1d8467a63ee97ee12bc46e3680 Mon Sep 17 00:00:00 2001 From: robertu <4065233+robertu7@users.noreply.github.com> Date: Mon, 11 Mar 2024 13:32:09 +0800 Subject: [PATCH 2/2] feat: add more tests to normalizeCommentHTML --- src/transformers/normalize.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/transformers/normalize.test.ts b/src/transformers/normalize.test.ts index f431407..95c9f6a 100644 --- a/src/transformers/normalize.test.ts +++ b/src/transformers/normalize.test.ts @@ -286,6 +286,20 @@ describe('Normalization: Article', () => { }) describe('Normalization: Comment', () => { + test('quote', () => { + expectNormalizeCommentHTML( + '

abc

', + '

abc

', + ) + }) + + test('link', () => { + expectNormalizeCommentHTML( + '

abc

', + '

abc

', + ) + }) + test('bolds is not supported', () => { expectNormalizeCommentHTML('

abc

', '

abc

') expectNormalizeCommentHTML('

abc

', '

abc

')