2019-07-25 18:47:29 +02:00
|
|
|
/*
|
|
|
|
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 EditorModel from "../../src/editor/model";
|
2021-06-29 14:11:58 +02:00
|
|
|
import { htmlSerializeIfNeeded } from "../../src/editor/serialize";
|
|
|
|
import { createPartCreator } from "./mock";
|
2019-07-25 18:47:29 +02:00
|
|
|
|
|
|
|
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("<a href=\"https://matrix.to/#/@alice:hs.tld\">Alice</a>");
|
|
|
|
});
|
|
|
|
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("<a href=\"https://matrix.to/#/#room:hs.tld\">#room:hs.tld</a>");
|
|
|
|
});
|
|
|
|
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("<em>hello</em> world");
|
|
|
|
});
|
2020-04-15 01:50:28 +02:00
|
|
|
it('displaynames ending in a backslash work', function() {
|
2020-04-15 01:40:38 +02:00
|
|
|
const pc = createPartCreator();
|
|
|
|
const model = new EditorModel([pc.userPill("Displayname\\", "@user:server")]);
|
|
|
|
const html = htmlSerializeIfNeeded(model, {});
|
2020-04-15 01:50:28 +02:00
|
|
|
expect(html).toBe("<a href=\"https://matrix.to/#/@user:server\">Displayname\\</a>");
|
2020-04-15 01:40:38 +02:00
|
|
|
});
|
2020-04-15 02:02:08 +02:00
|
|
|
it('displaynames containing an opening square bracket work', function() {
|
|
|
|
const pc = createPartCreator();
|
2020-04-15 03:31:30 +02:00
|
|
|
const model = new EditorModel([pc.userPill("Displayname[[", "@user:server")]);
|
2020-04-15 02:02:08 +02:00
|
|
|
const html = htmlSerializeIfNeeded(model, {});
|
2020-04-15 03:31:30 +02:00
|
|
|
expect(html).toBe("<a href=\"https://matrix.to/#/@user:server\">Displayname[[</a>");
|
2020-04-15 02:02:08 +02:00
|
|
|
});
|
2020-04-15 01:50:28 +02:00
|
|
|
it('displaynames containing a closing square bracket work', function() {
|
2020-04-15 01:40:38 +02:00
|
|
|
const pc = createPartCreator();
|
|
|
|
const model = new EditorModel([pc.userPill("Displayname]", "@user:server")]);
|
|
|
|
const html = htmlSerializeIfNeeded(model, {});
|
|
|
|
expect(html).toBe("<a href=\"https://matrix.to/#/@user:server\">Displayname]</a>");
|
|
|
|
});
|
2020-06-03 23:36:48 +02:00
|
|
|
it('escaped markdown should not retain backslashes', function() {
|
|
|
|
const pc = createPartCreator();
|
|
|
|
const model = new EditorModel([pc.plain('\\*hello\\* world')]);
|
|
|
|
const html = htmlSerializeIfNeeded(model, {});
|
|
|
|
expect(html).toBe('*hello* world');
|
|
|
|
});
|
|
|
|
it('escaped markdown should convert HTML entities', function() {
|
|
|
|
const pc = createPartCreator();
|
|
|
|
const model = new EditorModel([pc.plain('\\*hello\\* world < hey world!')]);
|
|
|
|
const html = htmlSerializeIfNeeded(model, {});
|
|
|
|
expect(html).toBe('*hello* world < hey world!');
|
|
|
|
});
|
2019-07-25 18:47:29 +02:00
|
|
|
});
|