Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device catalogue #12

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
/node_modules
1 change: 1 addition & 0 deletions __mocks__/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'test-file-stub';
1 change: 1 addition & 0 deletions __mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
15,981 changes: 1,530 additions & 14,451 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 24 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,38 @@
"unit": "jest"
},
"dependencies": {
"@tds/core-card": "^2.6.0",
"@tds/core-chevron-link": "^2.3.2",
"@tds/core-css-reset": "^3.0.1",
"@tds/core-display-heading": "^3.1.0",
"@tds/core-heading": "^3.0.8",
"@tds/core-image": "^2.1.0",
"@tds/core-notification": "^3.2.0",
"@tds/core-paragraph": "^2.1.0",
"@tds/core-price-lockup": "^2.4.0",
"@tds/core-small": "^2.2.0",
"@tds/core-strong": "^2.2.0",
"@tds/core-terms-and-conditions": "^1.5.0",
"@tds/core-text": "^3.2.0",
"axios": "^0.24.0",
"cors": "^2.8.5",
"enzyme": "^3.11.0",
"express": "^4.17.1",
"file-loader": "^6.2.0",
"lodash": "^4.17.21",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-router-dom": "^5.2.0"
"react-router-dom": "^5.2.0",
"sass": "^1.43.4",
"sass-loader": "^12.3.0",
"styled-components": "^5.3.3",
"url-loader": "^4.1.1"
},
"devDependencies": {
"@babel/core": "^7.12.13",
"@babel/preset-env": "^7.12.13",
"@babel/preset-react": "^7.12.13",
"@testing-library/react": "^12.1.2",
"babel-loader": "^8.2.2",
"clean-webpack-plugin": "^3.0.0",
"concurrently": "^5.3.0",
Expand All @@ -30,5 +51,6 @@
"webpack": "^5.21.2",
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.11.2"
}
},
"proxy": "http://localhost:8081"
}
7 changes: 7 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link
rel="preload"
as="script"
href="https://polyfill.io/v3/polyfill.min.js?features=es6%2CArray.prototype.includes%2CSet"
/>
<title>Apple Shopper</title>
</head>
<body>
<div id="root"></div>

<script src="https://polyfill.io/v3/polyfill.min.js?features=es6%2CArray.prototype.includes%2CSet"></script>
</body>
</html>

7 changes: 6 additions & 1 deletion src/client.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './ui/components/App';
import CSSReset from '@tds/core-css-reset';

ReactDOM.render(
<App />,
<>
<CSSReset />
<App />
</>,
document.getElementById('root')
);


3 changes: 3 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ var express = require('express');
var app = express();
var router = express.Router();
var PORT = 8081;
var cors = require('cors');

app.use(cors());

router.get('/watches', function(req, res) {
res.json({
Expand Down
9 changes: 9 additions & 0 deletions src/ui/__tests__/page_heading.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import PageHeading from '../components/PageHeading';
import { render } from '@testing-library/react';



test("Should render a PageHeading component", () => {
render(<PageHeading/>);
});
44 changes: 40 additions & 4 deletions src/ui/__tests__/routes.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,52 @@ import {MemoryRouter} from 'react-router-dom';
import {mount, configure} from 'enzyme';
import App from '../components/App';
import Home from '../components/Home';
import Watches from '../components/Watches';
import Iphones from '../components/Iphones';
import NotFound from '../components/NotFound';
import PageProduct from '../components/PageProduct';

describe('Application routes', () => {
import {cleanup, fireEvent, render} from '@testing-library/react';


describe('Application 1 routes', () => {
it('should render a Home component', () => {
const wrapper = mount(
<MemoryRouter initialEntries={['/']}>
<App />
<Home />
</MemoryRouter>
);

expect(wrapper.find(Home)).toHaveLength(1);
});
});

// it('should render a Watches component', () => {
// const wrapper = mount(
// <MemoryRouter initialEntries={['/watches']}>
// <App />
// </MemoryRouter>
// );
// expect(wrapper.find(Watches)).toHaveLength(1);
// });

/*
it('should render a Iphones component', () => {
const wrapper = mount(
<MemoryRouter initialEntries={['/iphones']}>
<App />
</MemoryRouter>
);
expect(wrapper.find(Iphones)).toHaveLength(1);
});


it('should render a NotFound component', () => {
const wrapper = mount(
<MemoryRouter initialEntries={['/*']}>
<App />
</MemoryRouter>
);
expect(wrapper.find(NotFound)).toHaveLength(1);
});
*/

});
35 changes: 27 additions & 8 deletions src/ui/components/App/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
import React from 'react';
import {BrowserRouter as Router, Switch, Route} from 'react-router-dom';
import { BrowserRouter as Router, Switch, Route, Redirect, Link } from 'react-router-dom';
import Home from '../Home';
import Watches from '../Watches';
import Iphones from '../Iphones';
import NotFound from '../NotFound';
import HairlineDivider from '@tds/core-hairline-divider';
import Nav from '../Nav';
import WatchesContextProvider from "../../context/WatchesContext";
import IphonesContextProvider from "../../context/IphonesContext";

const App = () => (
<Router>
<Switch>
<Route path="/">
<Home />
</Route>
</Switch>
</Router>
<WatchesContextProvider>
<IphonesContextProvider>
<Router>
<Nav />
<HairlineDivider />
<Switch>
<Route exact path="/" component={Home} />
{/* <Route path="/watches">
<Watches/>
</Route>
<Route path="/iphones">
<Iphones/>
</Route> */}
<Route exact path="/watches" component={Watches} />
<Route exact path="/iphones" component={Iphones} />
<Route component={NotFound} />
</Switch>
</Router>
</IphonesContextProvider>
</WatchesContextProvider>
);

export default App;
11 changes: 8 additions & 3 deletions src/ui/components/Home/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import React from 'react';
import Heading from '@tds/core-heading';

const Home = () => <Heading level="h1">Device Catalogue</Heading>;
import PageHeading from "../PageHeading";

const Home = () => {
return (
<>
<PageHeading title="Device Catalogue" />
</>
)
}
export default Home;
27 changes: 27 additions & 0 deletions src/ui/components/Iphones/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { useState, useContext, useEffect } from 'react';
import FlexGrid from '@tds/core-flex-grid';
import PageHeading from "../PageHeading";
import PageProduct from "../PageProduct";
import { IphonesContext } from "../../context/IphonesContext";


export default function Iphones() {
const [iphoneState] = useContext(IphonesContext);
//console.log(`Iphones Component retrieving data from context: ${iphoneState}`);
const iPhones = iphoneState.data;
return (
<>
<PageHeading title="iPhones" />
<FlexGrid>
<FlexGrid.Row>
{iPhones ?
iPhones.map((item, index) => (
<PageProduct key={`iphones-${index}`} product={item} index={index} type="iphones"/>
))
: "No iPhones available at this moment. Come back soon!"
}
</FlexGrid.Row>
</FlexGrid>
</>
)
}
36 changes: 36 additions & 0 deletions src/ui/components/Nav/Nav.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@import "../../styles/theme.scss";

.NavComponent {
background: $TELUSPurple;
> div {
> div {
padding: 0;
a {
color: $TELUSWhite;
padding:20px;
> i {
position: relative;
top: 4px;
right: 5px;
> svg {
fill: $TELUSWhite;
}
}
}
a.active {
background: $TELUSWhite;
color: $TELUSPurple;
> i {
> svg {
fill: $TELUSPurple;
}
}
}

}
}



}

31 changes: 31 additions & 0 deletions src/ui/components/Nav/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
import { Watch, Phone, Home } from '@tds/core-decorative-icon';
import Box from '@tds/core-box';
import "./Nav.scss";

export default function Nav() {
const [activePage, setActivePage] = useState('Home')

// useEffect(() => {
// console.log("+++++++++++++ activePage", activePage)
// }, [activePage])

return (
<div className="NavComponent">
<Box inline between={0} inset={0}>
<Box inline between={0} inset={3}>
<Link className={activePage == 'Home' && 'active'} onClick={() => { setActivePage('Home') }} to="/"><Home variant="default" size={20} />Home</Link>
</Box>
<Box inline between={0} inset={3}>
<Link className={activePage == 'Watches' && 'active'} onClick={() => { setActivePage('Watches') }} to="/watches"><Watch variant="default" size={20} />Watches</Link>
</Box>
<Box inline between={0} inset={3}>
<Link className={activePage == 'iPhones' && 'active'} onClick={() => { setActivePage('iPhones') }} to="/iphones"><Phone variant="default" size={20} />iPhones</Link>
</Box>
</Box>
{/* <Link to="/asdadasdasd">404</Link> */}
</div>

)
}
17 changes: 17 additions & 0 deletions src/ui/components/PageHeading/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import DisplayHeading from '@tds/core-display-heading'
import Box from '@tds/core-box'
import FlexGrid from '@tds/core-flex-grid'

export default function PageHeading(props) {
const title = props.title || "Heading";
return (
<FlexGrid>
<FlexGrid.Row>
<Box inset={5}>
<DisplayHeading level="h1">{title}</DisplayHeading>
</Box>
</FlexGrid.Row>
</FlexGrid>
)
}
Loading