@@ -50,19 +50,20 @@ const multiViewModelList = [
5050 { key : 'foo' , ...bar , order : 0 } ,
5151] ;
5252
53- const testMethod = ( fn , resultKind , mapOrMaps , keyOrKeys , hitHighlights , expected , filter ?) => {
53+ const testMethod = ( fn , resultKind , mapOrMaps , keyOrKeys , hitHighlights , expected , filter ?, limit ?: number ) => {
5454 const keys = keyOrKeys instanceof Array ? keyOrKeys : [ keyOrKeys ] ;
5555 describe ( 'and key' + ( keys . length === 1 ? ( ' ' + keys [ 0 ] ) : ( 's ' + JSON . stringify ( keys ) ) )
5656 + ' with ' + ( isUndefined ( filter ) ? 'no filter' : 'filter ' + JSON . stringify ( filter ) ) , ( ) => {
57- const result = fn ( mapOrMaps , keys , hitHighlights , filter ) ;
57+ const result = fn ( mapOrMaps , keys , hitHighlights , filter , true , limit ) ;
5858 let shouldReturn ;
5959 if ( resultKind === 'boolean' ) {
6060 shouldReturn = expected ;
6161 } else if ( isUndefined ( expected ) ) {
6262 shouldReturn = 'undefined' ;
6363 } else if ( expected instanceof Array ) {
6464 shouldReturn = 'an array with ' + expected . length + ' ' + ( expected . length > 1 ? 'ordered ' : '' )
65- + resultKind + ( expected . length !== 1 ? 's' : '' ) ;
65+ + resultKind + ( expected . length !== 1 ? 's' : '' )
66+ + ( isUndefined ( limit ) ? '' : ' (limited to ' + limit + ')' ) ;
6667 } else {
6768 shouldReturn = 'a ' + resultKind ;
6869 }
@@ -255,4 +256,60 @@ describe('Metadata', () => {
255256
256257 } ) ;
257258
259+ describe ( 'all method with limit' , ( ) => {
260+ const testAllWithLimit = ( mapOrMaps , keyOrKeys , expected , limit ) =>
261+ testMethod ( Metadata . all , 'value' , mapOrMaps , keyOrKeys , undefined , expected , undefined , limit ) ;
262+
263+ describe ( 'with multiMap and limit' , ( ) => {
264+ testAllWithLimit ( multiMap , 'dc.title' , [ dcTitle1 ] , 1 ) ;
265+ } ) ;
266+ } ) ;
267+
268+ describe ( 'hasValue method' , ( ) => {
269+ const testHasValue = ( value , expected ) =>
270+ testMethod ( Metadata . hasValue , 'boolean' , value , undefined , undefined , expected ) ;
271+
272+ describe ( 'with undefined value' , ( ) => {
273+ testHasValue ( undefined , false ) ;
274+ } ) ;
275+ describe ( 'with null value' , ( ) => {
276+ testHasValue ( null , false ) ;
277+ } ) ;
278+ describe ( 'with string value' , ( ) => {
279+ testHasValue ( 'test' , true ) ;
280+ } ) ;
281+ describe ( 'with empty string value' , ( ) => {
282+ testHasValue ( '' , false ) ;
283+ } ) ;
284+ describe ( 'with undefined value for a MetadataValue object' , ( ) => {
285+ const value : Partial < MetadataValue > = {
286+ value : undefined ,
287+ } ;
288+ testHasValue ( value , false ) ;
289+ } ) ;
290+ describe ( 'with null value for a MetadataValue object' , ( ) => {
291+ const value : Partial < MetadataValue > = {
292+ value : null ,
293+ } ;
294+ testHasValue ( value , false ) ;
295+ } ) ;
296+ describe ( 'with empty string for a MetadataValue object' , ( ) => {
297+ const value : Partial < MetadataValue > = {
298+ value : '' ,
299+ } ;
300+ testHasValue ( value , false ) ;
301+ } ) ;
302+ describe ( 'with value for a MetadataValue object' , ( ) => {
303+ const value : Partial < MetadataValue > = {
304+ value : 'test' ,
305+ } ;
306+ testHasValue ( value , true ) ;
307+ } ) ;
308+ describe ( 'with a generic object' , ( ) => {
309+ const value : any = {
310+ test : 'test' ,
311+ } ;
312+ testHasValue ( value , true ) ;
313+ } ) ;
314+ } ) ;
258315} ) ;
0 commit comments