Skip to content

Commit 9814fb3

Browse files
committed
test: add new test csse for useParagonThemeCore
1 parent f4556a3 commit 9814fb3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/react/hooks/paragon/useParagonThemeCore.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ const useParagonThemeCore = ({
130130
} else {
131131
existingCoreThemeLink.rel = 'stylesheet';
132132
existingCoreThemeLink.removeAttribute('as');
133+
existingCoreThemeLink.dataset.paragonThemeCore = true;
133134
if (brandCoreLink) {
134135
brandCoreLink.rel = 'stylesheet';
135136
brandCoreLink.removeAttribute('as');
137+
brandCoreLink.dataset.brandThemeCore = true;
136138
}
137139
setIsParagonThemeCoreLoaded(true);
138140
setIsBrandThemeCoreLoaded(true);

src/react/hooks/paragon/useParagonThemeCore.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@ describe('useParagonThemeCore', () => {
8686
expect(document.querySelector('link').href).toBe(`${getConfig().BASE_URL}/${PARAGON_THEME.paragon.themeUrls.core.fileName}`);
8787
});
8888

89+
it('should not create a new link if the core theme is already loaded', () => {
90+
document.head.innerHTML = '<link rel="preload" as="style" href="https://cdn.jsdelivr.net/npm/@edx/paragon@$21.0.0/dist/core.min.css" onerror="this.remove();">';
91+
const coreConfig = {
92+
themeCore: {
93+
urls: {
94+
default: 'https://cdn.jsdelivr.net/npm/@edx/paragon@$21.0.0/dist/core.min.css',
95+
},
96+
},
97+
onLoad: themeOnLoad,
98+
};
99+
100+
renderHook(() => useParagonThemeCore(coreConfig));
101+
const themeCoreLinks = document.head.querySelectorAll('link');
102+
expect(themeCoreLinks.length).toBe(1);
103+
expect(themeCoreLinks[0].rel).toContain('stylesheet');
104+
expect(themeCoreLinks[0]).not.toHaveAttribute('as', 'style');
105+
});
106+
89107
it('should not create any core link if can not find themeCore urls definition', () => {
90108
const coreConfig = {
91109
themeCore: {

0 commit comments

Comments
 (0)