tests and jsdocs

This commit is contained in:
Robert Elliott 2018-10-24 13:13:17 +02:00
parent bc098e58d4
commit 6b2bd1e11d
2 changed files with 16 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import { utcParse as d3UTCParse } from 'd3-time-format';
*/
import dummyOrders from './fixtures/dummy';
import {
compareStrings,
getDateSpaces,
getOrderedKeys,
getLineData,
@ -194,3 +195,11 @@ describe( 'getdateSpaces', () => {
expect( testDateSpaces[ testDateSpaces.length - 1 ].width ).toEqual( 10 );
} );
} );
describe( 'compareStrings', () => {
it( 'return an array of unique words from s2 that dont appear in base string', () => {
expect( compareStrings( 'Jul 2018', 'Aug 2018' ).join( ' ' ) ).toEqual( 'Aug' );
expect( compareStrings( 'Jul 2017', 'Aug 2018' ).join( ' ' ) ).toEqual( 'Aug 2018' );
expect( compareStrings( 'Jul 2017', 'Jul 2018' ).join( ' ' ) ).toEqual( '2018' );
} );
} );

View File

@ -357,6 +357,13 @@ export const getDateSpaces = ( data, uniqueDates, width, xLineScale ) =>
};
} );
/**
* Compares 2 strings and returns a list of words that are unique from s2
* @param {string} s1 - base string to compare against
* @param {string} s2 - string to compare against the base string
* @param {string} splitChar - character to use to deliminate words
* @returns {array} of unique words that appear in s2 but not in s1, the base string
*/
export const compareStrings = ( s1, s2, splitChar = ' ' ) => {
const string1 = s1.split( splitChar );
const string2 = s2.split( splitChar );