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
describe('logout', () => { | |
let firebaseAuth: any; | |
beforeEach(async () => { | |
firebaseAuth = await import('firebase/auth'); | |
}); | |
it('should call firebase signOut', async () => { | |
auth.logout(); | |
expect(firebaseAuth.signOut).toHaveBeenCalledWith(firebaseAuth.getAuth()); |
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
import { Auth } from './auth'; | |
const COMPONENT_NAME = 'yag-test'; | |
vi.mock('firebase/auth', () => { | |
return { | |
getAuth: vi.fn().mockReturnValue({ | |
currentUser: null | |
}), | |
signInWithEmailAndPassword: vi.fn(), | |
fetchSignInMethodsForEmail: vi.fn(), |
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
it('should emit `user-status-change` event when login successful', async () => { | |
const firebaseAuth = await import('firebase/auth'); | |
(firebaseAuth.signInWithEmailAndPassword as any).mockImplementation(async () => { | |
(firebaseAuth.getAuth as any).mockReturnValue({ | |
currentUser: { | |
uid: '123', | |
email: 'test@test.com' | |
} | |
}); | |
}); |
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
it('should call `signInWithEmailAndPassword` with auth, email and password', async () => { | |
const email = 't@t.com'; | |
const password = '123456'; | |
const firebaseAuth = await import('firebase/auth'); | |
await auth.login(email, password); | |
expect(firebaseAuth.signInWithEmailAndPassword).toHaveBeenCalledWith(firebaseAuth.getAuth(), email, password); | |
}); |
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
it('should toggle `isLoggedIn` if login successful', async () => { | |
const firebaseAuth = await import('firebase/auth'); | |
(firebaseAuth.signInWithEmailAndPassword as any).mockImplementation(async () => { | |
const user = { | |
uid: '123', | |
email: 'test@test.com' | |
}; | |
(firebaseAuth.getAuth as any).mockReturnValue({ |
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
import { Firebase } from './firebase'; | |
describe('firebase', () => { | |
let firebase: Firebase; | |
beforeAll(() => { | |
vi.mock('firebase/app', () => { | |
return { | |
initializeApp: () => 'MockFirebaseApp' | |
} |
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
const numberInput = document.createElement('input'); | |
numberInput.type = 'number'; | |
export function getValidValue(value: string) { | |
if (!this.isUserInput) { | |
numberInput.value = value; | |
return numberInput.value; | |
} | |
if (value === '' || value === '-' || value === '.') { | |
return value; |
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
import { Auth } from './auth'; | |
describe('login', () => { | |
let auth: Auth; | |
beforeAll(() => { | |
customElements.define('yag-auth', Auth); | |
}); | |
beforeEach(() => { |
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
get #loginElement () { | |
return this.shadowRoot!.querySelector('yag-login') as HTMLElement; | |
} | |
#setLoginListener = () => { | |
this.#loginElement.addEventListener('login-attempt', this.#handleLoginAttempt); | |
} | |
#unsetLoginListener = () => { | |
this.#loginElement?.removeEventListener('login-attempt', this.#handleLoginAttempt); |
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
#handleLoginAttempt = (e: Event) => { | |
const { email, password } = (<CustomEvent>e).detail; | |
this.#authComponent?.login(email, password); | |
} | |
#setViewAccordingToUserStatus = () => { | |
if (!this.#authComponent!.isLoggedIn || this.#authComponent!.isLoggedIn?.() === false) { | |
this.shadowRoot!.innerHTML = `<yag-login></yag-login>`; | |
const loginElement = this.shadowRoot!.querySelector('yag-login') as HTMLElement; | |
loginElement.addEventListener('login-attempt', this.#handleLoginAttempt); |