fa5ec5077b
* The WordCounter should only do one thing: count words. This makes it also easier to test. * Add some really basic unit tests. * Instead of only refreshing the count on enter and delete, refresh the count when the user stops typing. Also look at paste and content changes in TinyMCE. * Use `match` instead of `replace` when it is appropriate. * More readable code. See #30966. Fixes #26620. git-svn-id: https://develop.svn.wordpress.org/trunk@32856 602fd350-edb4-49c9-b593-d223f7449a82
48 lines
1.0 KiB
JavaScript
48 lines
1.0 KiB
JavaScript
( function( QUnit ) {
|
|
var wordCounter = new window.wp.utils.WordCounter();
|
|
|
|
QUnit.module( 'word-count' );
|
|
|
|
QUnit.test( 'All.', function( assert ) {
|
|
var tests = [
|
|
{
|
|
message: 'Basic test.',
|
|
string: 'one two three',
|
|
wordCount: 3,
|
|
charCount: 11
|
|
},
|
|
{
|
|
message: 'HTML tags.',
|
|
string: 'one <em class="test">two</em><br />three',
|
|
wordCount: 3,
|
|
charCount: 11
|
|
},
|
|
{
|
|
message: 'Line breaks.',
|
|
string: 'one\ntwo\nthree',
|
|
wordCount: 3,
|
|
charCount: 11
|
|
},
|
|
{
|
|
message: 'Encoded spaces.',
|
|
string: 'one two three',
|
|
wordCount: 3,
|
|
charCount: 11
|
|
},
|
|
{
|
|
message: 'Punctuation.',
|
|
string: 'It\'s two three... 4?',
|
|
wordCount: 3,
|
|
charCount: 11
|
|
}
|
|
];
|
|
|
|
var i = tests.length;
|
|
|
|
while ( i-- ) {
|
|
assert.equal( wordCounter.count( tests[ i ].string ), tests[ i ].wordCount, tests[ i ].message + ' (words)' );
|
|
assert.equal( wordCounter.count( tests[ i ].string, 'characters' ), tests[ i ].charCount, tests[ i ].message + ' (characters)' );
|
|
}
|
|
} );
|
|
} )( window.QUnit );
|