Skip to content

Commit

Permalink
Blocks: Add unit tests for isMatchingSearchTerm
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Mar 12, 2019
1 parent 9ce3def commit bfc1a38
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion packages/blocks/src/store/test/selectors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/**
* Internal dependencies
*/
import { getChildBlockNames } from '../selectors';
import {
getChildBlockNames,
isMatchingSearchTerm,
} from '../selectors';

describe( 'selectors', () => {
describe( 'getChildBlockNames', () => {
Expand Down Expand Up @@ -134,4 +137,66 @@ describe( 'selectors', () => {
expect( getChildBlockNames( state, 'parent2' ) ).toEqual( [ 'child2' ] );
} );
} );

describe( 'isMatchingSearchTerm', () => {
const name = 'core/paragraph';
const blockType = {
title: 'Paragraph',
category: 'common',
keywords: [ 'text' ],
};

const state = {
blockTypes: {
[ name ]: blockType,
},
};

describe.each( [
[ 'name', name ],
[ 'block type', blockType ],
] )( 'by %s', ( label, nameOrType ) => {
it( 'should return false if not match', () => {
const result = isMatchingSearchTerm( state, nameOrType, 'Quote' );

expect( result ).toBe( false );
} );

it( 'should return true if match by title', () => {
const result = isMatchingSearchTerm( state, nameOrType, 'Paragraph' );

expect( result ).toBe( true );
} );

it( 'should return true if match ignoring case', () => {
const result = isMatchingSearchTerm( state, nameOrType, 'PARAGRAPH' );

expect( result ).toBe( true );
} );

it( 'should return true if match ignoring diacritics', () => {
const result = isMatchingSearchTerm( state, nameOrType, 'PÁRAGRAPH' );

expect( result ).toBe( true );
} );

it( 'should return true if match ignoring whitespace', () => {
const result = isMatchingSearchTerm( state, nameOrType, ' PARAGRAPH ' );

expect( result ).toBe( true );
} );

it( 'should return true if match using the keywords', () => {
const result = isMatchingSearchTerm( state, nameOrType, 'TEXT' );

expect( result ).toBe( true );
} );

it( 'should return true if match using the categories', () => {
const result = isMatchingSearchTerm( state, nameOrType, 'COMMON' );

expect( result ).toBe( true );
} );
} );
} );
} );

0 comments on commit bfc1a38

Please sign in to comment.