Skip to content

Commit

Permalink
fix: issue7026 RELEASE (#702)
Browse files Browse the repository at this point in the history
## Related Issues

Fixes descope/etc#7026
  • Loading branch information
nirgur authored Jul 11, 2024
1 parent 73b3af1 commit 7ea3b2c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,10 @@ class BaseDescopeWc extends HTMLElement {
});

this.#debugState.update({ isDebug: this.debug });

if (attrName === 'theme') {
this.#applyTheme();
}
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions packages/sdks/web-component/test/descope-wc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,37 @@ describe('web-component', () => {
pageContent = '';
});

it('should switch theme on the fly', async () => {
startMock.mockReturnValue(generateSdkResponse());

pageContent = '<button id="email">Button</button><span>It works!</span>';

const DescopeUI = {
componentsThemeManager: { currentThemeName: undefined },
};
globalThis.DescopeUI = DescopeUI;

document.body.innerHTML = `<h1>Custom element test</h1> <descope-wc theme="light" flow-id="otpSignInEmail" project-id="1"></descope-wc>`;

await waitFor(() => screen.getByShadowText('Button'), {
timeout: WAIT_TIMEOUT,
});

const wc = document.querySelector('descope-wc');
wc.setAttribute('theme', 'dark');

const rootEle = wc.shadowRoot.querySelector('#wc-root');

await waitFor(
() =>
expect(DescopeUI.componentsThemeManager.currentThemeName).toBe('dark'),
{ timeout: 3000 },
);
await waitFor(() => expect(rootEle).toHaveAttribute('data-theme', 'dark'), {
timeout: 3000,
});
}, 5000);

it('should clear the flow query params after render', async () => {
window.location.search = `?${URL_RUN_IDS_PARAM_NAME}=0_1&code=123456`;
nextMock.mockReturnValue(generateSdkResponse({}));
Expand Down

0 comments on commit 7ea3b2c

Please sign in to comment.