Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrommen committed Apr 10, 2019
1 parent 2aefd9c commit ca3e521
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
20 changes: 20 additions & 0 deletions packages/components/src/form-token-field/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,26 @@ describe( 'FormTokenField', function() {
expect( getSelectedSuggestion() ).toBe( null );
expect( getTokensHTML() ).toEqual( [ 'foo', 'bar', 'with' ] );
} );

it( 'should re-render when suggestions prop has changed', function() {
wrapper.setState( {
tokenSuggestions: [],
isExpanded: true,
} );
expect( getSuggestionsText() ).toEqual( [] );
setText( 'so' );
expect( getSuggestionsText() ).toEqual( [] );

wrapper.setState( {
tokenSuggestions: fixtures.specialSuggestions.default,
} );
expect( getSuggestionsText() ).toEqual( fixtures.matchingSuggestions.so );

wrapper.setState( {
tokenSuggestions: [],
} );
expect( getSuggestionsText() ).toEqual( [] );
} );
} );

describe( 'adding tokens', function() {
Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/form-token-field/test/lib/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export default {
htmlUnescaped: [ 'a   b', 'i <3 tags', '1&2&3&4' ],
},
specialSuggestions: {
default: [
'the', 'of', 'and', 'to', 'a', 'in', 'for', 'is', 'on', 'that', 'by', 'this', 'with', 'i', 'you', 'it',
'not', 'or', 'be', 'are', 'from', 'at', 'as', 'your', 'all', 'have', 'new', 'more', 'an', 'was', 'we',
'associate', 'snake', 'pipes', 'sound',
],
textEscaped: [ '<3', 'Stuff & Things', 'Tags & Stuff', 'Tags & Stuff 2' ],
textUnescaped: [ '<3', 'Stuff & Things', 'Tags & Stuff', 'Tags & Stuff 2' ],
matchAmpersandUnescaped: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ import { Component } from '@wordpress/element';
/**
* Internal dependencies
*/
import fixtures from './fixtures';
import TokenField from '../../';

const suggestions = [
'the', 'of', 'and', 'to', 'a', 'in', 'for', 'is', 'on', 'that', 'by', 'this', 'with', 'i', 'you', 'it',
'not', 'or', 'be', 'are', 'from', 'at', 'as', 'your', 'all', 'have', 'new', 'more', 'an', 'was', 'we',
'associate', 'snake', 'pipes', 'sound',
];
const { specialSuggestions: { default: suggestions } } = fixtures;

function unescapeAndFormatSpaces( str ) {
const nbsp = String.fromCharCode( 160 );
Expand Down

0 comments on commit ca3e521

Please sign in to comment.