|
| 1 | +import chai from 'chai'; |
| 2 | +import { describe, it} from 'mocha'; |
| 3 | +import canonicalTitleMap from './canonical-title-map'; |
| 4 | + |
| 5 | +chai.should(); |
| 6 | + |
| 7 | +describe('canonical-title-map.js', () => { |
| 8 | + it('should hold a normalisation function for enums and titleMaps to generate titleMaps', () => { |
| 9 | + canonicalTitleMap.should.be.an('function'); |
| 10 | + }); |
| 11 | + |
| 12 | + describe('canonicalTitleMap', () => { |
| 13 | + const enumeration = [ 'Joker', 'Riddler', 'Bane', 'Penguin', 'Cat Woman' ]; |
| 14 | + const titlemap = [ |
| 15 | + { 'name': 'Joker', 'value': 'Joker' }, |
| 16 | + { 'name': 'Riddler', 'value': 'Riddler' }, |
| 17 | + { 'name': 'Bane', 'value': 'Bane' }, |
| 18 | + { 'name': 'Penguin', 'value': 'Penguin' }, |
| 19 | + { 'name': 'Cat Woman', 'value': 'Cat Woman' } |
| 20 | + ]; |
| 21 | + const titlemapObj = { |
| 22 | + 'Joker': 'Joker', |
| 23 | + 'Riddler': 'Riddler', |
| 24 | + 'Bane': 'Bane', |
| 25 | + 'Penguin': 'Penguin', |
| 26 | + 'Cat Woman': 'Cat Woman' |
| 27 | + }; |
| 28 | + |
| 29 | + it('should return a titleMap for a titleMap object with original enum', () => { |
| 30 | + let result = canonicalTitleMap(titlemapObj, enumeration); |
| 31 | + result.should.be.deep.equal(titlemap); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should return a titleMap for a titleMap list with original enum', () => { |
| 35 | + let result = canonicalTitleMap(titlemap, enumeration); |
| 36 | + result.should.be.deep.equal(titlemap); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should return a titleMap for a titleMap object without enum', () => { |
| 40 | + let result = canonicalTitleMap(titlemapObj); |
| 41 | + result.should.be.deep.equal(titlemap); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should return a titleMap for a titleMap list without enum', () => { |
| 45 | + let result = canonicalTitleMap(titlemap); |
| 46 | + result.should.be.deep.equal(titlemap); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should return a titleMap for a titleMap object with original enum, returning "undefined" name if the enum value is not found', () => { |
| 50 | + enumeration.push('Mr Freeze'); |
| 51 | + let result = canonicalTitleMap(titlemapObj, enumeration); |
| 52 | + titlemap.push({ |
| 53 | + "name": undefined, |
| 54 | + "value": "Mr Freeze" |
| 55 | + }) |
| 56 | + result.should.be.deep.equal(titlemap); |
| 57 | + }); |
| 58 | + }); |
| 59 | +}); |
0 commit comments