mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 19:56:47 +03:00
b9da2255c4
* editor/mock ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/editor/serialize-test.js -> test/editor/serialize-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts in serialize-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/editor/range-test.js -> test/editor/range-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/editor/position-test.js -> test/editor/position-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * fix position-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/editor/operations-test.js -> test/editor/operations-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/editor/model-test.js -> test/editor/model-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts in model-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/editor/history-test.js -> test/editor/history-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts in history-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/editor/diff-test.js -> test/editor/diff-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/editor/deserialize-test.js -> test/editor/deserialize-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * ts in deserialize-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/editor/caret-test.js -> test/editor/caret-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * ts caret-test Signed-off-by: Kerry Archibald <kerrya@element.io>
76 lines
3.6 KiB
TypeScript
76 lines
3.6 KiB
TypeScript
/*
|
|
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";
|
|
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")], pc);
|
|
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")], pc);
|
|
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")], pc);
|
|
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")], pc);
|
|
const html = htmlSerializeIfNeeded(model, {});
|
|
expect(html).toBe("<em>hello</em> world");
|
|
});
|
|
it('displaynames ending in a backslash work', function() {
|
|
const pc = createPartCreator();
|
|
const model = new EditorModel([pc.userPill("Displayname\\", "@user:server")], pc);
|
|
const html = htmlSerializeIfNeeded(model, {});
|
|
expect(html).toBe("<a href=\"https://matrix.to/#/@user:server\">Displayname\\</a>");
|
|
});
|
|
it('displaynames containing an opening square bracket work', function() {
|
|
const pc = createPartCreator();
|
|
const model = new EditorModel([pc.userPill("Displayname[[", "@user:server")], pc);
|
|
const html = htmlSerializeIfNeeded(model, {});
|
|
expect(html).toBe("<a href=\"https://matrix.to/#/@user:server\">Displayname[[</a>");
|
|
});
|
|
it('displaynames containing a closing square bracket work', function() {
|
|
const pc = createPartCreator();
|
|
const model = new EditorModel([pc.userPill("Displayname]", "@user:server")], pc);
|
|
const html = htmlSerializeIfNeeded(model, {});
|
|
expect(html).toBe("<a href=\"https://matrix.to/#/@user:server\">Displayname]</a>");
|
|
});
|
|
it('escaped markdown should not retain backslashes', function() {
|
|
const pc = createPartCreator();
|
|
const model = new EditorModel([pc.plain('\\*hello\\* world')], pc);
|
|
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!')], pc);
|
|
const html = htmlSerializeIfNeeded(model, {});
|
|
expect(html).toBe('*hello* world < hey world!');
|
|
});
|
|
});
|