From b51c41f47412a9b21bb93fb30eb030086bbdfcd4 Mon Sep 17 00:00:00 2001 From: Taylor Grafft Date: Wed, 1 Nov 2023 14:25:33 -0500 Subject: [PATCH] task/WP-355: Fixing issue with icons on dev/prod sites (#892) * fixing issue with icons all defaulting to icon-applications on dev/prod site * getting rid of console.logs --------- Co-authored-by: Taylor Grafft --- client/src/utils/doesClassExist.js | 6 ++- client/src/utils/doesClassExist.test.js | 55 +++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 client/src/utils/doesClassExist.test.js diff --git a/client/src/utils/doesClassExist.js b/client/src/utils/doesClassExist.js index b3ddab017..29055efe6 100644 --- a/client/src/utils/doesClassExist.js +++ b/client/src/utils/doesClassExist.js @@ -6,7 +6,11 @@ function doesClassExist(className, stylesheets) { return true; } } else if (typeof stylesheet === 'string') { - if (stylesheet.includes(`.${className}::before`)) { + if ( + //Required to fix issue with dev and prod defaulting to icon-applications for every icon + stylesheet.includes(`.${className}::before`) || + stylesheet.includes(`.${className}:before`) + ) { return true; } } diff --git a/client/src/utils/doesClassExist.test.js b/client/src/utils/doesClassExist.test.js new file mode 100644 index 000000000..d43fb5c6e --- /dev/null +++ b/client/src/utils/doesClassExist.test.js @@ -0,0 +1,55 @@ +import doesClassExist from './doesClassExist'; + +const mockStylesheet = ` +.icon-upload:before { + content: "\\ea57" +} + +.icon-user-reverse:before { + content: "\\ea58" +} + +.icon-user:before { + content: "\\ea59" +} + +.icon-visualization:before { + content: "\\ea5a" +} + +.icon-zoom-in:before { + content: "\\ea5b" +} + +.icon-zoom-out:before { + content: "\\ea5c" +} +`; + +describe('doesClassExist', () => { + it('should return true for existing class in string stylesheet', async () => { + const result = doesClassExist('icon-visualization', [mockStylesheet]); + expect(result).toBe(true); + }); + + it('should return false for non-existing class in string stylesheet', async () => { + const result = doesClassExist('icon-nonexistent', [mockStylesheet]); + expect(result).toBe(false); + }); + + it('should return true for existing class in object stylesheet', async () => { + const mockStylesheetObject = { + 'icon-visualization': true, + }; + const result = doesClassExist('icon-visualization', [mockStylesheetObject]); + expect(result).toBe(true); + }); + + it('should return false for non-existing class in object stylesheet', async () => { + const mockStylesheetObject = { + 'icon-visualization': true, + }; + const result = doesClassExist('icon-nonexistent', [mockStylesheetObject]); + expect(result).toBe(false); + }); +});