-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbasic.html
158 lines (130 loc) · 5.47 KB
/
basic.html
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!doctype html>
<head>
<meta charset="UTF-8">
<title>vaadin-rich-text-editor tests</title>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../test-fixture/test-fixture.html">
<link rel="import" href="../vaadin-rich-text-editor.html">
</head>
<body>
<test-fixture id="default">
<template>
<vaadin-rich-text-editor></vaadin-rich-text-editor>
</template>
</test-fixture>
<script>
describe('rich text editor', () => {
let rte, editor;
beforeEach(() => {
rte = fixture('default');
editor = rte._editor;
});
describe('custom element definition', () => {
it('should have proper tag name', () => {
expect(rte.localName).to.be.equal('vaadin-rich-text-editor');
});
it('should not expose class name globally', () => {
expect(window.RichTextEditorElement).not.to.be.ok;
});
it('should have a valid version number', () => {
expect(customElements.get('vaadin-rich-text-editor').version).to.match(/^(\d+\.)?(\d+\.)?(\*|\d+)$/);
});
});
describe('toolbar controls', () => {
let btn;
['bold', 'italic', 'underline', 'strike', 'blockquote', 'code-block'].forEach(fmt => {
it(`should apply ${fmt} formatting when clicking the "btn-${fmt}" button`, () => {
btn = rte.shadowRoot.querySelector(`[part="btn-${fmt}"]`);
btn.click();
editor.insertText(0, 'Foo');
expect(editor.getFormat(0, 2)[fmt]).to.be.true;
});
it(`should undo ${fmt} formatting when clicking the "btn-${fmt}" button`, () => {
btn = rte.shadowRoot.querySelector(`[part="btn-${fmt}"]`);
editor.format(fmt, true);
btn.click();
expect(editor.getFormat(0)).to.be.empty.object;
});
});
['sub', 'super'].forEach(scr => {
it(`should apply ${scr} script when clicking the "btn-${scr}" button`, () => {
btn = rte.shadowRoot.querySelector(`[part="btn-${scr}"]`);
btn.click();
editor.insertText(0, 'Foo');
expect(editor.getFormat(0, 2).script).to.be.equal(scr);
});
it(`should undo ${scr} script when clicking the "btn-${scr}" button`, () => {
btn = rte.shadowRoot.querySelector(`[part="btn-${scr}"]`);
editor.format('script', scr);
btn.click();
expect(editor.getFormat(0)).to.be.empty.object;
});
});
['ordered', 'bullet'].forEach(type => {
it(`should create ${type} list when clicking the "btn-${type}-list" button`, () => {
btn = rte.shadowRoot.querySelector(`[part="btn-${type}-list"]`);
btn.click();
expect(editor.getFormat(0).list).to.be.equal(type);
btn.click();
expect(editor.getFormat(0).list).to.be.empty;
});
});
[1, 2].forEach(level => {
it(`should create <h${level}> header when clicking the "btn-h${level}" button`, () => {
btn = rte.shadowRoot.querySelector(`[part="btn-h${level}"]`);
btn.click();
expect(editor.getFormat(0).header).to.be.equal(level);
btn.click();
expect(editor.getFormat(0).header).to.be.empty;
});
});
it('should increase / decrease indentation when clicking "btn-indent-plus" / "btn-indent-minus" buttons', () => {
btn = rte.shadowRoot.querySelector('[part="btn-indent-plus"]');
btn.click();
expect(editor.getFormat(0).indent).to.be.equal(1);
btn.click();
expect(editor.getFormat(0).indent).to.be.equal(2);
btn = rte.shadowRoot.querySelector('[part="btn-indent-minus"]');
btn.click();
expect(editor.getFormat(0).indent).to.be.equal(1);
btn.click();
expect(editor.getFormat(0).indent).to.be.empty;
});
['center', 'right', 'justify'].forEach(align => {
it(`should apply ${align} alignment when clicking the toolbar button`, () => {
btn = rte.shadowRoot.querySelector(`[part="btn-align-${align}"]`);
btn.click();
expect(editor.getFormat(0).align).to.be.equal(align);
btn = rte.shadowRoot.querySelector('[part="btn-align-left"]');
btn.click();
expect(editor.getFormat(0).align).to.be.empty;
});
});
it('should clear formatting when clicking the "btn-clean" button', () => {
editor.format('bold', true);
editor.format('underline', true);
btn = rte.shadowRoot.querySelector('[part="btn-clean"]');
btn.click();
expect(editor.getFormat(0)).to.be.empty.object;
});
});
describe('value', () => {
it('should represent the "delta" of the editor', done => {
rte.addEventListener('value-changed', e => {
expect(e.detail.value).to.be.object;
expect(e.detail.value.ops).to.be.array;
expect(e.detail.value.ops).to.have.length(1);
expect(e.detail.value.ops[0]).to.deep.equal({insert: 'Foo\n'});
done();
});
editor.insertText(0, 'Foo');
});
it('should be read only and disallow modifications', () => {
rte.value = 'Foo';
expect(rte.value).to.not.equal('Foo');
});
});
});
</script>
</body>