diff --git a/src/pages/Test/JotaiTestPage.tsx b/src/pages/Test/JotaiTestPage.tsx index 96ada5e6..3f932733 100644 --- a/src/pages/Test/JotaiTestPage.tsx +++ b/src/pages/Test/JotaiTestPage.tsx @@ -100,7 +100,7 @@ function JotaiTest() { {currentUser && }

{JSON.stringify(userRoles)}

-

{projectId}

+

Project: {projectId}

{JSON.stringify(publicSettings)}

{JSON.stringify(projectSettings)}

{JSON.stringify(userSettings)}

diff --git a/src/test/App.test.tsx b/src/test/App.test.tsx new file mode 100644 index 00000000..387dede3 --- /dev/null +++ b/src/test/App.test.tsx @@ -0,0 +1,33 @@ +import { customRender, signInAsAdmin } from "./testUtils"; +import { screen, renderHook } from "@testing-library/react"; +import { useAtom, useSetAtom } from "jotai"; + +import App from "@src/App"; +import JotaiTestPage from "@src/pages/Test/JotaiTestPage"; + +import { globalScope, currentUserAtom } from "@src/atoms/globalScope"; + +test("renders without crashing", async () => { + customRender(); + expect(await screen.findByText(/Sign in with Google/i)).toBeInTheDocument(); + expect(await screen.findByText(/Authenticating/i)).toBeInTheDocument(); + expect( + (await screen.findAllByText(/Project: rowy-testing/i)).length + ).toBeGreaterThan(0); +}); + +test("signs in", async () => { + const initialAtomValues = await signInAsAdmin(); + + customRender(, initialAtomValues, true); + // const { + // result: { current: currentUser }, + // } = renderHook(() => useSetAtom(currentUserAtom, globalScope)); + // expect(currentUser).toBeDefined(); + + // expect(await screen.findByText(/Loading/i)).toBeInTheDocument(); + expect((await screen.findAllByText(/tablesd/i)).length).toBeGreaterThan(0); +}); + +// TODO: +// test("signs in without roles in auth") diff --git a/src/test/App.test.tsx.disabled b/src/test/App.test.tsx.disabled deleted file mode 100644 index 9d709606..00000000 --- a/src/test/App.test.tsx.disabled +++ /dev/null @@ -1,24 +0,0 @@ -import { customRender, signInAsAdmin } from "./testUtils"; -import { screen } from "@testing-library/react"; - -import App from "@src/App"; -import JotaiTest from "@src/pages/JotaiTest"; - -test("renders without crashing", async () => { - customRender(); - expect(await screen.findByText(/Sign in with Google/i)).toBeInTheDocument(); - expect(await screen.findByText(/{"emulator":true}/i)).toBeInTheDocument(); -}); - -// test("signs in", async () => { -// const initialAtomValues = await signInAsAdmin(); - -// customRender(, initialAtomValues); - -// expect(await screen.findByText(/Loading/i)).toBeInTheDocument(); -// // expect(await screen.findByText(/Nav/i)).toBeInTheDocument(); -// expect(await screen.findByText(/{"emulator":true}/i)).toBeInTheDocument(); -// }); - -// TODO: -// test("signs in without roles in auth") diff --git a/src/test/testUtils.tsx b/src/test/testUtils.tsx index e6801f8c..3f5cb291 100644 --- a/src/test/testUtils.tsx +++ b/src/test/testUtils.tsx @@ -5,12 +5,19 @@ import { connectAuthEmulator, signInWithEmailAndPassword, } from "firebase/auth"; +import { + initializeFirestore, + connectFirestoreEmulator, +} from "firebase/firestore"; import Providers, { IProvidersProps } from "@src/Providers"; import ProjectSourceFirebase from "@src/sources/ProjectSourceFirebase"; import { envConfig, + firebaseConfigAtom, + firebaseAppAtom, firebaseAuthAtom, + firebaseDbAtom, } from "@src/sources/ProjectSourceFirebase"; import { currentUserAtom } from "@src/atoms/globalScope"; @@ -20,11 +27,12 @@ import { currentUserAtom } from "@src/atoms/globalScope"; */ export const customRender = ( ui: React.ReactElement, - initialAtomValues?: IProvidersProps["initialAtomValues"] + initialAtomValues?: IProvidersProps["initialAtomValues"], + disableProjectSource: boolean = false ) => render( - + {!disableProjectSource && } {ui} ); @@ -37,6 +45,8 @@ export const signInAsAdmin = async () => { const app = initializeApp(envConfig); const auth = getAuth(app); connectAuthEmulator(auth, "http://localhost:9099", { disableWarnings: true }); + const db = initializeFirestore(app, { ignoreUndefinedProperties: true }); + connectFirestoreEmulator(db, "localhost", 9299); const userCredential = await signInWithEmailAndPassword( auth, @@ -49,8 +59,11 @@ export const signInAsAdmin = async () => { expect(tokenResult.claims.roles).toContain("ADMIN"); const initialAtomValues = [ + [firebaseConfigAtom, envConfig], + [firebaseAppAtom, app], [firebaseAuthAtom, auth], - // [currentUserAtom, userCredential.user], + [firebaseDbAtom, db], + [currentUserAtom, userCredential.user], ] as const; return initialAtomValues;