-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcanonical-title-map.spec.js
68 lines (59 loc) · 2.33 KB
/
canonical-title-map.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import chai from 'chai';
import { describe, it} from 'mocha';
import canonicalTitleMap from './canonical-title-map';
chai.should();
describe('canonical-title-map.js', () => {
it('should hold a normalisation function for enums and titleMaps to generate titleMaps', () => {
canonicalTitleMap.should.be.an('function');
});
describe('canonicalTitleMap', () => {
const enumeration = [ 'Joker', 'Riddler', 'Bane', 'Penguin', 'Cat Woman' ];
const titlemap = [
{ 'name': 'Joker', 'value': 'Joker' },
{ 'name': 'Riddler', 'value': 'Riddler' },
{ 'name': 'Bane', 'value': 'Bane' },
{ 'name': 'Penguin', 'value': 'Penguin' },
{ 'name': 'Cat Woman', 'value': 'Cat Woman' }
];
const titlemapObj = {
'Joker': 'Joker',
'Riddler': 'Riddler',
'Bane': 'Bane',
'Penguin': 'Penguin',
'Cat Woman': 'Cat Woman'
};
it('should return a titleMap for a titleMap object with original enum', () => {
let result = canonicalTitleMap(titlemapObj, enumeration);
result.should.be.deep.equal(titlemap);
});
it('should return a titleMap for a titleMap list with original enum', () => {
let result = canonicalTitleMap(titlemap, enumeration);
result.should.be.deep.equal(titlemap);
});
it('should return a titleMap for a enumNames list with enum values', () => {
let result = canonicalTitleMap([ 'name', 'firstname', 'phone' ], [ 'n', 'f', 'p' ]);
result.should.be.deep.equal([
{ name: 'name', value: 'n' },
{ name: 'firstname', value: 'f' },
{ name: 'phone', value: 'p' },
]);
});
it('should return a titleMap for a titleMap object without enum', () => {
let result = canonicalTitleMap(titlemapObj);
result.should.be.deep.equal(titlemap);
});
it('should return a titleMap for a titleMap list without enum', () => {
let result = canonicalTitleMap(titlemap);
result.should.be.deep.equal(titlemap);
});
it('should return a titleMap for a titleMap object with original enum, returning "undefined" name if the enum value is not found', () => {
enumeration.push('Mr Freeze');
let result = canonicalTitleMap(titlemapObj, enumeration);
titlemap.push({
"name": undefined,
"value": "Mr Freeze"
})
result.should.be.deep.equal(titlemap);
});
});
});