diff --git a/src/Functions/Chat/getChat.jsx b/src/Functions/Chat/getChat.jsx
index 7acd9eb..f8cc6a1 100644
--- a/src/Functions/Chat/getChat.jsx
+++ b/src/Functions/Chat/getChat.jsx
@@ -1,20 +1,21 @@
import axios from "axios";
import { apis } from "../../assets/apis";
+import { returnToken } from "../returnToken";
export async function getChat(setValue, username, setLoading, setInfo) {
console.log("🚀 ~ getChat ~ username:", username)
- const token = JSON.parse(localStorage.getItem("authTokens")).token.access;
- await axios(apis["chat"]["chatWith"]+username+"/", {
+ const token = returnToken();
+ await axios(apis["chat"]["chatWith"] + username + "/", {
headers: { Authorization: `Bearer ${token}` },
})
.then((data) => {
setValue((x) => {
- let val = data.data.messages.map((item,index) => {
+ let val = data.data.messages.map((item, index) => {
return { id: item.author, messageId: index, text: item.content };
});
return [...val.reverse()];
});
setLoading(false)
- setInfo({id:data.data.id, participants:data.data.participants})
+ setInfo({ id: data.data.id, participants: data.data.participants })
return data.data
})
.catch((error) => console.error(error));
diff --git a/src/Functions/Shopping/getCartInfo.jsx b/src/Functions/Shopping/getCartInfo.jsx
index c0fd01d..ef7df2b 100644
--- a/src/Functions/Shopping/getCartInfo.jsx
+++ b/src/Functions/Shopping/getCartInfo.jsx
@@ -1,15 +1,15 @@
import { apis } from "../../assets/apis";
+import { returnToken } from "../returnToken";
-
-export function getCartInfo(setState, setTotalPrice, setAmount,setLoading) {
- const token = JSON.parse(localStorage.getItem("authTokens")).token.access;
+export function getCartInfo(setState, setTotalPrice, setAmount, setLoading) {
+ const token = returnToken();
const shopId = JSON.parse(localStorage.getItem("shopId"));
fetch(apis["carts"], {
headers: { Authorization: `Bearer ${token}` },
})
.then((response) => response.json())
.then((data) => {
- setState(data.length >= 0? data[0].items:[]);
+ setState(data.length >= 0 ? data[0].items : []);
setTotalPrice(data.total_price);
setAmount(data.total_number);
setLoading(false);
diff --git a/src/Functions/Shopping/saveWallet.jsx b/src/Functions/Shopping/saveWallet.jsx
index a457af1..e2a91b4 100644
--- a/src/Functions/Shopping/saveWallet.jsx
+++ b/src/Functions/Shopping/saveWallet.jsx
@@ -1,13 +1,14 @@
import axios from "axios";
import { apis } from "../../assets/apis";
+import { returnToken } from "../returnToken";
export function saveWallet(setWallet) {
- const token = JSON.parse(localStorage.getItem("authTokens")).token.access;
- axios(apis["accounts"]["wallet"]["seeWallet"], {
- headers: { Authorization: `Bearer ${token}` },
+ const token = returnToken();
+ axios(apis["accounts"]["wallet"]["seeWallet"], {
+ headers: { Authorization: `Bearer ${token}` },
+ })
+ .then((data) => {
+ setWallet(data.balance);
})
- .then((data) => {
- setWallet(data.balance);
- })
- .catch((error) => console.error(error));
- }
\ No newline at end of file
+ .catch((error) => console.error(error));
+}
\ No newline at end of file
diff --git a/src/Functions/isValidPassword.test.jsx b/src/Functions/isValidPassword.test.jsx
new file mode 100644
index 0000000..dc1f6bd
--- /dev/null
+++ b/src/Functions/isValidPassword.test.jsx
@@ -0,0 +1,27 @@
+// import { describe, it, expect, vi, test } from "vitest";
+// import { Movies } from './Movies';
+// Imports
+
+import { describe, it, expect, vi, test } from 'vitest';
+import { render, screen } from '@testing-library/react';
+import isValidPassword from './isValidPassword';
+import * as Router from "react-router-dom";
+import ContextInfo from '../contexts/InfoContext';
+describe('Renders main page correctly', () => {
+ it('should render the fucntion without crashing', () => {
+ render();
+ });
+});
+
+// test("UserPage component", () => {
+// it("should render the Instructorall component", () => {
+// const { getByTestId } = render();
+// expect(getByTestId("instructor-all")).toBeInTheDocument();
+// });
+// });
+test("isValidPassword function", () => {
+ // it("should render the weekly schedule table", () => {
+ // const { getByText } = render();
+ // expect(getByText("برنامه هفتگی")).toBeInTheDocument();
+ // });
+});
diff --git a/src/hooks/Shopping/getCartInfo.jsx b/src/hooks/Shopping/getCartInfo.jsx
index e7dee15..5256f33 100644
--- a/src/hooks/Shopping/getCartInfo.jsx
+++ b/src/hooks/Shopping/getCartInfo.jsx
@@ -3,14 +3,15 @@ import { useEffect } from "react";
import { useState } from "react";
import { apis } from "../../assets/apis";
import { getCartInfo } from "../../Functions/Shopping/getCartInfo";
+import { returnToken } from "../../Functions/returnToken";
export const useGetCartInfo = () => {
- const token = JSON.parse(localStorage.getItem("authTokens")).token.access;
+ const token = returnToken();
const [state, setState] = useState([]);
const [amount, setAmount] = useState(0);
const [totalPrice, setTotalPrice] = useState(0);
const [loading, setLoading] = useState(true);
useEffect(() => {
- getCartInfo(setState, setTotalPrice, setAmount,setLoading)
+ getCartInfo(setState, setTotalPrice, setAmount, setLoading)
}, []);
- return {state,setState, amount, setAmount, totalPrice, setTotalPrice,loading,setLoading};
+ return { state, setState, amount, setAmount, totalPrice, setTotalPrice, loading, setLoading };
};
\ No newline at end of file
diff --git a/src/views/Shopping/Shopping.jsx b/src/views/Shopping/Shopping.jsx
index 564e53c..d996bc4 100644
--- a/src/views/Shopping/Shopping.jsx
+++ b/src/views/Shopping/Shopping.jsx
@@ -1,6 +1,7 @@
import React from "react";
import { useInfo } from "../../contexts/InfoContext";
import AdminNavbar from "../../components/Navbars/AdminNavbar";
+import { returnToken } from "../../Functions/returnToken";
import {
Button,
Card,
@@ -31,7 +32,7 @@ function Shopping() {
const [s2, ss2] = React.useState(false);
const [s3, ss3] = React.useState(false);
// const notificationAlertRef = React.useRef(null);
- const token = JSON.parse(localStorage.getItem("authTokens")).token.access;
+ const token = returnToken();
const {
state: info,
@@ -89,7 +90,7 @@ function Shopping() {
return response.then((data) => {
alert(
data.telegram +
- "\n لطفا به صفحه پروفایل بروید و روی آیکون تلگرام کلیک کنید و ربات تلگرام را فعال کنید"
+ "\n لطفا به صفحه پروفایل بروید و روی آیکون تلگرام کلیک کنید و ربات تلگرام را فعال کنید"
);
});
} else console.error(error);
@@ -237,9 +238,8 @@ function Shopping() {
style={{
height: "100%",
marginBottom: "0",
- justifyContent: `${
- loading && info.length == 0 ? "center" : ""
- }`,
+ justifyContent: `${loading && info.length == 0 ? "center" : ""
+ }`,
}}
>
{info.length == 0 ? (
diff --git a/src/views/Shopping/Shopping.test.jsx b/src/views/Shopping/Shopping.test.jsx
new file mode 100644
index 0000000..81463c8
--- /dev/null
+++ b/src/views/Shopping/Shopping.test.jsx
@@ -0,0 +1,27 @@
+// import { describe, it, expect, vi, test } from "vitest";
+// import { Movies } from './Movies';
+// Imports
+
+import { describe, it, expect, vi, test } from 'vitest';
+import { render, screen } from '@testing-library/react';
+import Shopping from './Shopping';
+import * as Router from "react-router-dom";
+import ContextInfo from '../../contexts/InfoContext';
+describe('Renders main page correctly', () => {
+ it('should render the Shopping component without crashing', () => {
+ render();
+ });
+});
+
+// test("UserPage component", () => {
+// it("should render the Instructorall component", () => {
+// const { getByTestId } = render();
+// expect(getByTestId("instructor-all")).toBeInTheDocument();
+// });
+// });
+test("Shopping component", () => {
+ // it("should render the weekly schedule table", () => {
+ // const { getByText } = render();
+ // expect(getByText("برنامه هفتگی")).toBeInTheDocument();
+ // });
+});
diff --git a/src/views/TimeLine/Chat.test.jsx b/src/views/TimeLine/Chat.test.jsx
new file mode 100644
index 0000000..9b2db8f
--- /dev/null
+++ b/src/views/TimeLine/Chat.test.jsx
@@ -0,0 +1,27 @@
+// import { describe, it, expect, vi, test } from "vitest";
+// import { Movies } from './Movies';
+// Imports
+
+import { describe, it, expect, vi, test } from 'vitest';
+import { render, screen } from '@testing-library/react';
+import Chat from './Chat';
+import * as Router from "react-router-dom";
+import ContextInfo from '../../contexts/InfoContext';
+describe('Renders Chat page correctly', () => {
+ it('should render the Chat component without crashing', () => {
+ render();
+ });
+});
+
+// test("UserPage component", () => {
+// it("should render the Instructorall component", () => {
+// const { getByTestId } = render();
+// expect(getByTestId("instructor-all")).toBeInTheDocument();
+// });
+// });
+test("Chat component", () => {
+ // it("should render the weekly schedule table", () => {
+ // const { getByText } = render();
+ // expect(getByText("برنامه هفتگی")).toBeInTheDocument();
+ // });
+});
diff --git a/src/views/TimeLine/Timeline.jsx b/src/views/TimeLine/Timeline.jsx
index 909f113..b1ca199 100644
--- a/src/views/TimeLine/Timeline.jsx
+++ b/src/views/TimeLine/Timeline.jsx
@@ -31,9 +31,9 @@ function Timeline() {
const [open, setOpen] = useState(false);
const containerRef = useRef(null); // Reference to the tweets container div
const containerAboutYou = useRef(null); // Reference to the tweets container div
- useEffect(()=>{
+ useEffect(() => {
console.log("🚀 ~ CommentModal ~ data:", tweets)
- },[tweets])
+ }, [tweets])
var number = 2;
var forYouNum = 2;
var loadingScroll = false;
@@ -46,7 +46,7 @@ function Timeline() {
handleScroll(fetchForYouTweets, containerAboutYou);
});
- return () => {};
+ return () => { };
}, []);
const handleScroll = (funcCaller, containerRefIn) => {
diff --git a/src/views/TimeLine/Timeline.test.jsx b/src/views/TimeLine/Timeline.test.jsx
new file mode 100644
index 0000000..c2bbbf5
--- /dev/null
+++ b/src/views/TimeLine/Timeline.test.jsx
@@ -0,0 +1,27 @@
+// import { describe, it, expect, vi, test } from "vitest";
+// import { Movies } from './Movies';
+// Imports
+
+import { describe, it, expect, vi, test } from 'vitest';
+import { render, screen } from '@testing-library/react';
+import Timeline from './Timeline';
+import * as Router from "react-router-dom";
+import ContextInfo from '../../contexts/InfoContext';
+describe('Renders Timeline page correctly', () => {
+ it('should render the Timeline component without crashing', () => {
+ render();
+ });
+});
+
+// test("UserPage component", () => {
+// it("should render the Instructorall component", () => {
+// const { getByTestId } = render();
+// expect(getByTestId("instructor-all")).toBeInTheDocument();
+// });
+// });
+test("Timeline component", () => {
+ // it("should render the weekly schedule table", () => {
+ // const { getByText } = render();
+ // expect(getByText("برنامه هفتگی")).toBeInTheDocument();
+ // });
+});