|
1 | 1 | import { isUndefined } from '../../shared/empty.util'; |
2 | 2 | import { v4 as uuidv4 } from 'uuid'; |
3 | 3 | import { MetadataMap, MetadataValue, MetadataValueFilter, MetadatumViewModel } from './metadata.models'; |
4 | | -import { Metadata } from './metadata.utils'; |
| 4 | +import { Metadata, PLACEHOLDER_VALUE } from './metadata.utils'; |
5 | 5 |
|
6 | 6 | const mdValue = (value: string, language?: string, authority?: string): MetadataValue => { |
7 | 7 | return Object.assign(new MetadataValue(), { |
@@ -44,19 +44,20 @@ const multiViewModelList = [ |
44 | 44 | { key: 'foo', ...bar, order: 0 } |
45 | 45 | ]; |
46 | 46 |
|
47 | | -const testMethod = (fn, resultKind, mapOrMaps, keyOrKeys, expected, filter?) => { |
| 47 | +const testMethod = (fn, resultKind, mapOrMaps, keyOrKeys, expected, filter?, limit?: number) => { |
48 | 48 | const keys = keyOrKeys instanceof Array ? keyOrKeys : [keyOrKeys]; |
49 | 49 | describe('and key' + (keys.length === 1 ? (' ' + keys[0]) : ('s ' + JSON.stringify(keys))) |
50 | 50 | + ' with ' + (isUndefined(filter) ? 'no filter' : 'filter ' + JSON.stringify(filter)), () => { |
51 | | - const result = fn(mapOrMaps, keys, filter); |
| 51 | + const result = fn(mapOrMaps, keys, filter, limit); |
52 | 52 | let shouldReturn; |
53 | 53 | if (resultKind === 'boolean') { |
54 | 54 | shouldReturn = expected; |
55 | 55 | } else if (isUndefined(expected)) { |
56 | 56 | shouldReturn = 'undefined'; |
57 | 57 | } else if (expected instanceof Array) { |
58 | 58 | shouldReturn = 'an array with ' + expected.length + ' ' + (expected.length > 1 ? 'ordered ' : '') |
59 | | - + resultKind + (expected.length !== 1 ? 's' : ''); |
| 59 | + + resultKind + (expected.length !== 1 ? 's' : '') |
| 60 | + + (isUndefined(limit) ? '' : ' (limited to ' + limit + ')'); |
60 | 61 | } else { |
61 | 62 | shouldReturn = 'a ' + resultKind; |
62 | 63 | } |
@@ -297,4 +298,29 @@ describe('Metadata', () => { |
297 | 298 |
|
298 | 299 | }); |
299 | 300 |
|
| 301 | + describe('all method with limit', () => { |
| 302 | + const testAllWithLimit = (mapOrMaps, keyOrKeys, expected, limit) => |
| 303 | + testMethod(Metadata.all, 'value', mapOrMaps, keyOrKeys, expected, undefined, limit); |
| 304 | + |
| 305 | + describe('with multiMap and limit', () => { |
| 306 | + testAllWithLimit(multiMap, 'dc.title', [dcTitle1], 1); |
| 307 | + }); |
| 308 | + }); |
| 309 | + |
| 310 | + describe('Placeholder values', () => { |
| 311 | + it('should ignore placeholder values in get methods', () => { |
| 312 | + const placeholderMd = mdValue(PLACEHOLDER_VALUE); |
| 313 | + const key = 'dc.test.placeholder'; |
| 314 | + const map = { 'dc.test.placeholder': [placeholderMd] }; |
| 315 | + |
| 316 | + expect(Metadata.all(map, key).length).toEqual(0); |
| 317 | + expect(Metadata.allValues(map, key).length).toEqual(0); |
| 318 | + expect(Metadata.has(map, key)).toBeFalsy(); |
| 319 | + expect(Metadata.first(map, key)).toBeUndefined(); |
| 320 | + expect(Metadata.firstValue(map, key)).toBeUndefined(); |
| 321 | + expect(Metadata.hasValue(placeholderMd)).toBeFalsy(); |
| 322 | + expect(Metadata.valueMatches(placeholderMd, null)).toBeFalsy(); |
| 323 | + }); |
| 324 | + }); |
| 325 | + |
300 | 326 | }); |
0 commit comments