From 02dc510ce4b692923903bf2e04082ccf32819f1f Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Tue, 12 Sep 2023 11:32:40 -0400 Subject: [PATCH 1/4] fix(icon): do not warn if same icon is registered multiple times --- src/components/icon/utils.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/icon/utils.ts b/src/components/icon/utils.ts index ff8deefc3..f6c664479 100644 --- a/src/components/icon/utils.ts +++ b/src/components/icon/utils.ts @@ -40,10 +40,17 @@ export const addIcons = (icons: { [name: string]: string; }) => { const addToIconMap = (name: string, data: any) => { const map = getIconMap(); + + const existingIcon = map.get(name); - if (map.get(name) === undefined) { + if (existingIcon === undefined) { map.set(name, data); - } else { + + /** + * Importing and defining the same icon reference + * multiple times should not yield a warning. + */ + } else if (existingIcon !== data) { console.warn(`[Ionicons Warning]: Multiple icons were mapped to name "${name}". Ensure that multiple icons are not mapped to the same icon name.`) } } From 3c1d9813eba3d5ce71d45121e685a1c2538bf12b Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Tue, 12 Sep 2023 12:03:09 -0400 Subject: [PATCH 2/4] add tests --- src/components/icon/test/utils.spec.ts | 33 +++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/components/icon/test/utils.spec.ts b/src/components/icon/test/utils.spec.ts index 4844e942b..189ae21d6 100644 --- a/src/components/icon/test/utils.spec.ts +++ b/src/components/icon/test/utils.spec.ts @@ -126,27 +126,38 @@ describe('addIcons', () => { expect(getIconMap().get('myCoolIcon')).toEqual(logoIonitron); }); + it('should not warn when mapping the same icon twice', () => { + const spy = jest.spyOn(console, 'warn'); + + const myIcon = 'my-icon'; + + expect(spy).not.toHaveBeenCalled(); + + addIcons({ myIcon }); + + expect(spy).not.toHaveBeenCalled(); + + addIcons({ myIcon }); + + expect(spy).not.toHaveBeenCalled(); + }); + it('should not overwrite icons', () => { + const spy = jest.spyOn(console, 'warn'); + const logoA = 'logo a'; const logoB = 'logo b'; + expect(spy).not.toHaveBeenCalled(); + expect(getIconMap().get('logo-a')).toEqual(undefined); addIcons({ 'logo-a': logoB, logoA }); expect(getIconMap().get('logo-a')).toEqual(logoB); expect(getIconMap().get('logoA')).toEqual(logoA); - }); - - it('passing kebab case key should not generate a camel case key', () => { - const logoIonitron = 'stubbed data'; - - expect(getIconMap().get('kebab-key')).toEqual(undefined); - expect(getIconMap().get('kebabKey')).toEqual(undefined); - - addIcons({ 'kebab-key': logoIonitron }); - expect(getIconMap().get('kebab-key')).toEqual(logoIonitron); - expect(getIconMap().get('kebabKey')).toEqual(undefined); + expect(spy).toHaveBeenCalled(); }); + }); From 00ad92740c3da4b583fe11646bd58947eb226a8a Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Tue, 12 Sep 2023 12:03:31 -0400 Subject: [PATCH 3/4] fix(icon): do not warn when mapping same icon twice --- src/components/icon/utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/icon/utils.ts b/src/components/icon/utils.ts index f6c664479..e94bb8492 100644 --- a/src/components/icon/utils.ts +++ b/src/components/icon/utils.ts @@ -47,9 +47,9 @@ const addToIconMap = (name: string, data: any) => { map.set(name, data); /** - * Importing and defining the same icon reference - * multiple times should not yield a warning. - */ + +* Importing and defining the same icon reference + * multiple times should not yield a warning. */ } else if (existingIcon !== data) { console.warn(`[Ionicons Warning]: Multiple icons were mapped to name "${name}". Ensure that multiple icons are not mapped to the same icon name.`) } From 2d3f8aa79dfee1e0e30cbfabe5d63ece26f28c19 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Tue, 12 Sep 2023 12:05:39 -0400 Subject: [PATCH 4/4] fix formatting --- src/components/icon/utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/icon/utils.ts b/src/components/icon/utils.ts index e94bb8492..f6c664479 100644 --- a/src/components/icon/utils.ts +++ b/src/components/icon/utils.ts @@ -47,9 +47,9 @@ const addToIconMap = (name: string, data: any) => { map.set(name, data); /** - -* Importing and defining the same icon reference - * multiple times should not yield a warning. */ + * Importing and defining the same icon reference + * multiple times should not yield a warning. + */ } else if (existingIcon !== data) { console.warn(`[Ionicons Warning]: Multiple icons were mapped to name "${name}". Ensure that multiple icons are not mapped to the same icon name.`) }