Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChromaticPanic committed Jun 21, 2024
1 parent e538367 commit d01dca5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 32 deletions.
42 changes: 20 additions & 22 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HashRouter as Router, Route, Routes } from "react-router-dom";
import { useCallback, Fragment, useState, useEffect } from "react";
import { v4 as uuidv4 } from "uuid";
// import { v4 as uuidv4 } from "uuid";
import Cookies from "js-cookie";
import Navbar from "./components/header/navbar";
import Body from "./root/body";
Expand All @@ -19,7 +19,7 @@ function App({
height: window.innerHeight,
});
const [uuid, setUuid] = useState<string>("");
const [container_uuid, setContainerUuid] = useState<string>("");
// const [container_uuid, setContainerUuid] = useState<string>("");
const [creativeCommonsPopupOpen, setCreativeCommonsPopupOpen] =
useState<boolean>(false);
const [switchLanguage, setSwitchLanguage] = useState<boolean>(false);
Expand Down Expand Up @@ -48,24 +48,24 @@ function App({
}
}, []);

const createContainerUuid = useCallback((): void => {
// create a new uuid for user and set a cookie to remember it for 10 years (it is used to identify user container in azure storage)
const newUuid = uuidv4();
setContainerUuid(newUuid);
Cookies.set("container-uuid", newUuid, { expires: 365 * 10 });
}, []);
// const createContainerUuid = useCallback((): void => {
// // create a new uuid for user and set a cookie to remember it for 10 years (it is used to identify user container in azure storage)
// const newUuid = uuidv4();
// setContainerUuid(newUuid);
// Cookies.set("container-uuid", newUuid, { expires: 365 * 10 });
// }, []);

const getContainerUuid = useCallback((): void => {
// check if the user has already a uuid (cookie)
const existingUuid = Cookies.get("container-uuid") as string;
if (existingUuid !== undefined) {
setContainerUuid(existingUuid);
console.log("Existing Container UUID: " + existingUuid);
} else {
console.log("Creating new Container UUID");
createContainerUuid();
}
}, [createContainerUuid]);
// const getContainerUuid = useCallback((): void => {
// // check if the user has already a uuid (cookie)
// const existingUuid = Cookies.get("container-uuid") as string;
// if (existingUuid !== undefined) {
// setContainerUuid(existingUuid);
// console.log("Existing Container UUID: " + existingUuid);
// } else {
// console.log("Creating new Container UUID");
// createContainerUuid();
// }
// }, [createContainerUuid]);

// const handleSignIn = (): void => {
// setSignedIn(true);
Expand All @@ -89,9 +89,8 @@ function App({
// }, [signedIn]);

useEffect(() => {
getContainerUuid();
getCreativeCommonsAgreement();
}, [getContainerUuid, getCreativeCommonsAgreement]);
}, [getCreativeCommonsAgreement]);

useEffect(() => {
// update window size on resize
Expand Down Expand Up @@ -129,7 +128,6 @@ function App({
<Body
windowSize={windowSize}
uuid={uuid}
container_uuid={container_uuid}
creativeCommonsPopupOpen={creativeCommonsPopupOpen}
setCreativeCommonsPopupOpen={setCreativeCommonsPopupOpen}
handleCreativeCommonsAgreement={handleCreativeCommonsAgreement}
Expand Down
1 change: 1 addition & 0 deletions src/common/tests/api.test.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ describe("inferenceRequest", () => {
imageObject,
curDir,
uuid,
uuid,
),
).toEqual("data");
});
Expand Down
22 changes: 14 additions & 8 deletions src/common/tests/loadresultstocache.test.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ describe("loadResultsToCache", () => {
let inferenceData: ApiInferenceData = {
filename: "test",
imageId: "test",
inferenceId: "test",
inference_id: "test",
boxes: [
{
score: 0.1,
classId: "0",
label: "a",
boxId: "0",
box_id: "0",
object_type_id: "0",
box: {
topX: 1,
topY: 1,
Expand All @@ -42,7 +43,8 @@ describe("loadResultsToCache", () => {
score: 0.2,
classId: "1",
label: "b",
boxId: "1",
box_id: "1",
object_type_id: "1",
box: {
topX: 2,
topY: 2,
Expand All @@ -57,7 +59,8 @@ describe("loadResultsToCache", () => {
score: 0.3,
classId: "2",
label: "c",
boxId: "2",
box_id: "2",
object_type_id: "2",
box: {
topX: 3,
topY: 3,
Expand Down Expand Up @@ -92,13 +95,14 @@ describe("loadResultsToCache", () => {
inferenceData = {
filename: "test",
imageId: "test",
inferenceId: "test",
inference_id: "test",
boxes: [
{
score: 0.1,
classId: "0",
label: "a",
boxId: "0",
box_id: "0",
object_type_id: "0",
box: {
topX: 1,
topY: 1,
Expand All @@ -113,7 +117,8 @@ describe("loadResultsToCache", () => {
score: 0.2,
classId: "1",
label: "b",
boxId: "1",
box_id: "1",
object_type_id: "1",
box: {
topX: 2,
topY: 2,
Expand All @@ -128,7 +133,8 @@ describe("loadResultsToCache", () => {
score: 0.3,
classId: "2",
label: "c",
boxId: "2",
box_id: "2",
object_type_id: "2",
box: {
topX: 3,
topY: 3,
Expand Down
1 change: 0 additions & 1 deletion src/root/body/body.test.tsx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import Body from "./body";
import axios from "axios";
import { a } from "vitest/dist/suite-a18diDsI";

process.env.VITE_BACKEND_URL = "somebackendurl";

Expand Down
1 change: 0 additions & 1 deletion src/root/body/body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ interface params {
height: number;
};
uuid: string;
container_uuid: string;
creativeCommonsPopupOpen: boolean;
setCreativeCommonsPopupOpen: React.Dispatch<React.SetStateAction<boolean>>;
handleCreativeCommonsAgreement: (agree: boolean) => void;
Expand Down

0 comments on commit d01dca5

Please sign in to comment.