This repository has been archived by the owner on May 30, 2023. It is now read-only.
/
formattedText.spec.js
95 lines (84 loc) · 2.76 KB
/
formattedText.spec.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { createElement } from 'lwc';
import Element from 'c/formattedText';
const createComponent = () => {
const element = createElement('c-formatted-text', { is: Element });
document.body.appendChild(element);
return element;
};
const exampleText =
'I love www.salesforce.com \n And I like cats@salesforce.com';
describe('c-formatted-text', () => {
it('default', () => {
const element = createComponent();
expect(element).toMatchSnapshot();
});
it('parses multiple new lines into multiple BRs', () => {
const element = createComponent();
element.value = 'First line \r\n\r\n Fourth line \n\n\n Eighth line';
element.linkify = true;
return Promise.resolve().then(() => {
expect(element).toMatchSnapshot();
});
});
it('parses url after ?', () => {
const element = createComponent();
element.value = 'First http://www.some-business.com?a=1&b=2';
element.linkify = true;
return Promise.resolve().then(() => {
expect(element).toMatchSnapshot();
});
});
it('with linkified text', () => {
const element = createComponent();
element.value = exampleText;
element.linkify = true;
return Promise.resolve().then(() => {
expect(element).toMatchSnapshot();
});
});
it('without linkified text', () => {
const element = createComponent();
element.value = exampleText;
return Promise.resolve().then(() => {
expect(element).toMatchSnapshot();
});
});
});
describe('c-formatted-text edge cases', () => {
it('url only', () => {
const element = createComponent();
element.value = 'www.salesforce.com';
element.linkify = true;
return Promise.resolve().then(() => {
expect(element).toMatchSnapshot();
});
});
it('newline only', () => {
const element = createComponent();
element.value = '\r\n';
return Promise.resolve().then(() => {
expect(element).toMatchSnapshot();
});
});
it('empty value', () => {
const element = createComponent();
element.value = null;
return Promise.resolve().then(() => {
expect(element).toMatchSnapshot();
});
});
it('empty text', () => {
const element = createComponent();
element.value = '';
return Promise.resolve().then(() => {
expect(element).toMatchSnapshot();
});
});
it('url and newline', () => {
const element = createComponent();
element.value = 'www.salesforce.com\r\n';
return Promise.resolve().then(() => {
expect(element).toMatchSnapshot();
});
});
});