Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dspace7 Angular
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vtechworks
Dspace7 Angular
Commits
6474cbfa
Commit
6474cbfa
authored
6 years ago
by
Chris Wilper
Browse files
Options
Downloads
Patches
Plain Diff
DS-4107 Add tests for Metadata utility methods
parent
ea9ce619
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/core/shared/metadata.model.spec.ts
+174
-0
174 additions, 0 deletions
src/app/core/shared/metadata.model.spec.ts
with
174 additions
and
0 deletions
src/app/core/shared/metadata.model.spec.ts
0 → 100644
+
174
−
0
View file @
6474cbfa
import
{
MetadataValue
,
MetadataValueFilter
}
from
'
./metadata.interfaces
'
;
import
{
Metadata
}
from
'
./metadata.model
'
;
const
mdValue
=
(
value
:
string
,
language
?:
string
):
MetadataValue
=>
{
return
{
value
:
value
,
language
:
language
===
undefined
?
null
:
language
};
}
const
dcDescription
=
mdValue
(
'
Some description
'
);
const
dcAbstract
=
mdValue
(
'
Some abstract
'
);
const
dcTitle0
=
mdValue
(
'
Title 0
'
);
const
dcTitle1
=
mdValue
(
'
Title 1
'
);
const
dcTitle2
=
mdValue
(
'
Title 2
'
,
'
en_US
'
);
const
bar
=
mdValue
(
'
Bar
'
);
const
singleMap
=
{
'
dc.title
'
:
[
dcTitle0
]
};
const
multiMap
=
{
'
dc.description
'
:
[
dcDescription
],
'
dc.description.abstract
'
:
[
dcAbstract
],
'
dc.title
'
:
[
dcTitle1
,
dcTitle2
],
'
foo
'
:
[
bar
]
};
const
testMethod
=
(
fn
,
resultKind
,
mapOrMaps
,
keyOrKeys
,
expected
,
filter
?)
=>
{
const
keys
=
keyOrKeys
instanceof
Array
?
keyOrKeys
:
[
keyOrKeys
];
describe
(
'
and key
'
+
(
keys
.
length
===
1
?
(
'
'
+
keys
[
0
])
:
(
'
s
'
+
JSON
.
stringify
(
keys
)))
+
'
with
'
+
(
filter
===
undefined
?
'
no filter
'
:
'
filter
'
+
JSON
.
stringify
(
filter
)),
()
=>
{
const
result
=
fn
(
mapOrMaps
,
keys
,
filter
);
let
shouldReturn
;
if
(
resultKind
===
'
boolean
'
)
{
shouldReturn
=
expected
;
}
else
if
(
expected
===
undefined
)
{
shouldReturn
=
'
undefined
'
;
}
else
if
(
expected
instanceof
Array
)
{
shouldReturn
=
'
an array with
'
+
expected
.
length
+
'
'
+
(
expected
.
length
>
1
?
'
ordered
'
:
''
)
+
resultKind
+
(
expected
.
length
!==
1
?
'
s
'
:
''
);
}
else
{
shouldReturn
=
'
a
'
+
resultKind
;
}
it
(
'
should return
'
+
shouldReturn
,
()
=>
{
expect
(
result
).
toEqual
(
expected
);
});
})
};
describe
(
'
Metadata
'
,
()
=>
{
describe
(
'
all method
'
,
()
=>
{
const
testAll
=
(
mapOrMaps
,
keyOrKeys
,
expected
,
filter
?:
MetadataValueFilter
)
=>
testMethod
(
Metadata
.
all
,
'
value
'
,
mapOrMaps
,
keyOrKeys
,
expected
,
filter
);
describe
(
'
with emptyMap
'
,
()
=>
{
testAll
({},
'
foo
'
,
[]);
testAll
({},
'
*
'
,
[]);
});
describe
(
'
with singleMap
'
,
()
=>
{
testAll
(
singleMap
,
'
foo
'
,
[]);
testAll
(
singleMap
,
'
*
'
,
[
dcTitle0
]);
testAll
(
singleMap
,
'
*
'
,
[],
{
value
:
'
baz
'
});
testAll
(
singleMap
,
'
dc.title
'
,
[
dcTitle0
]);
testAll
(
singleMap
,
'
dc.*
'
,
[
dcTitle0
]);
});
describe
(
'
with multiMap
'
,
()
=>
{
testAll
(
multiMap
,
'
foo
'
,
[
bar
]);
testAll
(
multiMap
,
'
*
'
,
[
dcDescription
,
dcAbstract
,
dcTitle1
,
dcTitle2
,
bar
]);
testAll
(
multiMap
,
'
dc.title
'
,
[
dcTitle1
,
dcTitle2
]);
testAll
(
multiMap
,
'
dc.*
'
,
[
dcDescription
,
dcAbstract
,
dcTitle1
,
dcTitle2
]);
testAll
(
multiMap
,
[
'
dc.title
'
,
'
dc.*
'
],
[
dcTitle1
,
dcTitle2
,
dcDescription
,
dcAbstract
]);
});
describe
(
'
with [ singleMap, multiMap ]
'
,
()
=>
{
testAll
([
singleMap
,
multiMap
],
'
foo
'
,
[
bar
]);
testAll
([
singleMap
,
multiMap
],
'
*
'
,
[
dcTitle0
]);
testAll
([
singleMap
,
multiMap
],
'
dc.title
'
,
[
dcTitle0
]);
testAll
([
singleMap
,
multiMap
],
'
dc.*
'
,
[
dcTitle0
]);
});
describe
(
'
with [ multiMap, singleMap ]
'
,
()
=>
{
testAll
([
multiMap
,
singleMap
],
'
foo
'
,
[
bar
]);
testAll
([
multiMap
,
singleMap
],
'
*
'
,
[
dcDescription
,
dcAbstract
,
dcTitle1
,
dcTitle2
,
bar
]);
testAll
([
multiMap
,
singleMap
],
'
dc.title
'
,
[
dcTitle1
,
dcTitle2
]);
testAll
([
multiMap
,
singleMap
],
'
dc.*
'
,
[
dcDescription
,
dcAbstract
,
dcTitle1
,
dcTitle2
]);
testAll
([
multiMap
,
singleMap
],
[
'
dc.title
'
,
'
dc.*
'
],
[
dcTitle1
,
dcTitle2
,
dcDescription
,
dcAbstract
]);
});
});
describe
(
'
allValues method
'
,
()
=>
{
const
testAllValues
=
(
mapOrMaps
,
keyOrKeys
,
expected
)
=>
testMethod
(
Metadata
.
allValues
,
'
string
'
,
mapOrMaps
,
keyOrKeys
,
expected
);
describe
(
'
with emptyMap
'
,
()
=>
{
testAllValues
({},
'
*
'
,
[]);
});
describe
(
'
with singleMap
'
,
()
=>
{
testAllValues
([
singleMap
,
multiMap
],
'
*
'
,
[
dcTitle0
.
value
]);
});
describe
(
'
with [ multiMap, singleMap ]
'
,
()
=>
{
testAllValues
([
multiMap
,
singleMap
],
'
*
'
,
[
dcDescription
.
value
,
dcAbstract
.
value
,
dcTitle1
.
value
,
dcTitle2
.
value
,
bar
.
value
]);
});
});
describe
(
'
first method
'
,
()
=>
{
const
testFirst
=
(
mapOrMaps
,
keyOrKeys
,
expected
)
=>
testMethod
(
Metadata
.
first
,
'
value
'
,
mapOrMaps
,
keyOrKeys
,
expected
);
describe
(
'
with emptyMap
'
,
()
=>
{
testFirst
({},
'
*
'
,
undefined
);
});
describe
(
'
with singleMap
'
,
()
=>
{
testFirst
(
singleMap
,
'
*
'
,
dcTitle0
);
});
describe
(
'
with [ multiMap, singleMap ]
'
,
()
=>
{
testFirst
([
multiMap
,
singleMap
],
'
*
'
,
dcDescription
);
});
});
describe
(
'
firstValue method
'
,
()
=>
{
const
testFirstValue
=
(
mapOrMaps
,
keyOrKeys
,
expected
)
=>
testMethod
(
Metadata
.
firstValue
,
'
value
'
,
mapOrMaps
,
keyOrKeys
,
expected
);
describe
(
'
with emptyMap
'
,
()
=>
{
testFirstValue
({},
'
*
'
,
undefined
);
});
describe
(
'
with singleMap
'
,
()
=>
{
testFirstValue
(
singleMap
,
'
*
'
,
dcTitle0
.
value
);
});
describe
(
'
with [ multiMap, singleMap ]
'
,
()
=>
{
testFirstValue
([
multiMap
,
singleMap
],
'
*
'
,
dcDescription
.
value
);
});
});
describe
(
'
has method
'
,
()
=>
{
const
testHas
=
(
mapOrMaps
,
keyOrKeys
,
expected
,
filter
?:
MetadataValueFilter
)
=>
testMethod
(
Metadata
.
has
,
'
boolean
'
,
mapOrMaps
,
keyOrKeys
,
expected
,
filter
);
describe
(
'
with emptyMap
'
,
()
=>
{
testHas
({},
'
*
'
,
false
);
});
describe
(
'
with singleMap
'
,
()
=>
{
testHas
(
singleMap
,
'
*
'
,
true
);
testHas
(
singleMap
,
'
*
'
,
false
,
{
value
:
'
baz
'
});
});
describe
(
'
with [ multiMap, singleMap ]
'
,
()
=>
{
testHas
([
multiMap
,
singleMap
],
'
*
'
,
true
);
});
});
describe
(
'
valueMatches method
'
,
()
=>
{
const
testValueMatches
=
(
value
:
MetadataValue
,
expected
:
boolean
,
filter
?:
MetadataValueFilter
)
=>
{
describe
(
'
with value
'
+
JSON
.
stringify
(
value
)
+
'
and filter
'
+
(
filter
===
undefined
?
'
undefined
'
:
JSON
.
stringify
(
filter
)),
()
=>
{
const
result
=
Metadata
.
valueMatches
(
value
,
filter
);
it
(
'
should return
'
+
expected
,
()
=>
{
expect
(
result
).
toEqual
(
expected
);
});
});
};
testValueMatches
(
mdValue
(
'
a
'
),
true
);
testValueMatches
(
mdValue
(
'
a
'
),
true
,
{
value
:
'
a
'
});
testValueMatches
(
mdValue
(
'
a
'
),
false
,
{
value
:
'
A
'
});
testValueMatches
(
mdValue
(
'
a
'
),
true
,
{
value
:
'
A
'
,
ignoreCase
:
true
});
testValueMatches
(
mdValue
(
'
ab
'
),
false
,
{
value
:
'
b
'
});
testValueMatches
(
mdValue
(
'
ab
'
),
true
,
{
value
:
'
b
'
,
substring
:
true
});
testValueMatches
(
mdValue
(
'
a
'
),
true
,
{
language
:
null
});
testValueMatches
(
mdValue
(
'
a
'
),
false
,
{
language
:
'
en_US
'
});
testValueMatches
(
mdValue
(
'
a
'
,
'
en_US
'
),
true
,
{
language
:
'
en_US
'
});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment