-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
6,161 additions
and
6,125 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
26 changes: 13 additions & 13 deletions
26
react-context-api/src/components/cart-dropdown/cart-dropdown.component.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
react-context-api/src/components/cart-item/cart-item.component.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
react-context-api/src/components/cart-item/cart-item.component.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from "react"; | ||
import { shallow } from "enzyme"; | ||
import CartItem from "./cart-item.component"; | ||
import { findByDataAttr } from "../../utils/utils"; | ||
|
||
const setUp = (props = {}) => { | ||
const component = shallow(<CartItem {...props}></CartItem>); | ||
return component; | ||
}; | ||
|
||
describe("Cart Item Component", () => { | ||
let wrapper; | ||
beforeEach(() => { | ||
const props = { | ||
item: { | ||
imageUrl: "https://i.ibb.co/ZYW3VTp/brown-brim.png", | ||
price: 33, | ||
name: "mir", | ||
quantity: 3 | ||
} | ||
}; | ||
wrapper = setUp(props); | ||
}); | ||
|
||
it("should render without error", () => { | ||
const component = findByDataAttr(wrapper, "cart-item"); | ||
expect(component.length).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
react-context-api/src/components/custom-button/custom-button.component.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from "react"; | ||
import { shallow } from "enzyme"; | ||
import CustomButton from "./custom-button.component"; | ||
import { findByDataAttr } from "../../utils/utils"; | ||
|
||
const setUp = (props = {}) => { | ||
const component = shallow(<CustomButton {...props}></CustomButton>); | ||
return component; | ||
}; | ||
|
||
describe("Custom Button Component", () => { | ||
let component; | ||
beforeEach(() => { | ||
component = setUp(); | ||
}); | ||
|
||
it("should render without error", () => { | ||
const wrapper = findByDataAttr(component, "custom-button"); | ||
expect(wrapper.length).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from "react"; | ||
import { Switch, Route, Redirect } from "react-router-dom"; | ||
|
||
import "./main.css"; | ||
|
||
import HomePage from "../../pages/homepage/homepage.component"; | ||
import ShopPage from "../../pages/shop/shop.component"; | ||
import SignInAndSignUpPage from "../../pages/sign-in-and-sign-up/sign-in-and-sign-up.component"; | ||
import CheckoutPage from "../../pages/checkout/checkout.component"; | ||
|
||
import Header from "../header/header.component"; | ||
|
||
import { auth, createUserProfileDocument } from "../../firebase/firebase.utils"; | ||
|
||
class MainComponent extends React.Component { | ||
unsubscribeFromAuth = null; | ||
|
||
componentDidMount() { | ||
const { setCurrentUser } = this.props; | ||
|
||
this.unsubscribeFromAuth = auth.onAuthStateChanged(async userAuth => { | ||
if (userAuth) { | ||
const userRef = await createUserProfileDocument(userAuth); | ||
|
||
userRef.onSnapshot(snapShot => { | ||
setCurrentUser({ | ||
id: snapShot.id, | ||
...snapShot.data() | ||
}); | ||
}); | ||
} | ||
|
||
setCurrentUser(userAuth); | ||
}); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.unsubscribeFromAuth(); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div data-testid="main-component"> | ||
<Header /> | ||
<Switch> | ||
<Route exact path="/" component={HomePage} /> | ||
<Route path="/shop" component={ShopPage} /> | ||
<Route exact path="/checkout" component={CheckoutPage} /> | ||
<Route | ||
exact | ||
path="/signin" | ||
render={() => | ||
this.props.currentUser ? ( | ||
<Redirect to="/" /> | ||
) : ( | ||
<SignInAndSignUpPage /> | ||
) | ||
} | ||
/> | ||
</Switch> | ||
</div> | ||
); | ||
} | ||
} | ||
export default MainComponent; |
24 changes: 24 additions & 0 deletions
24
react-context-api/src/components/main/main.component.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from "react"; | ||
import { shallow } from "enzyme"; | ||
import MainComponent from "./main.component"; | ||
import { findByDataAttr } from "../../utils/utils"; | ||
|
||
const setUp = (props = {}) => { | ||
const component = shallow(<MainComponent {...props}></MainComponent>); | ||
return component; | ||
}; | ||
|
||
describe("Main Component", () => { | ||
let wrapper; | ||
beforeEach(() => { | ||
const props = { | ||
setCurrentUser: jest.fn() | ||
}; | ||
wrapper = setUp(props); | ||
}); | ||
|
||
it("should render without error", () => { | ||
const component = findByDataAttr(wrapper, "main-component"); | ||
expect(component.length).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
body { | ||
font-family: "Open Sans Condensed"; | ||
padding: 20px 40px; | ||
} | ||
|
||
a { | ||
text-decoration: none; | ||
color: black; | ||
} | ||
|
||
* { | ||
box-sizing: border-box; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from "react"; | ||
import { connect } from "react-redux"; | ||
import { createStructuredSelector } from "reselect"; | ||
|
||
import "./App.css"; | ||
|
||
import { setCurrentUser } from "../../redux/user/user.actions"; | ||
import { selectCurrentUser } from "../../redux/user/user.selectors"; | ||
import MainComponent from "../../components/main/main.component"; | ||
|
||
class App extends React.Component { | ||
render() { | ||
return <MainComponent {...this.props}></MainComponent>; | ||
} | ||
} | ||
|
||
const mapStateToProps = createStructuredSelector({ | ||
currentUser: selectCurrentUser | ||
}); | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
setCurrentUser: user => dispatch(setCurrentUser(user)) | ||
}); | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(App); |
Oops, something went wrong.