|
@@ -13,6 +13,8 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
|
|
|
import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
import { add as addTranslations, _clear as clearTranslations } from '@ckeditor/ckeditor5-utils/src/translation-service';
|
|
import { add as addTranslations, _clear as clearTranslations } from '@ckeditor/ckeditor5-utils/src/translation-service';
|
|
|
import Position from '@ckeditor/ckeditor5-engine/src/model/position';
|
|
import Position from '@ckeditor/ckeditor5-engine/src/model/position';
|
|
|
|
|
+import ShiftEnter from '@ckeditor/ckeditor5-enter/src/shiftenter';
|
|
|
|
|
+import TableEditing from '@ckeditor/ckeditor5-table/src/tableediting';
|
|
|
|
|
|
|
|
// Delay related to word-count throttling.
|
|
// Delay related to word-count throttling.
|
|
|
const DELAY = 255;
|
|
const DELAY = 255;
|
|
@@ -24,7 +26,7 @@ describe( 'WordCount', () => {
|
|
|
|
|
|
|
|
beforeEach( () => {
|
|
beforeEach( () => {
|
|
|
return VirtualTestEditor.create( {
|
|
return VirtualTestEditor.create( {
|
|
|
- plugins: [ WordCount, Paragraph ]
|
|
|
|
|
|
|
+ plugins: [ WordCount, Paragraph, ShiftEnter, TableEditing ]
|
|
|
} )
|
|
} )
|
|
|
.then( _editor => {
|
|
.then( _editor => {
|
|
|
editor = _editor;
|
|
editor = _editor;
|
|
@@ -56,7 +58,7 @@ describe( 'WordCount', () => {
|
|
|
setModelData( model, '<paragraph>Foo(bar)baz</paragraph>' +
|
|
setModelData( model, '<paragraph>Foo(bar)baz</paragraph>' +
|
|
|
'<paragraph><$text foo="true">Hello</$text> world.</paragraph>' +
|
|
'<paragraph><$text foo="true">Hello</$text> world.</paragraph>' +
|
|
|
'<paragraph>1234</paragraph>' +
|
|
'<paragraph>1234</paragraph>' +
|
|
|
- '<paragraph>(-@#$%^*())</paragraph>' );
|
|
|
|
|
|
|
+ '<paragraph>(@#$%^*())</paragraph>' );
|
|
|
|
|
|
|
|
wordCountPlugin._calculateWordsAndCharacters();
|
|
wordCountPlugin._calculateWordsAndCharacters();
|
|
|
|
|
|
|
@@ -71,6 +73,28 @@ describe( 'WordCount', () => {
|
|
|
expect( wordCountPlugin.characters ).to.equal( 12 );
|
|
expect( wordCountPlugin.characters ).to.equal( 12 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'should not count enter as a character', () => {
|
|
|
|
|
+ expect( wordCountPlugin.characters ).to.equal( 0 );
|
|
|
|
|
+
|
|
|
|
|
+ setModelData( model, '<paragraph>Fo<softBreak></softBreak>o</paragraph>' +
|
|
|
|
|
+ '<paragraph>Foo</paragraph>' +
|
|
|
|
|
+ '<table>' +
|
|
|
|
|
+ '<tableRow>' +
|
|
|
|
|
+ '<tableCell></tableCell><tableCell></tableCell><tableCell></tableCell>' +
|
|
|
|
|
+ '</tableRow>' +
|
|
|
|
|
+ '<tableRow>' +
|
|
|
|
|
+ '<tableCell></tableCell><tableCell><paragraph>foo</paragraph></tableCell><tableCell></tableCell>' +
|
|
|
|
|
+ '</tableRow>' +
|
|
|
|
|
+ '<tableRow>' +
|
|
|
|
|
+ '<tableCell></tableCell><tableCell></tableCell><tableCell></tableCell>' +
|
|
|
|
|
+ '</tableRow>' +
|
|
|
|
|
+ '</table>' );
|
|
|
|
|
+
|
|
|
|
|
+ wordCountPlugin._calculateWordsAndCharacters();
|
|
|
|
|
+
|
|
|
|
|
+ expect( wordCountPlugin.characters ).to.equal( 9 );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
describe( 'update event', () => {
|
|
describe( 'update event', () => {
|
|
|
it( 'fires update event with actual amount of characters and words', () => {
|
|
it( 'fires update event with actual amount of characters and words', () => {
|
|
|
const fake = sinon.fake();
|
|
const fake = sinon.fake();
|
|
@@ -123,7 +147,7 @@ describe( 'WordCount', () => {
|
|
|
wordCountPlugin._calculateWordsAndCharacters();
|
|
wordCountPlugin._calculateWordsAndCharacters();
|
|
|
|
|
|
|
|
// There is \n between paragraph which has to be included into calculations
|
|
// There is \n between paragraph which has to be included into calculations
|
|
|
- expect( container.innerText ).to.equal( 'Words: 5Characters: 24' );
|
|
|
|
|
|
|
+ expect( container.innerText ).to.equal( 'Words: 5Characters: 23' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'subsequent calls provides the same element', () => {
|
|
it( 'subsequent calls provides the same element', () => {
|