kempo-ui 0.3.9 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/HtmlEditor.js +15 -15
- package/docs/src/components/HtmlEditor.js +15 -15
- package/package.json +3 -3
- package/src/components/HtmlEditor.js +24 -29
- package/tests/components/htmlEditorControls/Align.browser-test.js +203 -0
- package/tests/components/htmlEditorControls/Bold.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/BulletList.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/CharacterCount.browser-test.js +106 -0
- package/tests/components/htmlEditorControls/ClearFormatting.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/CodeBlock.browser-test.js +143 -0
- package/tests/components/htmlEditorControls/ControlGroup.browser-test.js +116 -0
- package/tests/components/htmlEditorControls/ControlSpacer.browser-test.js +69 -0
- package/tests/components/htmlEditorControls/CreateLink.browser-test.js +129 -0
- package/tests/components/htmlEditorControls/DropdownControl.browser-test.js +138 -0
- package/tests/components/htmlEditorControls/FormatBlock.browser-test.js +163 -0
- package/tests/components/htmlEditorControls/InlineCode.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/InsertTable.browser-test.js +129 -0
- package/tests/components/htmlEditorControls/Italic.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/Mode.browser-test.js +138 -0
- package/tests/components/htmlEditorControls/NumberList.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/Strikethrough.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/TextBackgroundColor.browser-test.js +136 -0
- package/tests/components/htmlEditorControls/TextColor.browser-test.js +136 -0
- package/tests/components/htmlEditorControls/Underline.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/WordCount.browser-test.js +106 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import '../../../src/components/HtmlEditor.js';
|
|
2
|
+
import WordCount from '../../../src/components/htmlEditorControls/WordCount.js';
|
|
3
|
+
|
|
4
|
+
const createEditorWithControl = async () => {
|
|
5
|
+
const container = document.createElement('div');
|
|
6
|
+
container.innerHTML = `
|
|
7
|
+
<k-html-editor>
|
|
8
|
+
<k-hec-word-count slot="toolbar-bottom-left"></k-hec-word-count>
|
|
9
|
+
</k-html-editor>
|
|
10
|
+
`;
|
|
11
|
+
document.body.appendChild(container);
|
|
12
|
+
const editor = container.querySelector('k-html-editor');
|
|
13
|
+
await new Promise(r => editor.addEventListener('ready', r, { once: true }));
|
|
14
|
+
const control = container.querySelector('k-hec-word-count');
|
|
15
|
+
return { container, editor, control };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const cleanup = container => {
|
|
19
|
+
if(container?.parentNode) container.parentNode.removeChild(container);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
/*
|
|
24
|
+
Element Creation
|
|
25
|
+
*/
|
|
26
|
+
'should create k-hec-word-count element': async ({pass, fail}) => {
|
|
27
|
+
const { container, control } = await createEditorWithControl();
|
|
28
|
+
if(!(control instanceof WordCount)){
|
|
29
|
+
cleanup(container);
|
|
30
|
+
return fail('Element should be instance of WordCount');
|
|
31
|
+
}
|
|
32
|
+
cleanup(container);
|
|
33
|
+
pass('WordCount element created correctly');
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
'should have shadow root': async ({pass, fail}) => {
|
|
37
|
+
const { container, control } = await createEditorWithControl();
|
|
38
|
+
if(!control.shadowRoot){
|
|
39
|
+
cleanup(container);
|
|
40
|
+
return fail('WordCount should have shadow root');
|
|
41
|
+
}
|
|
42
|
+
cleanup(container);
|
|
43
|
+
pass('WordCount has shadow root');
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
Editor Integration
|
|
48
|
+
*/
|
|
49
|
+
'should find parent editor': async ({pass, fail}) => {
|
|
50
|
+
const { container, editor, control } = await createEditorWithControl();
|
|
51
|
+
if(control.editor !== editor){
|
|
52
|
+
cleanup(container);
|
|
53
|
+
return fail('WordCount should find its parent k-html-editor');
|
|
54
|
+
}
|
|
55
|
+
cleanup(container);
|
|
56
|
+
pass('WordCount finds parent editor');
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
'should initialize count to 0': async ({pass, fail}) => {
|
|
60
|
+
const { container, control } = await createEditorWithControl();
|
|
61
|
+
if(control.count !== 0){
|
|
62
|
+
cleanup(container);
|
|
63
|
+
return fail(`Expected initial count 0, got ${control.count}`);
|
|
64
|
+
}
|
|
65
|
+
cleanup(container);
|
|
66
|
+
pass('WordCount initializes count to 0');
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
'should update count when editor content changes': async ({pass, fail}) => {
|
|
70
|
+
const { container, editor, control } = await createEditorWithControl();
|
|
71
|
+
editor.setValue('<p>hello world foo bar</p>');
|
|
72
|
+
await new Promise(r => setTimeout(r, 200));
|
|
73
|
+
await control.updateComplete;
|
|
74
|
+
if(control.count !== 4){
|
|
75
|
+
cleanup(container);
|
|
76
|
+
return fail(`Expected count 4, got ${control.count}`);
|
|
77
|
+
}
|
|
78
|
+
cleanup(container);
|
|
79
|
+
pass('WordCount updates on content change');
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
'should count empty content as 0 words': async ({pass, fail}) => {
|
|
83
|
+
const { container, editor, control } = await createEditorWithControl();
|
|
84
|
+
editor.setValue('');
|
|
85
|
+
await new Promise(r => setTimeout(r, 200));
|
|
86
|
+
await control.updateComplete;
|
|
87
|
+
if(control.count !== 0){
|
|
88
|
+
cleanup(container);
|
|
89
|
+
return fail(`Expected count 0 for empty content, got ${control.count}`);
|
|
90
|
+
}
|
|
91
|
+
cleanup(container);
|
|
92
|
+
pass('WordCount counts empty content as 0');
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
'should render word count span': async ({pass, fail}) => {
|
|
96
|
+
const { container, control } = await createEditorWithControl();
|
|
97
|
+
await control.updateComplete;
|
|
98
|
+
const span = control.shadowRoot.querySelector('.word-count');
|
|
99
|
+
if(!span){
|
|
100
|
+
cleanup(container);
|
|
101
|
+
return fail('WordCount should render a .word-count span');
|
|
102
|
+
}
|
|
103
|
+
cleanup(container);
|
|
104
|
+
pass('WordCount renders word count span');
|
|
105
|
+
},
|
|
106
|
+
};
|