Skip to content

Commit

Permalink
Merge pull request #162 from Katyusha-Group/test/Modals
Browse files Browse the repository at this point in the history
Test/modals
  • Loading branch information
ymasteryfarahani authored Jan 29, 2024
2 parents 198b296 + f379c50 commit 45c260b
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 27 deletions.
9 changes: 5 additions & 4 deletions src/Functions/Chat/getChat.jsx
Original file line number Diff line number Diff line change
@@ -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));
Expand Down
8 changes: 4 additions & 4 deletions src/Functions/Shopping/getCartInfo.jsx
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
17 changes: 9 additions & 8 deletions src/Functions/Shopping/saveWallet.jsx
Original file line number Diff line number Diff line change
@@ -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));
}
.catch((error) => console.error(error));
}
27 changes: 27 additions & 0 deletions src/Functions/isValidPassword.test.jsx
Original file line number Diff line number Diff line change
@@ -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(<ContextInfo><Router.BrowserRouter><isValidPassword /></Router.BrowserRouter></ContextInfo>);
});
});

// test("UserPage component", () => {
// it("should render the Instructorall component", () => {
// const { getByTestId } = render(<UserPage />);
// expect(getByTestId("instructor-all")).toBeInTheDocument();
// });
// });
test("isValidPassword function", () => {
// it("should render the weekly schedule table", () => {
// const { getByText } = render(<UserPage />);
// expect(getByText("برنامه هفتگی")).toBeInTheDocument();
// });
});
7 changes: 4 additions & 3 deletions src/hooks/Shopping/getCartInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
10 changes: 5 additions & 5 deletions src/views/Shopping/Shopping.jsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -89,7 +90,7 @@ function Shopping() {
return response.then((data) => {
alert(
data.telegram +
"\n لطفا به صفحه پروفایل بروید و روی آیکون تلگرام کلیک کنید و ربات تلگرام را فعال کنید"
"\n لطفا به صفحه پروفایل بروید و روی آیکون تلگرام کلیک کنید و ربات تلگرام را فعال کنید"
);
});
} else console.error(error);
Expand Down Expand Up @@ -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 ? (
Expand Down
27 changes: 27 additions & 0 deletions src/views/Shopping/Shopping.test.jsx
Original file line number Diff line number Diff line change
@@ -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(<ContextInfo><Router.BrowserRouter><Shopping /></Router.BrowserRouter></ContextInfo>);
});
});

// test("UserPage component", () => {
// it("should render the Instructorall component", () => {
// const { getByTestId } = render(<UserPage />);
// expect(getByTestId("instructor-all")).toBeInTheDocument();
// });
// });
test("Shopping component", () => {
// it("should render the weekly schedule table", () => {
// const { getByText } = render(<UserPage />);
// expect(getByText("برنامه هفتگی")).toBeInTheDocument();
// });
});
27 changes: 27 additions & 0 deletions src/views/TimeLine/Chat.test.jsx
Original file line number Diff line number Diff line change
@@ -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(<ContextInfo><Router.BrowserRouter><Chat /></Router.BrowserRouter></ContextInfo>);
});
});

// test("UserPage component", () => {
// it("should render the Instructorall component", () => {
// const { getByTestId } = render(<UserPage />);
// expect(getByTestId("instructor-all")).toBeInTheDocument();
// });
// });
test("Chat component", () => {
// it("should render the weekly schedule table", () => {
// const { getByText } = render(<UserPage />);
// expect(getByText("برنامه هفتگی")).toBeInTheDocument();
// });
});
6 changes: 3 additions & 3 deletions src/views/TimeLine/Timeline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,7 +46,7 @@ function Timeline() {
handleScroll(fetchForYouTweets, containerAboutYou);
});

return () => {};
return () => { };
}, []);

const handleScroll = (funcCaller, containerRefIn) => {
Expand Down
27 changes: 27 additions & 0 deletions src/views/TimeLine/Timeline.test.jsx
Original file line number Diff line number Diff line change
@@ -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(<ContextInfo><Router.BrowserRouter><Timeline /></Router.BrowserRouter></ContextInfo>);
});
});

// test("UserPage component", () => {
// it("should render the Instructorall component", () => {
// const { getByTestId } = render(<UserPage />);
// expect(getByTestId("instructor-all")).toBeInTheDocument();
// });
// });
test("Timeline component", () => {
// it("should render the weekly schedule table", () => {
// const { getByText } = render(<UserPage />);
// expect(getByText("برنامه هفتگی")).toBeInTheDocument();
// });
});

0 comments on commit 45c260b

Please sign in to comment.