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
function setUserCreds(firebaseAuth: any, successful: boolean, user = { | |
uid: '123', | |
email: '[email protected]' | |
}) { | |
return async () => { | |
(firebaseAuth.getAuth as any).mockReturnValue({ | |
currentUser: successful ? user : null | |
}); | |
if (successful) firebaseAuth.authChangeCallback(); |
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
constructor() { | |
super(); | |
onAuthStateChanged(getAuth(), () => this.dispatchEvent(new CustomEvent('user-status-change'))); | |
} |
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
function setLogin(firebaseAuth: any, successful: boolean) { | |
(firebaseAuth.signInWithEmailAndPassword as any).mockImplementation(async () => { | |
const user = { | |
uid: '123', | |
email: '[email protected]' | |
}; | |
(firebaseAuth.getAuth as any).mockReturnValue({ | |
currentUser: successful ? user : null | |
}); |
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 `logout` on auth component when logout button is clicked', () => { | |
isLoggedIn = true; | |
app.connectedCallback(); | |
getLogoutButton()?.dispatchEvent(new CustomEvent('click')); | |
expect(authComponent.logout).toHaveBeenCalled(); | |
}); |
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
describe('logout button', () => { | |
it('should add a logout button to the header when user is logged in', () => { | |
isLoggedIn = true; | |
app.connectedCallback(); | |
expect(isLoginButtonVisible()).toBe(true); | |
}); | |
it('should remove the logout button from the header when user is logged out', () => { | |
isLoggedIn = true; | |
app.connectedCallback(); |
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
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 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({ |