Merge branch 'develop' into rc

* develop:
  bump version number
  tests: fix firestore not authenticating
  fix rowActions expecting ID- sorted rows from db
This commit is contained in:
Sidney Alcantara
2022-06-16 14:50:51 +10:00
6 changed files with 60 additions and 35 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "rowy",
"version": "2.6.0-rc.0",
"version": "2.6.0",
"homepage": "https://rowy.io",
"repository": {
"type": "git",

View File

@@ -2,7 +2,7 @@ import { useCallback } from "react";
import { renderHook, act } from "@testing-library/react";
import { useAtomValue, useSetAtom } from "jotai";
import { useAtomCallback } from "jotai/utils";
import { find, findIndex } from "lodash-es";
import { find, findIndex, sortBy } from "lodash-es";
import { currentUserAtom } from "@src/atoms/globalScope";
import {
@@ -60,12 +60,15 @@ const initRows = (
setRowsDb((rows) => {
const index = findIndex(rows, ["_rowy_ref.path", path]);
// Append if not found
// Append if not found and sort by ID
if (index === -1) {
return [
...rows,
{ ...update, _rowy_ref: { id: path.split("/").pop()!, path } },
];
return sortBy(
[
...rows,
{ ...update, _rowy_ref: { id: path.split("/").pop()!, path } },
],
["_rowy_ref.id"]
);
}
rows[index] = updateRowData(rows[index], update);

View File

@@ -100,7 +100,7 @@ function JotaiTest() {
{currentUser && <CurrentUser currentUser={currentUser} />}
<p>{JSON.stringify(userRoles)}</p>
<p>{projectId}</p>
<p>Project: {projectId}</p>
<p>{JSON.stringify(publicSettings)}</p>
<p>{JSON.stringify(projectSettings)}</p>
<p>{JSON.stringify(userSettings)}</p>

33
src/test/App.test.tsx Normal file
View File

@@ -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(<JotaiTestPage />);
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(<App />, 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")

View File

@@ -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(<JotaiTest />);
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(<App />, 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")

View File

@@ -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(
<Providers initialAtomValues={initialAtomValues}>
<ProjectSourceFirebase />
{!disableProjectSource && <ProjectSourceFirebase />}
{ui}
</Providers>
);
@@ -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;