This file contains hidden or 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 hidden or 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: '[email protected]' | |
| } | |
| }); | |
| }); |
This file contains hidden or 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 = '[email protected]'; | |
| 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 hidden or 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: '[email protected]' | |
| }; | |
| (firebaseAuth.getAuth as any).mockReturnValue({ |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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); |
This file contains hidden or 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
| class MockAuth extends HTMLElement { | |
| constructor() { | |
| super(); | |
| authComponent = this; | |
| } | |
| isLoggedIn?() { | |
| return isLoggedIn; | |
| } |