|
1 | 1 | import { expect } from 'chai' |
2 | 2 | import { EditorState, ContentState } from 'draft-js' |
3 | | -import { getCharCount, getWordCount } from '../index' |
| 3 | +import { getCharCount, getWordCount, getLineCount } from '../index' |
4 | 4 |
|
5 | | -describe('char Counter(non-unicode)', () => { |
| 5 | +describe('Char Counter', () => { |
6 | 6 | const createEditorStateFromText = text => { |
7 | 7 | const contentState = ContentState.createFromText(text) |
8 | 8 | return EditorState.createWithContent(contentState) |
9 | 9 | } |
10 | 10 |
|
11 | | - it('create editorState and counts 3 char', () => { |
| 11 | + it('create editorState and counts 3 characters', () => { |
12 | 12 | const editorState = createEditorStateFromText('One') |
13 | 13 |
|
14 | 14 | const result = getCharCount(editorState) |
15 | 15 | expect(result).to.equal(3) |
16 | 16 | }) |
| 17 | + |
| 18 | + it('create editorState and counts 3 unicode characters', () => { |
| 19 | + const editorState = createEditorStateFromText('😁😂😃') |
| 20 | + |
| 21 | + const result = getCharCount(editorState) |
| 22 | + expect(result).to.equal(3) |
| 23 | + }) |
17 | 24 | }) |
18 | 25 |
|
19 | | -describe('char Counter(unicode)', () => { |
| 26 | +describe('Word Counter', () => { |
20 | 27 | const createEditorStateFromText = text => { |
21 | 28 | const contentState = ContentState.createFromText(text) |
22 | 29 | return EditorState.createWithContent(contentState) |
23 | 30 | } |
24 | 31 |
|
25 | | - it('create editorState and counts 1 char', () => { |
26 | | - const editorState = createEditorStateFromText('一') |
| 32 | + it('create editorState and counts 3 words', () => { |
| 33 | + const editorState = createEditorStateFromText('One two three') |
27 | 34 |
|
28 | | - const result = getCharCount(editorState) |
29 | | - expect(result).to.equal(1) |
| 35 | + const result = getWordCount(editorState) |
| 36 | + expect(result).to.equal(3) |
30 | 37 | }) |
31 | 38 | }) |
32 | 39 |
|
33 | | -describe('word Counter', () => { |
| 40 | +describe('Line Counter', () => { |
34 | 41 | const createEditorStateFromText = text => { |
35 | 42 | const contentState = ContentState.createFromText(text) |
36 | 43 | return EditorState.createWithContent(contentState) |
37 | 44 | } |
38 | 45 |
|
39 | | - it('create editorState and counts 3 word', () => { |
40 | | - const editorState = createEditorStateFromText('One two three') |
| 46 | + it('create editorState and counts 3 lines', () => { |
| 47 | + const editorState = createEditorStateFromText('One\ntwo\nthree') |
41 | 48 |
|
42 | | - const result = getWordCount(editorState) |
| 49 | + const result = getLineCount(editorState) |
43 | 50 | expect(result).to.equal(3) |
44 | 51 | }) |
45 | 52 | }) |
0 commit comments