mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 15:03:07 +00:00
DS-4107 Use isUndefined and isNotUndefined where appropriate
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
|
import { isUndefined } from '../../shared/empty.util';
|
||||||
import { MetadataValue, MetadataValueFilter } from './metadata.interfaces';
|
import { MetadataValue, MetadataValueFilter } from './metadata.interfaces';
|
||||||
import { Metadata } from './metadata.model';
|
import { Metadata } from './metadata.model';
|
||||||
|
|
||||||
const mdValue = (value: string, language?: string): MetadataValue => {
|
const mdValue = (value: string, language?: string): MetadataValue => {
|
||||||
return { value: value, language: language === undefined ? null : language };
|
return { value: value, language: isUndefined(language) ? null : language };
|
||||||
}
|
}
|
||||||
|
|
||||||
const dcDescription = mdValue('Some description');
|
const dcDescription = mdValue('Some description');
|
||||||
@@ -24,12 +25,12 @@ const multiMap = {
|
|||||||
const testMethod = (fn, resultKind, mapOrMaps, keyOrKeys, expected, filter?) => {
|
const testMethod = (fn, resultKind, mapOrMaps, keyOrKeys, expected, filter?) => {
|
||||||
const keys = keyOrKeys instanceof Array ? keyOrKeys : [ keyOrKeys ];
|
const keys = keyOrKeys instanceof Array ? keyOrKeys : [ keyOrKeys ];
|
||||||
describe('and key' + (keys.length === 1 ? (' ' + keys[0]) : ('s ' + JSON.stringify(keys)))
|
describe('and key' + (keys.length === 1 ? (' ' + keys[0]) : ('s ' + JSON.stringify(keys)))
|
||||||
+ ' with ' + (filter === undefined ? 'no filter' : 'filter ' + JSON.stringify(filter)), () => {
|
+ ' with ' + (isUndefined(filter) ? 'no filter' : 'filter ' + JSON.stringify(filter)), () => {
|
||||||
const result = fn(mapOrMaps, keys, filter);
|
const result = fn(mapOrMaps, keys, filter);
|
||||||
let shouldReturn;
|
let shouldReturn;
|
||||||
if (resultKind === 'boolean') {
|
if (resultKind === 'boolean') {
|
||||||
shouldReturn = expected;
|
shouldReturn = expected;
|
||||||
} else if (expected === undefined) {
|
} else if (isUndefined(expected)) {
|
||||||
shouldReturn = 'undefined';
|
shouldReturn = 'undefined';
|
||||||
} else if (expected instanceof Array) {
|
} else if (expected instanceof Array) {
|
||||||
shouldReturn = 'an array with ' + expected.length + ' ' + (expected.length > 1 ? 'ordered ' : '')
|
shouldReturn = 'an array with ' + expected.length + ' ' + (expected.length > 1 ? 'ordered ' : '')
|
||||||
@@ -152,7 +153,7 @@ describe('Metadata', () => {
|
|||||||
|
|
||||||
const testValueMatches = (value: MetadataValue, expected: boolean, filter?: MetadataValueFilter) => {
|
const testValueMatches = (value: MetadataValue, expected: boolean, filter?: MetadataValueFilter) => {
|
||||||
describe('with value ' + JSON.stringify(value) + ' and filter '
|
describe('with value ' + JSON.stringify(value) + ' and filter '
|
||||||
+ (filter === undefined ? 'undefined' : JSON.stringify(filter)), () => {
|
+ (isUndefined(filter) ? 'undefined' : JSON.stringify(filter)), () => {
|
||||||
const result = Metadata.valueMatches(value, filter);
|
const result = Metadata.valueMatches(value, filter);
|
||||||
it('should return ' + expected, () => {
|
it('should return ' + expected, () => {
|
||||||
expect(result).toEqual(expected);
|
expect(result).toEqual(expected);
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { isEmpty } from '../../shared/empty.util';
|
import { isEmpty, isNotUndefined, isUndefined } from '../../shared/empty.util';
|
||||||
import { MetadataMap, MetadataValue, MetadataValueFilter } from './metadata.interfaces';
|
import { MetadataMap, MetadataValue, MetadataValueFilter } from './metadata.interfaces';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,7 +93,7 @@ export class Metadata {
|
|||||||
public static firstValue(mdMapOrMaps: MetadataMap | MetadataMap[], keyOrKeys: string | string[],
|
public static firstValue(mdMapOrMaps: MetadataMap | MetadataMap[], keyOrKeys: string | string[],
|
||||||
filter?: MetadataValueFilter): string {
|
filter?: MetadataValueFilter): string {
|
||||||
const value = Metadata.first(mdMapOrMaps, keyOrKeys, filter);
|
const value = Metadata.first(mdMapOrMaps, keyOrKeys, filter);
|
||||||
return value === undefined ? undefined : value.value;
|
return isUndefined(value) ? undefined : value.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,7 +106,7 @@ export class Metadata {
|
|||||||
*/
|
*/
|
||||||
public static has(mdMapOrMaps: MetadataMap | MetadataMap[], keyOrKeys: string | string[],
|
public static has(mdMapOrMaps: MetadataMap | MetadataMap[], keyOrKeys: string | string[],
|
||||||
filter?: MetadataValueFilter): boolean {
|
filter?: MetadataValueFilter): boolean {
|
||||||
return Metadata.first(mdMapOrMaps, keyOrKeys, filter) !== undefined;
|
return isNotUndefined(Metadata.first(mdMapOrMaps, keyOrKeys, filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user