diff --git a/package-lock.json b/package-lock.json index 2d2172fed..d1ee02c99 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,14 +36,16 @@ "devDependencies": { "@edx/brand": "npm:@openedx/brand-openedx@^1.2.2", "@edx/browserslist-config": "1.2.0", - "@openedx/frontend-build": "14.0.3", - "@openedx/paragon": "22.3.2", + "@openedx/frontend-build": "github:edunext/frontend-build#dcoa/design-tokens-support", + "@openedx/paragon": "npm:@openedx/paragon@^22.0.0-alpha.25", "@testing-library/jest-dom": "6.4.5", "@testing-library/react": "12.1.5", "@testing-library/react-hooks": "^8.0.1", + "@testing-library/user-event": "14.4.3", "axios-mock-adapter": "^1.21.3", "core-js": "3.37.0", "husky": "8.0.3", + "jest-localstorage-mock": "^2.4.26", "jsdoc": "^4.0.0", "nodemon": "3.1.0", "prop-types": "15.8.1", @@ -3425,10 +3427,10 @@ } }, "node_modules/@openedx/frontend-build": { - "version": "14.0.3", - "resolved": "https://registry.npmjs.org/@openedx/frontend-build/-/frontend-build-14.0.3.tgz", - "integrity": "sha512-SnYGezb9XAW9HNOHdmRXyAPkVcCRWdtFK45nN2rIOgArW5XwDQjzjyWM1aSKWfY7Mizk9LgJrej1GhSE/rpp7g==", + "version": "1.0.0-semantically-released", + "resolved": "git+ssh://git@github.com/edunext/frontend-build.git#3915ec1f9821971fc9058f30eb76e320db8ba2ad", "dev": true, + "license": "AGPL-3.0", "dependencies": { "@babel/cli": "7.22.5", "@babel/core": "7.22.5", @@ -4135,6 +4137,19 @@ } } }, + "node_modules/@testing-library/user-event": { + "version": "14.4.3", + "resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-14.4.3.tgz", + "integrity": "sha512-kCUc5MEwaEMakkO5x7aoD+DLi02ehmEM2QCGWvNqAS1dV/fAvORWEjnjsEIvml59M7Y5kCkWN6fCCyPOe8OL6Q==", + "dev": true, + "engines": { + "node": ">=12", + "npm": ">=6" + }, + "peerDependencies": { + "@testing-library/dom": ">=7.21.4" + } + }, "node_modules/@tootallnate/once": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", @@ -12438,6 +12453,15 @@ "integrity": "sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==", "dev": true }, + "node_modules/jest-localstorage-mock": { + "version": "2.4.26", + "resolved": "https://registry.npmjs.org/jest-localstorage-mock/-/jest-localstorage-mock-2.4.26.tgz", + "integrity": "sha512-owAJrYnjulVlMIXOYQIPRCCn3MmqI3GzgfZCXdD3/pmwrIvFMXcKVWZ+aMc44IzaASapg0Z4SEFxR+v5qxDA2w==", + "dev": true, + "engines": { + "node": ">=6.16.0" + } + }, "node_modules/jest-matcher-utils": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-29.7.0.tgz", diff --git a/package.json b/package.json index ba6774eeb..48b7a6b69 100644 --- a/package.json +++ b/package.json @@ -35,14 +35,16 @@ "devDependencies": { "@edx/brand": "npm:@openedx/brand-openedx@^1.2.2", "@edx/browserslist-config": "1.2.0", - "@openedx/frontend-build": "14.0.3", - "@openedx/paragon": "22.3.2", + "@openedx/frontend-build": "github:edunext/frontend-build#dcoa/design-tokens-support", + "@openedx/paragon": "npm:@openedx/paragon@^22.0.0-alpha.25", "@testing-library/jest-dom": "6.4.5", "@testing-library/react": "12.1.5", "@testing-library/react-hooks": "^8.0.1", + "@testing-library/user-event": "14.4.3", "axios-mock-adapter": "^1.21.3", "core-js": "3.37.0", "husky": "8.0.3", + "jest-localstorage-mock": "^2.4.26", "jsdoc": "^4.0.0", "nodemon": "3.1.0", "prop-types": "15.8.1", diff --git a/src/react/AppProvider.test.jsx b/src/react/AppProvider.test.jsx index 71f076392..f82cceafa 100644 --- a/src/react/AppProvider.test.jsx +++ b/src/react/AppProvider.test.jsx @@ -2,7 +2,7 @@ import React from 'react'; import { createStore } from 'redux'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import '@testing-library/jest-dom/extend-expect'; +import '@testing-library/jest-dom'; import AppProvider from './AppProvider'; import { initialize } from '../initialize'; @@ -32,6 +32,7 @@ jest.mock('../config', () => ({ REFRESH_ACCESS_TOKEN_ENDPOINT: 'localhost:18000/oauth2/access_token', ACCESS_TOKEN_COOKIE_NAME: 'access_token', CSRF_TOKEN_API_PATH: 'localhost:18000/csrf', + PUBLIC_PATH: '/', }), })); diff --git a/src/react/hooks/paragon/useParagonThemeCore.js b/src/react/hooks/paragon/useParagonThemeCore.js index f1090d52e..d3b5983bb 100644 --- a/src/react/hooks/paragon/useParagonThemeCore.js +++ b/src/react/hooks/paragon/useParagonThemeCore.js @@ -34,8 +34,9 @@ const useParagonThemeCore = ({ setIsBrandThemeCoreLoaded(true); return; } - const getParagonThemeCoreLink = () => document.head.querySelector('link[data-paragon-theme-core="true"'); + const getParagonThemeCoreLink = () => document.head.querySelector('link[data-paragon-theme-core="true"]'); const existingCoreThemeLink = document.head.querySelector(`link[href='${themeCore.urls.default}']`); + const brandCoreLink = document.head.querySelector(`link[href='${themeCore.urls.brandOverride}']`); if (!existingCoreThemeLink) { const getExistingCoreThemeLinks = (isBrandOverride) => { const coreThemeLinkSelector = `link[data-${isBrandOverride ? 'brand' : 'paragon'}-theme-core="true"]`; @@ -126,6 +127,15 @@ const useParagonThemeCore = ({ } else { setIsBrandThemeCoreLoaded(true); } + } else { + existingCoreThemeLink.rel = 'stylesheet'; + existingCoreThemeLink.removeAttribute('as'); + if (brandCoreLink) { + brandCoreLink.rel = 'stylesheet'; + brandCoreLink.removeAttribute('as'); + } + setIsParagonThemeCoreLoaded(true); + setIsBrandThemeCoreLoaded(true); } }, [themeCore?.urls, onLoad]); }; diff --git a/src/react/hooks/paragon/useParagonThemeVariants.js b/src/react/hooks/paragon/useParagonThemeVariants.js index efb8ef4c5..737129ef9 100644 --- a/src/react/hooks/paragon/useParagonThemeVariants.js +++ b/src/react/hooks/paragon/useParagonThemeVariants.js @@ -187,7 +187,13 @@ const useParagonThemeVariants = ({ } else { const updatedStylesheetRel = generateStylesheetRelAttr(themeVariant); existingThemeVariantLink.rel = updatedStylesheetRel; - existingThemeVariantBrandLink.rel = updatedStylesheetRel; + existingThemeVariantLink.removeAttribute('as'); + if (existingThemeVariantBrandLink) { + existingThemeVariantBrandLink.rel = updatedStylesheetRel; + existingThemeVariantBrandLink.removeAttribute('as'); + } + setIsParagonThemeVariantLoaded(true); + setIsBrandThemeVariantLoaded(true); } }); }, [themeVariants, currentThemeVariant, onLoad]); diff --git a/src/setupTest.js b/src/setupTest.js index 82d22731d..081f09e84 100644 --- a/src/setupTest.js +++ b/src/setupTest.js @@ -2,6 +2,7 @@ import 'core-js/stable'; import 'regenerator-runtime/runtime'; import '@testing-library/jest-dom'; +import 'jest-localstorage-mock'; // These configuration values are usually set in webpack's EnvironmentPlugin however // Jest does not use webpack so we need to set these so for testing