From b8a3c5ebd0710086cb9753ffd62b21b7864c0f33 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 25 Jul 2019 18:47:29 +0200 Subject: [PATCH] test serialization only produces html messages when needed --- test/editor/serialize-test.js | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/editor/serialize-test.js diff --git a/test/editor/serialize-test.js b/test/editor/serialize-test.js new file mode 100644 index 0000000000..2e7712e6e6 --- /dev/null +++ b/test/editor/serialize-test.js @@ -0,0 +1,47 @@ +/* +Copyright 2019 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import expect from 'expect'; +import EditorModel from "../../src/editor/model"; +import {htmlSerializeIfNeeded} from "../../src/editor/serialize"; +import {createPartCreator} from "./mock"; + +describe('editor/serialize', function() { + it('user pill turns message into html', function() { + const pc = createPartCreator(); + const model = new EditorModel([pc.userPill("Alice", "@alice:hs.tld")]); + const html = htmlSerializeIfNeeded(model, {}); + expect(html).toBe("Alice"); + }); + it('room pill turns message into html', function() { + const pc = createPartCreator(); + const model = new EditorModel([pc.roomPill("#room:hs.tld")]); + const html = htmlSerializeIfNeeded(model, {}); + expect(html).toBe("#room:hs.tld"); + }); + it('@room pill turns message into html', function() { + const pc = createPartCreator(); + const model = new EditorModel([pc.atRoomPill("@room")]); + const html = htmlSerializeIfNeeded(model, {}); + expect(html).toBeFalsy(); + }); + it('any markdown turns message into html', function() { + const pc = createPartCreator(); + const model = new EditorModel([pc.plain("*hello* world")]); + const html = htmlSerializeIfNeeded(model, {}); + expect(html).toBe("hello world"); + }); +});