-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(Portal): eliminate flickering on theme switch (#2281)
- Loading branch information
1 parent
2e3d790
commit 02656a7
Showing
17 changed files
with
280 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
packages/dnb-design-system-portal/cypress/e2e/themeSwitch.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Cypress e2e Test | ||
* | ||
*/ | ||
|
||
describe('Theme', () => { | ||
beforeEach(() => { | ||
cy.visit('/uilib?data-visual-test') // skip animation | ||
|
||
// Check if app is mounted | ||
cy.get('#dnb-drawer-list__portal', { timeout: 10000 }).should('exist') | ||
}) | ||
|
||
afterEach(() => { | ||
cy.clearLocalStorage('eufemia-theme') | ||
}) | ||
|
||
it('should have preload link', () => { | ||
cy.get('link[href^="/ui."][rel="preload"]') | ||
.should('exist') | ||
.its('length') | ||
.should('equal', 1) | ||
}) | ||
|
||
it('should load css file', () => { | ||
cy.get('#portal-tools').click() | ||
|
||
// Choose last one | ||
cy.get('#change-theme').click() | ||
cy.get('#change-theme-portal ul li').eq(2).click() | ||
|
||
cy.get('link[href^="/sbanken."]', { timeout: 10000 }) | ||
.should('exist') | ||
.its('length') | ||
.should('equal', 1) | ||
}) | ||
|
||
it('should set local storage', () => { | ||
cy.get('#portal-tools').click() | ||
|
||
// Choose last one | ||
cy.get('#change-theme').click() | ||
cy.get('#change-theme-portal ul li').eq(2).click() | ||
|
||
cy.getAllLocalStorage().then((result) => { | ||
expect(Object.values(result)[0]['eufemia-theme']).to.equal( | ||
'{"name":"sbanken"}' | ||
) | ||
}) | ||
}) | ||
|
||
it('should switch back and forth', () => { | ||
cy.get('#portal-tools').click() | ||
|
||
// Choose last one | ||
cy.get('#change-theme').click() | ||
cy.get('#change-theme-portal ul li').eq(2).click() | ||
|
||
// Choose first one again | ||
cy.get('#change-theme').click() | ||
cy.get('#change-theme-portal ul li').eq(0).click() | ||
|
||
cy.get('link[href^="/ui."][rel="stylesheet"]', { timeout: 10000 }) | ||
.should('exist') | ||
.its('length') | ||
.should('equal', 1) | ||
}) | ||
|
||
it('should load css file after template', () => { | ||
cy.get('#portal-tools').click() | ||
|
||
// Choose last one | ||
cy.get('#change-theme').click() | ||
cy.get('#change-theme-portal ul li').eq(2).click() | ||
|
||
cy.get( | ||
'#eufemia-style-theme + link[href^="/sbanken."][rel="stylesheet"]', | ||
{ timeout: 10000 } | ||
).should('exist') | ||
|
||
// Choose first one again | ||
cy.get('#change-theme').click() | ||
cy.get('#change-theme-portal ul li').eq(0).click() | ||
|
||
cy.get('#eufemia-style-theme + link[href^="/ui."][rel="stylesheet"]', { | ||
timeout: 10000, | ||
}).should('exist') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module '!raw-loader!terser-loader!*' { | ||
const contents: string | ||
export = contents | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
51 changes: 0 additions & 51 deletions
51
packages/gatsby-plugin-eufemia-theme-handler/inlineScriptDev.js
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
packages/gatsby-plugin-eufemia-theme-handler/inlineScriptDev.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
if (typeof window !== 'undefined') { | ||
try { | ||
const headElement = document.querySelector('html head') | ||
const logMutations = (mutations) => { | ||
for (const mutation of mutations) { | ||
const element = mutation.nextSibling | ||
if ( | ||
element && | ||
(element.src || element.href || '').includes('/commons.') | ||
) { | ||
const themeName = globalThis.__getEufemiaThemeName() | ||
globalThis.__updateEufemiaThemeFile(themeName, true) | ||
break | ||
} | ||
} | ||
} | ||
|
||
const observer = new MutationObserver(logMutations) | ||
observer.observe(headElement, { childList: true }) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
} |
70 changes: 0 additions & 70 deletions
70
packages/gatsby-plugin-eufemia-theme-handler/inlineScriptProd.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.