|
1 | 1 | import { Icon } from '../icon'; |
2 | | -import { getName, getSrc, getUrl } from '../utils'; |
| 2 | +import { addIcons, getIconMap, getName, getSrc, getUrl } from '../utils'; |
3 | 3 |
|
4 | 4 |
|
5 | 5 | describe('getUrl', () => { |
@@ -82,3 +82,82 @@ describe('getName', () => { |
82 | 82 | }); |
83 | 83 |
|
84 | 84 | }); |
| 85 | + |
| 86 | +describe('addIcons', () => { |
| 87 | + it('should add an svg to the icon cache', () => { |
| 88 | + const testData = 'stubbed data'; |
| 89 | + |
| 90 | + expect(getIconMap().get('logo-ionic')).toEqual(undefined); |
| 91 | + |
| 92 | + addIcons({ 'logo-ionic': 'stubbed data' }); |
| 93 | + |
| 94 | + expect(getIconMap().get('logo-ionic')).toEqual(testData); |
| 95 | + }); |
| 96 | + |
| 97 | + it('should add kebab and camel case names to the icon cache', () => { |
| 98 | + const logoIonitron = 'stubbed data'; |
| 99 | + |
| 100 | + expect(getIconMap().get('logo-ionitron')).toEqual(undefined); |
| 101 | + expect(getIconMap().get('logoIonitron')).toEqual(undefined); |
| 102 | + |
| 103 | + addIcons({ logoIonitron }); |
| 104 | + |
| 105 | + expect(getIconMap().get('logo-ionitron')).toEqual(logoIonitron); |
| 106 | + expect(getIconMap().get('logoIonitron')).toEqual(logoIonitron); |
| 107 | + }); |
| 108 | + |
| 109 | + it('should map to a name that does not match the svg', () => { |
| 110 | + const logoIonitron = 'stubbed data'; |
| 111 | + |
| 112 | + expect(getIconMap().get('my-fun-icon')).toEqual(undefined); |
| 113 | + |
| 114 | + addIcons({ 'my-fun-icon': logoIonitron }); |
| 115 | + |
| 116 | + expect(getIconMap().get('my-fun-icon')).toEqual(logoIonitron); |
| 117 | + }); |
| 118 | + |
| 119 | + it('should map to an explicit camel case name', () => { |
| 120 | + const logoIonitron = 'stubbed data'; |
| 121 | + |
| 122 | + expect(getIconMap().get('myCoolIcon')).toEqual(undefined); |
| 123 | + |
| 124 | + addIcons({ 'myCoolIcon': logoIonitron }); |
| 125 | + |
| 126 | + expect(getIconMap().get('myCoolIcon')).toEqual(logoIonitron); |
| 127 | + }); |
| 128 | + |
| 129 | + it('should not warn when mapping the same icon twice', () => { |
| 130 | + const spy = jest.spyOn(console, 'warn'); |
| 131 | + |
| 132 | + const myIcon = 'my-icon'; |
| 133 | + |
| 134 | + expect(spy).not.toHaveBeenCalled(); |
| 135 | + |
| 136 | + addIcons({ myIcon }); |
| 137 | + |
| 138 | + expect(spy).not.toHaveBeenCalled(); |
| 139 | + |
| 140 | + addIcons({ myIcon }); |
| 141 | + |
| 142 | + expect(spy).not.toHaveBeenCalled(); |
| 143 | + }); |
| 144 | + |
| 145 | + it('should not overwrite icons', () => { |
| 146 | + const spy = jest.spyOn(console, 'warn'); |
| 147 | + |
| 148 | + const logoA = 'logo a'; |
| 149 | + const logoB = 'logo b'; |
| 150 | + |
| 151 | + expect(spy).not.toHaveBeenCalled(); |
| 152 | + |
| 153 | + expect(getIconMap().get('logo-a')).toEqual(undefined); |
| 154 | + |
| 155 | + addIcons({ 'logo-a': logoB, logoA }); |
| 156 | + |
| 157 | + expect(getIconMap().get('logo-a')).toEqual(logoB); |
| 158 | + expect(getIconMap().get('logoA')).toEqual(logoA); |
| 159 | + |
| 160 | + expect(spy).toHaveBeenCalled(); |
| 161 | + }); |
| 162 | + |
| 163 | +}); |
0 commit comments