Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Created October 5, 2023 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YonatanKra/a4c019b62f7ed7e59c50bb927ee53b06 to your computer and use it in GitHub Desktop.
Save YonatanKra/a4c019b62f7ed7e59c50bb927ee53b06 to your computer and use it in GitHub Desktop.
Tauri-demo: display alert when user logs in but not verified
it('should display an alert if user is logged in and email not verified', () => {
app.connectedCallback();
authComponent.isUserEmailVerified.mockReturnValue(false);
const spy = vi.spyOn(app, 'alert');
setLoginStatus(true);
expect(spy).toHaveBeenCalledWith({message: 'Please verify your email address', title: 'Email not verified'});
});
#setViewAccordingToUserStatus = () => {
const isAuthComponentSet = !!this.#authComponent!.isLoggedIn;
const isLoggedIn = isAuthComponentSet && this.#authComponent!.isLoggedIn?.();
const isUserEmailVerified = isAuthComponentSet && this.#authComponent!.isUserEmailVerified?.();
if (isLoggedIn && isUserEmailVerified === false) {
this.#authComponent!.logout();
this.alert({message: 'Please verify your email address', title: 'Email not verified'});
return;
}
if (!isAuthComponentSet || !isLoggedIn) {
this.#loginButton.setAttribute('slot', 'hidden');
this.#mainContent.innerHTML = `<yag-login></yag-login>`;
this.#setLoginListener();
} else {
this.#loginButton.setAttribute('slot', 'action-items');
this.#unsetLoginListener();
this.#mainContent.innerHTML = `<yag-greeter></yag-greeter>`;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment