Skip to content

Commit ad586e7

Browse files
committed
Merge branch 'develop' into rc
2 parents 40e259e + 633106c commit ad586e7

File tree

4 files changed

+88
-31
lines changed

4 files changed

+88
-31
lines changed

src/components/ColumnMenu/ColumnMenu.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
columnMenuAtom,
5050
columnModalAtom,
5151
tableFiltersPopoverAtom,
52+
tableNextPageAtom,
5253
} from "@src/atoms/tableScope";
5354
import { FieldType } from "@src/constants/fields";
5455
import { getFieldProp } from "@src/components/fields";
@@ -89,6 +90,8 @@ export default function ColumnMenu() {
8990
tableFiltersPopoverAtom,
9091
tableScope
9192
);
93+
const [tableNextPage] = useAtom(tableNextPageAtom, tableScope);
94+
9295
const [altPress] = useAtom(altPressAtom, globalScope);
9396
const { enqueueSnackbar, closeSnackbar } = useSnackbar();
9497

@@ -305,7 +308,15 @@ export default function ColumnMenu() {
305308
: () =>
306309
confirm({
307310
title: "Evaluate all?",
308-
body: "All rows will be evaluated. This may take a while.",
311+
body: (
312+
<>
313+
All documents in {tableSettings.collection} collection will be
314+
evaluated.
315+
<br />{" "}
316+
{tableNextPage.available &&
317+
"For large collections this will take a while and might incur significant firestore costs."}
318+
</>
319+
),
309320
handleConfirm: handleEvaluateAll,
310321
}),
311322
},

src/components/fields/Markdown/SideDrawerField.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export default function Markdown({
2020
sx={[fieldSx, { display: "block", maxHeight: 300, overflow: "auto" }]}
2121
data-color-mode={theme.palette.mode}
2222
>
23-
<MDEditor.Markdown source={value} />
23+
<MDEditor.Markdown
24+
source={value}
25+
style={{ backgroundColor: theme.palette.background.paper }}
26+
/>
2427
</Box>
2528
);
2629

@@ -37,6 +40,7 @@ export default function Markdown({
3740
data-color-mode={theme.palette.mode}
3841
>
3942
<MDEditor
43+
style={{ backgroundColor: theme.palette.background.paper }}
4044
height={300}
4145
value={value}
4246
onChange={onChange}

src/test/App.test.tsx

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import { customRender, signInAsAdmin } from "./testUtils";
2-
import { screen, renderHook } from "@testing-library/react";
3-
import { useAtom, useSetAtom } from "jotai";
1+
import { customRender, signIn } from "./testUtils";
2+
import { screen, fireEvent } from "@testing-library/react";
43

54
import App from "@src/App";
65
import JotaiTestPage from "@src/pages/Test/JotaiTestPage";
76

8-
import { globalScope, currentUserAtom } from "@src/atoms/globalScope";
9-
107
test("renders without crashing", async () => {
118
customRender(<JotaiTestPage />);
129
expect(await screen.findByText(/Sign in with Google/i)).toBeInTheDocument();
@@ -16,18 +13,53 @@ test("renders without crashing", async () => {
1613
).toBeGreaterThan(0);
1714
});
1815

19-
test("signs in", async () => {
20-
const initialAtomValues = await signInAsAdmin();
16+
describe("sign in with roles", () => {
17+
test("signs in as admin", async () => {
18+
customRender(<App />, await signIn("admin"), true);
19+
expect((await screen.findAllByText(/tables/i)).length).toBeGreaterThan(0);
2120

22-
customRender(<App />, initialAtomValues, true);
23-
// const {
24-
// result: { current: currentUser },
25-
// } = renderHook(() => useSetAtom(currentUserAtom, globalScope));
26-
// expect(currentUser).toBeDefined();
21+
const userMenuButton = screen.getByLabelText("Open user menu");
22+
expect(userMenuButton).toBeInTheDocument();
23+
fireEvent.click(userMenuButton);
24+
expect(await screen.findByText(/admin@example.com/i)).toBeInTheDocument();
25+
});
2726

28-
// expect(await screen.findByText(/Loading/i)).toBeInTheDocument();
29-
expect((await screen.findAllByText(/tablesd/i)).length).toBeGreaterThan(0);
30-
});
27+
test("signs in as ops", async () => {
28+
customRender(<App />, await signIn("ops"), true);
29+
expect((await screen.findAllByText(/tables/i)).length).toBeGreaterThan(0);
30+
31+
const userMenuButton = screen.getByLabelText("Open user menu");
32+
expect(userMenuButton).toBeInTheDocument();
33+
fireEvent.click(userMenuButton);
34+
expect(await screen.findByText(/ops@example.com/i)).toBeInTheDocument();
35+
});
36+
37+
test("signs in as editor", async () => {
38+
customRender(<App />, await signIn("editor"), true);
39+
expect((await screen.findAllByText(/tables/i)).length).toBeGreaterThan(0);
40+
41+
const userMenuButton = screen.getByLabelText("Open user menu");
42+
expect(userMenuButton).toBeInTheDocument();
43+
fireEvent.click(userMenuButton);
44+
expect(await screen.findByText(/editor@example.com/i)).toBeInTheDocument();
45+
});
3146

32-
// TODO:
33-
// test("signs in without roles in auth")
47+
test("signs in as viewer", async () => {
48+
customRender(<App />, await signIn("viewer"), true);
49+
expect((await screen.findAllByText(/tables/i)).length).toBeGreaterThan(0);
50+
51+
const userMenuButton = screen.getByLabelText("Open user menu");
52+
expect(userMenuButton).toBeInTheDocument();
53+
fireEvent.click(userMenuButton);
54+
expect(await screen.findByText(/viewer@example.com/i)).toBeInTheDocument();
55+
});
56+
57+
test("signs in with no roles", async () => {
58+
customRender(<App />, await signIn("noRoles"), true);
59+
60+
expect(await screen.findByText(/Access denied/i)).toBeInTheDocument();
61+
expect(
62+
await screen.findByText(/Your account has no roles set/i)
63+
).toBeInTheDocument();
64+
});
65+
});

src/test/testUtils.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { initializeApp } from "firebase/app";
33
import {
44
getAuth,
55
connectAuthEmulator,
6+
signOut,
67
signInWithEmailAndPassword,
78
} from "firebase/auth";
89
import {
@@ -21,6 +22,14 @@ import {
2122
} from "@src/sources/ProjectSourceFirebase";
2223
import { currentUserAtom } from "@src/atoms/globalScope";
2324

25+
/** Initialize Firebase */
26+
console.log("Initializing Firebase...");
27+
const app = initializeApp(envConfig);
28+
const auth = getAuth(app);
29+
connectAuthEmulator(auth, "http://localhost:9099", { disableWarnings: true });
30+
const db = initializeFirestore(app, { ignoreUndefinedProperties: true });
31+
connectFirestoreEmulator(db, "localhost", 9299);
32+
2433
/**
2534
* Render with Jotai `globalScope` providers
2635
* & `ProjectSourceFirebase` component
@@ -38,25 +47,26 @@ export const customRender = (
3847
);
3948

4049
/**
41-
* Signs in with Google as an admin: admin(at)example.com
50+
* Signs in with email and password.
4251
* Returns `initialAtomValues`, which must be passed to `customRender`.
4352
*/
44-
export const signInAsAdmin = async () => {
45-
const app = initializeApp(envConfig);
46-
const auth = getAuth(app);
47-
connectAuthEmulator(auth, "http://localhost:9099", { disableWarnings: true });
48-
const db = initializeFirestore(app, { ignoreUndefinedProperties: true });
49-
connectFirestoreEmulator(db, "localhost", 9299);
53+
export const signIn = async (
54+
userType: "admin" | "ops" | "editor" | "viewer" | "noRoles"
55+
) => {
56+
await signOut(auth);
5057

5158
const userCredential = await signInWithEmailAndPassword(
5259
auth,
53-
54-
"adminUser"
60+
`${userType}@example.com`,
61+
`${userType}User`
62+
);
63+
expect(userCredential.user.email?.toLowerCase()).toBe(
64+
`${userType}@example.com`.toLowerCase()
5565
);
56-
expect(userCredential.user.email).toBe("[email protected]");
5766

5867
const tokenResult = await userCredential.user.getIdTokenResult();
59-
expect(tokenResult.claims.roles).toContain("ADMIN");
68+
if (userType === "noRoles") expect(tokenResult.claims.roles).toBeUndefined();
69+
else expect(tokenResult.claims.roles).toContain(userType.toUpperCase());
6070

6171
const initialAtomValues = [
6272
[firebaseConfigAtom, envConfig],
@@ -69,7 +79,7 @@ export const signInAsAdmin = async () => {
6979
return initialAtomValues;
7080
};
7181

72-
// Suppress Jotai warning about setting an initial value for derived atoms
82+
/** Suppress Jotai warning about setting an initial value for derived atoms */
7383
const realConsoleWarn = console.warn.bind(console.warn);
7484
beforeAll(() => {
7585
console.warn = (msg) =>

0 commit comments

Comments
 (0)