forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paste.test.tsx
53 lines (41 loc) · 1.68 KB
/
paste.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {parseTable, getTable, formatMarkdownTableMessage} from './paste';
const validClipboardData: any = {
items: [1],
types: ['text/html'],
getData: () => {
return '<table><tr><td>test</td><td>test</td></tr><tr><td>test</td><td>test</td></tr></table>';
},
};
const validTable: any = parseTable(validClipboardData.getData());
describe('Paste.getTable', () => {
test('returns false without html in the clipboard', () => {
const badClipboardData: any = {
items: [1],
types: ['text/plain'],
};
expect(getTable(badClipboardData)).toBe(false);
});
test('returns false without table in the clipboard', () => {
const badClipboardData: any = {
items: [1],
types: ['text/html'],
getData: () => '<p>There is no table here</p>',
};
expect(getTable(badClipboardData)).toBe(false);
});
test('returns table from valid clipboard data', () => {
expect(getTable(validClipboardData)).toEqual(validTable);
});
});
describe('Paste.formatMarkdownTableMessage', () => {
const markdownTable = '|test | test|\n|--- | ---|\n|test | test|\n';
test('returns a markdown table when valid html table provided', () => {
expect(formatMarkdownTableMessage(validTable)).toBe(markdownTable);
});
test('returns a markdown table under a message when one is provided', () => {
const testMessage = 'test message';
expect(formatMarkdownTableMessage(validTable, testMessage)).toBe(`${testMessage}\n\n${markdownTable}`);
});
});