Skip to content

Commit

Permalink
Resolve Merge Conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
MuntazirHaider committed Aug 30, 2023
2 parents b4dddc9 + 9addbb7 commit eb65b4f
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 20 deletions.
43 changes: 40 additions & 3 deletions cypress/e2e/components/homepage/homepage.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="cypress" />

describe("Error Page Test | CodeLabz", () => {
describe("Home Page Test | CodeLabz", () => {
beforeEach(function () {
cy.fixture("login").then(function (credentials) {
this.credentials = credentials;
Expand All @@ -10,7 +10,7 @@ describe("Error Page Test | CodeLabz", () => {
cy.visit(this.base_url);
});
});

let id;
before(function () {
indexedDB.deleteDatabase("firebaseLocalStorageDb");
});
Expand All @@ -20,8 +20,45 @@ describe("Error Page Test | CodeLabz", () => {
cy.get("[data-testId=homepage");
});

it("check main body has atleast one child", function () {
it("login", function () {
cy.visit(`${this.base_url}login`);
cy.get(".email").type(this.credentials.email);
cy.get(".password").type(this.credentials.password);
cy.get(".loginButton").click();
cy.wait(5000);
});

it("check main body child exist", function () {
cy.get("[data-testId=homepageMainBody");
cy.get("[data-testId=homepageMainBody").should("have.length.at.least", 1);
cy.get("[data-testId=sidebar_desktop]").should("exist");
cy.get("[data-testId=homepageNewCodelabz]").should("exist");
cy.get("[data-testId=activityCard]").should("exist");
});

it("check New Codelabz Button is working", function () {
cy.wait(5000);
cy.get("[data-testId=NewCodelabzBtn]").should("exist").click();
cy.get("[data-testId=newTutorial_title]").should("exist").type("test");
cy.get("[data-testId=newTutorial_summary]").should("exist").type("test");
cy.get("#orgSelect").should("exist").click();
cy.get("#react-select-3-listbox").click();
cy.get("[data-testId=newTutorialSubmit]").should("exist").click();
cy.wait(5000);
cy.get("[data-testId=publishTutorial]").should("exist").click();
cy.url().then(url => {
const urlArray = url.split("/");
id = urlArray.pop();
});
});

it("Check New Codelabz is visible on homepage", function () {
cy.visit(this.base_url);
cy.get("[data-testId=codelabz]").should("exist");
cy.get("[data-testId=codelabzDetails]").spread((first, second) => {
first.click();
cy.wait(5000);
cy.url().should("include", "/tutorial");
});
});
});
67 changes: 67 additions & 0 deletions cypress/e2e/components/tutorialPage/tutorialPage.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/// <reference types="cypress" />

describe("Tutorial Page Test | CodeLabz", () => {
let id, org;
beforeEach(function () {
cy.fixture("login").then(function (credentials) {
this.credentials = credentials;
});
cy.fixture("base_url").then(function (data) {
this.base_url = data.base_url;
});
});

before(function () {
indexedDB.deleteDatabase("firebaseLocalStorageDb");
});
it("login", function () {
cy.visit(`${this.base_url}login`);
cy.get(".email").type(this.credentials.email);
cy.get(".password").type(this.credentials.password);
cy.get(".loginButton").click();
cy.wait(5000);
});

it("Create new tutorial", function () {
cy.visit(`${this.base_url}tutorials`);
cy.wait(1000);
cy.get("[data-testId=NewTutorialBtn]").click();
cy.get("[data-testId=newTutorial_title]").should("exist").type("test");
cy.get("[data-testId=newTutorial_summary]").should("exist").type("test");
cy.get("#orgSelect").should("exist").click();
cy.get("#react-select-3-listbox").click();
cy.get("[data-testId=newTutorialSubmit]").should("exist").click();
cy.wait(5000);
cy.url().then(url => {
const urlArray = url.split("/");
id = urlArray.pop();
org = urlArray.pop();
});
});

it("Check tutorial can't be visited if not published", function () {
cy.visit(`${this.base_url}tutorial/${id}`);
cy.wait(5000);
cy.location().should(loc => {
expect(loc.href).to.eq(`${this.base_url}not-found`);
});
});

it("Check tutorial can be visited if published", function () {
cy.visit(`${this.base_url}tutorials/${org}/${id}`);
cy.get("[data-testId=publishTutorial]").should("exist").click();
cy.wait(5000);
cy.visit(`${this.base_url}tutorial/${id}`);
cy.wait(5000);
cy.location().should(loc => {
expect(loc.href).to.eq(`${this.base_url}tutorial/${id}`);
});
cy.get("[data-testId=tutorialpageSideBar]").should("exist");
cy.get("[data-testId=tutorialpageMainBody]");
cy.get("[data-testId=tutorialpageStepsBar]").should("exist");

cy.get("[data-testId=tutorialpageComments]").should("exist");
cy.get("[data-testId=tutorialpageAuthorName]").should("exist");
cy.get("[data-testId=tutorialpageSteps]").should("exist");
});
});
7 changes: 5 additions & 2 deletions src/components/Card/CardWithoutPicture.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default function CardWithoutPicture({ tutorial }) {
};

return (
<Card className={classes.root}>
<Card className={classes.root} data-testId="codelabz">
<CardHeader
avatar={
<Avatar className={classes.avatar}>
Expand Down Expand Up @@ -142,7 +142,10 @@ export default function CardWithoutPicture({ tutorial }) {
subheader={tutorial?.createdAt ? getTime(tutorial?.createdAt) : ""}
/>
<Link to={`/tutorial/${tutorial?.tutorial_id}`}>
<CardContent className={classes.contentPadding}>
<CardContent
className={classes.contentPadding}
data-testId="codelabzDetails"
>
<Typography variant="h5" color="text.primary" data-testId="Title">
{tutorial?.title}
</Typography>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Topbar/Activity/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function Activity() {

return (
<React.Fragment>
<Grid container>
<Grid container data-testId="activityCard">
<div className={classes.root}>
<Grid item>
<Typography variant="h6">Activity</Typography>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Topbar/NewCodelabz/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function NewCodelabz({ setVisibleModal }) {

return (
<React.Fragment>
<Paper className={classes.root}>
<Paper className={classes.root} data-testId="homepageNewCodelabz">
<Grid
spacing={0}
justifyContent="flex-start"
Expand All @@ -46,6 +46,7 @@ function NewCodelabz({ setVisibleModal }) {
className={classes.iconDiv}
justifyContent="center"
alignContent="center"
data-testId="NewCodelabzBtn"
onClick={() => setVisibleModal(true)}
>
<AddBoxRoundedIcon color="primary" fontSize="large" />
Expand Down
2 changes: 1 addition & 1 deletion src/components/TutorialPage/StepBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const StepsBar = ({
</StepList>
</Drawer>
) : (
<Card className={classes.card}>
<Card className={classes.card} data-testId="tutorialpageStepsBar">
<div data-testId="sidebar_desktop">
<Typography sx={{ fontWeight: "800", textAlign: "center" }}>
STEPS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ const CommentBox = ({ commentsArray, tutorialId }) => {
};

return (
<Card className={classes.container} id="comments">
<Card
className={classes.container}
id="comments"
data-testId="tutorialpageComments"
>
<Typography variant="h5" sx={{ fontWeight: "600" }}>
Comments({commentsArray?.length || 0})
</Typography>
Expand Down
2 changes: 1 addition & 1 deletion src/components/TutorialPage/components/Tutorial.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Tutorial = ({ steps }) => {
<Card className={classes.container}>
{steps?.map((step, i) => {
return (
<Box id={step.id} key={step.id}>
<Box id={step.id} key={step.id} data-testId="tutorialpageSteps">
<Typography sx={{ fontWeight: "600" }}>
{i + 1 + ". " + step.title}
</Typography>
Expand Down
17 changes: 13 additions & 4 deletions src/components/TutorialPage/components/UserDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const User = ({ id, timestamp, showFollowButton, size }) => {
const [isFollowed, setIsFollowed] = useState(true);
useEffect(() => {
getUserProfileData(id)(firebase, firestore, dispatch);
return () => {};
}, [id]);

const profileData = useSelector(({ firebase: { profile } }) => profile);
Expand All @@ -41,11 +42,17 @@ const User = ({ id, timestamp, showFollowButton, size }) => {

useEffect(() => {
const checkIsFollowed = async () => {
const status = await isUserFollower(profileData.uid, user.uid, firestore);
const status = await isUserFollower(
profileData?.uid,
user?.uid,
firestore
);
setIsFollowed(status);
console.log(status);
};
checkIsFollowed();
if (id && user && profileData) {
checkIsFollowed();
}
return () => {};
}, [profileData, user]);

const followUser = () => {
Expand Down Expand Up @@ -85,7 +92,9 @@ const User = ({ id, timestamp, showFollowButton, size }) => {
fontSize: size == "sm" ? "14px" : "16px"
}}
>
<span className={classes.bold}>{user?.displayName}</span>
<span className={classes.bold} data-testId="tutorialpageAuthorName">
{user?.displayName}
</span>
</Typography>
<Typography
sx={{
Expand Down
24 changes: 21 additions & 3 deletions src/components/TutorialPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import {
import { getUserProfileData } from "../../store/actions";
import { useDispatch, useSelector } from "react-redux";
import { useFirebase, useFirestore } from "react-redux-firebase";
import { useParams } from "react-router-dom";
import { useParams, useHistory } from "react-router-dom";

function TutorialPage({ background = "white", textColor = "black" }) {
const classes = useStyles();
const { id } = useParams();
const history = useHistory();
const windowSize = useWindowSize();
const [openMenu, setOpen] = useState(false);
const toggleSlider = () => {
Expand All @@ -32,6 +33,7 @@ function TutorialPage({ background = "white", textColor = "black" }) {
useEffect(() => {
getTutorialData(id)(firebase, firestore, dispatch);
getTutorialSteps(id)(firebase, firestore, dispatch);
return () => {};
}, []);
const tutorial = useSelector(
({
Expand All @@ -40,6 +42,13 @@ function TutorialPage({ background = "white", textColor = "black" }) {
}
}) => data
);
const loading = useSelector(
({
tutorialPage: {
post: { loading }
}
}) => loading
);

const postDetails = {
title: tutorial?.title,
Expand All @@ -58,6 +67,10 @@ function TutorialPage({ background = "white", textColor = "black" }) {
}
}) => steps
);
if ((!loading && !tutorial) || (!loading && !tutorial?.isPublished)) {
console.log(loading, tutorial);
history.push("/not-found");
}

return (
<Box
Expand Down Expand Up @@ -94,15 +107,20 @@ function TutorialPage({ background = "white", textColor = "black" }) {
<Grid
item
className={classes.mainBody}
data-testId="homepageMainBody"
data-testId="tutorialpageMainBody"
xs={6}
>
<PostDetails details={postDetails} />
<Tutorial steps={steps} />
<CommentBox commentsArray={tutorial?.comments} tutorialId={id} />
</Grid>

<Grid item className={classes.sideBody} xs={3}>
<Grid
item
className={classes.sideBody}
xs={3}
data-testId="tutorialpageSideBar"
>
<SideBar />
</Grid>
</Grid>
Expand Down
3 changes: 1 addition & 2 deletions src/store/actions/tutorialPageActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ export const getTutorialFeedIdArray =
return tutorialsArray;
});
}
followings.push(uid);
let newTutorials = [];
if (uid) {
if (followings.length > 0) {
newTutorials = await firestore
.collection("tutorials")
.where("created_by", "not-in", followings)
Expand Down
2 changes: 1 addition & 1 deletion src/store/reducers/tutorialPageReducers/postReducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as actions from "../../actions/actionTypes";

const initialState = {
loading: false,
loading: true,
error: null,
data: null,
steps: []
Expand Down

0 comments on commit eb65b4f

Please sign in to comment.