Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions front/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "regenerator-runtime/runtime";
import { ReactElement, Suspense, useEffect, useRef, useState } from "react";
import { ReactElement, Suspense, useEffect, useState } from "react";
import { Navigate, Outlet, Route, Routes, useLocation } from "react-router-dom";
import { useLoadAndSetGlobalPreferences } from "hooks/useLoadAndSetGlobalPreferences";
import Layout from "components/Layout";
Expand Down Expand Up @@ -100,9 +100,6 @@ function App() {
const { error, isInitialized } = useLoadAndSetGlobalPreferences();
const location = useLocation();
const [prevLocation, setPrevLocation] = useState<string | undefined>(undefined);
// For BoxesView to reduce number of expensive Boxes queries
// when navigating between boxes and other views.
const hasExecutedInitialFetchOfBoxes = useRef(false);

// store previous location to return to if you are not authorized
useEffect(() => {
Expand Down Expand Up @@ -155,7 +152,7 @@ function App() {
}
>
<Suspense fallback={<TableSkeleton />}>
<Boxes hasExecutedInitialFetchOfBoxes={hasExecutedInitialFetchOfBoxes} />
<Boxes />
</Suspense>
</ErrorBoundary>
}
Expand Down
129 changes: 32 additions & 97 deletions front/src/views/Boxes/BoxesView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ const boxesQuery = ({
boxes: {
__typename: "BoxPage",
elements:
state === "InStock" && state2 === "Scrap"
? [instockBox1, instockBox2, scrapBox]
: state === "InStock"
? [instockBox1, instockBox2]
: state === "Scrap"
? [scrapBox]
: state === "Donated"
? []
: [],
state === "ALL"
? [instockBox1, instockBox2]
: state === "InStock" && state2 === "Scrap"
? [instockBox1, instockBox2, scrapBox]
: state === "InStock"
? [instockBox1, instockBox2]
: state === "Scrap"
? [scrapBox]
: state === "Donated"
? []
: [],
pageInfo: {
__typename: "PageInfo",
hasNextPage: false,
Expand Down Expand Up @@ -301,19 +303,13 @@ describe("4.8.1 - Initial load of Page", () => {
}
>
<Suspense fallback={<TableSkeleton />}>
<Boxes hasExecutedInitialFetchOfBoxes={{ current: false }} />
<Boxes />
</Suspense>
</ErrorBoundary>,
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?state_ids=1",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ state: "InStock", paginationInput: 50 }),
boxesQuery({ state: "InStock" }),
actionsQuery,
],
mocks: [boxesQuery({ state: "InStock", paginationInput: 50 }), actionsQuery],
cache,
addTypename: true,
jotaiAtoms,
Expand All @@ -326,23 +322,11 @@ describe("4.8.1 - Initial load of Page", () => {
const failedInitialFetching = [
{
name: "4.8.1.2.2 - Failed to Fetch Initial Data",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
initialQueryGraphQLError({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
],
mocks: [initialQueryGraphQLError({ paginationInput: 50 }), actionsQuery],
},
{
name: "4.8.1.2.6 - Failed to Fetch Initial Data",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
initialQueryNetworkError({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
],
mocks: [initialQueryNetworkError({ paginationInput: 50 }), actionsQuery],
},
];

Expand All @@ -357,7 +341,7 @@ describe("4.8.1 - Initial load of Page", () => {
}
>
<Suspense fallback={<TableSkeleton />}>
<Boxes hasExecutedInitialFetchOfBoxes={{ current: false }} />
<Boxes />
</Suspense>
</ErrorBoundary>,
{
Expand Down Expand Up @@ -390,19 +374,13 @@ describe("4.8.1 - Initial load of Page", () => {
}
>
<Suspense fallback={<TableSkeleton />}>
<Boxes hasExecutedInitialFetchOfBoxes={{ current: false }} />
<Boxes />
</Suspense>
</ErrorBoundary>,
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?state_ids=1",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
],
mocks: [boxesQuery({ paginationInput: 50 }), actionsQuery],
cache,
addTypename: true,
jotaiAtoms,
Expand All @@ -421,16 +399,14 @@ describe("4.8.1 - Initial load of Page", () => {
}
>
<Suspense fallback={<TableSkeleton />}>
<Boxes hasExecutedInitialFetchOfBoxes={{ current: false }} />
<Boxes />
</Suspense>
</ErrorBoundary>,
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?state_ids=1,6",
mocks: [
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ state: "InStock", state2: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "InStock", state2: "Scrap" }),
actionsQuery,
],
cache,
Expand Down Expand Up @@ -513,19 +489,13 @@ describe("4.8.1 - Initial load of Page", () => {
}
>
<Suspense fallback={<TableSkeleton />}>
<Boxes hasExecutedInitialFetchOfBoxes={{ current: false }} />
<Boxes />
</Suspense>
</ErrorBoundary>,
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?state_ids=1",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
],
mocks: [boxesQuery({ paginationInput: 50 }), actionsQuery],
cache,
addTypename: true,
jotaiAtoms,
Expand Down Expand Up @@ -641,20 +611,13 @@ describe("4.8.2 - Selecting rows and performing bulk actions", () => {
}
>
<Suspense fallback={<TableSkeleton />}>
<Boxes hasExecutedInitialFetchOfBoxes={{ current: false }} />
<Boxes />
</Suspense>
</ErrorBoundary>,
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?state_ids=1",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
moveBoxesMutation,
],
mocks: [boxesQuery({ paginationInput: 50 }), actionsQuery, moveBoxesMutation],
cache,
addTypename: true,
jotaiAtoms,
Expand Down Expand Up @@ -741,19 +704,13 @@ describe("4.8.2 - Selecting rows and performing bulk actions", () => {
}
>
<Suspense fallback={<TableSkeleton />}>
<Boxes hasExecutedInitialFetchOfBoxes={{ current: false }} />
<Boxes />
</Suspense>
</ErrorBoundary>,
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?state_ids=1",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
],
mocks: [boxesQuery({ paginationInput: 50 }), actionsQuery],
cache,
addTypename: true,
jotaiAtoms,
Expand Down Expand Up @@ -814,19 +771,13 @@ describe("4.8.3 - URL Parameter Sync for Filters", () => {
}
>
<Suspense fallback={<TableSkeleton />}>
<Boxes hasExecutedInitialFetchOfBoxes={{ current: false }} />
<Boxes />
</Suspense>
</ErrorBoundary>,
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?state_ids=1",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
],
mocks: [boxesQuery({ paginationInput: 50 }), actionsQuery],
cache,
addTypename: true,
jotaiAtoms,
Expand All @@ -852,20 +803,13 @@ describe("4.8.3 - URL Parameter Sync for Filters", () => {
}
>
<Suspense fallback={<TableSkeleton />}>
<Boxes hasExecutedInitialFetchOfBoxes={{ current: false }} />
<Boxes />
</Suspense>
</ErrorBoundary>,
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?state_ids=999", // Invalid state ID
mocks: [
boxesQuery({ state: "ALL", paginationInput: 50 }),
boxesQuery({ state: "ALL" }),
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ paginationInput: 50 }),
actionsQuery,
],
mocks: [boxesQuery({ state: "ALL", paginationInput: 50 }), actionsQuery],
cache,
addTypename: true,
jotaiAtoms,
Expand All @@ -885,19 +829,13 @@ describe("4.8.3 - URL Parameter Sync for Filters", () => {
}
>
<Suspense fallback={<TableSkeleton />}>
<Boxes hasExecutedInitialFetchOfBoxes={{ current: false }} />
<Boxes />
</Suspense>
</ErrorBoundary>,
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?product_ids=267&state_ids=1",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
],
mocks: [boxesQuery({ paginationInput: 50 }), actionsQuery],
cache,
addTypename: true,
jotaiAtoms,
Expand Down Expand Up @@ -925,17 +863,14 @@ describe("4.8.3 - URL Parameter Sync for Filters", () => {
}
>
<Suspense fallback={<TableSkeleton />}>
<Boxes hasExecutedInitialFetchOfBoxes={{ current: false }} />
<Boxes />
</Suspense>
</ErrorBoundary>,
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?product_ids=267,350&state_ids=1,5",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ state: "InStock", state2: "Donated", paginationInput: 50 }),
boxesQuery({ state: "InStock", state2: "Donated" }),
actionsQuery,
],
cache,
Expand Down
Loading
Loading