Commit 07fb5380 authored by Kristian Freeman's avatar Kristian Freeman

Remove unused exercise

parent eb6e6bb9
# See https://help.github.com/ignore-files/ for more about ignoring files.
# dependencies
/node_modules
# testing
/coverage
# production
/build
# misc
.DS_Store
.env
npm-debug.log*
yarn-debug.log*
yarn-error.log*
default:
CI=true yarn run test
run:
yarn run start
This diff is collapsed.
{
"name": "first",
"version": "0.1.0",
"private": true,
"dependencies": {
"enzyme": "^2.9.1",
"faker": "^4.1.0",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-test-renderer": "^15.6.1"
},
"devDependencies": {
"react-scripts": "0.9.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tag above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body style="margin: 0; font-family: sans-serif;">
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start`.
To create a production bundle, use `npm run build`.
-->
</body>
</html>
import React from 'react';
import Header from './Header';
import Post from './Post';
import Sidebar from './Sidebar';
export default class Blog extends React.Component {
constructor() {
super()
// A state object should be initialized with
// the following:
// - blogTitle should be set to null
// - blogAuthor should be set to null
// - posts should be an empty array `[]`
}
componentDidMount() {
const url = "https://bytesized-training-assets.herokuapp.com/blog.json"
fetch(url).then(resp => resp.json().then(json => {
this.setState({
blogTitle: json.blogTitle,
blogAuthor: json.blogAuthor,
posts: json.posts
})
}));
}
render() {
// When you've replaced CHANGE_ME later in the render
// function, you can delete the below line.
var CHANGE_ME;
// The Blog component has three state values:
// - blogTitle
// - blogAuthor
// - posts
// Assign each of these to a variable of your choice.
// A number of additions need to be made to the return
// section of the render function below.
//
// Header:
// - Pass the value of your blogTitle variable as a
// prop `blogTitle`.
// - Pass the value of your blogAuthor variable as a
// prop `blogAuthor`.
// Post:
// - Update the value CHANGE_ME below to your posts
// variable. This will "loop" through the posts
// array and create a Post component for each post.
// Pass in post (value) _as_ the prop post (name) for each
// component.
// <Post name={value} />
// Sidebar:
// - Pass the value of your posts variable as a prop `posts`.
return (
<div>
<Header
/>
<div style={{display: "flex"}}>
<div style={{width: "75%"}}>
{CHANGE_ME.map((post, index) =>
<Post
key={index}
/>
)}
</div>
<div style={{height: "100%", width: "25%"}}>
<Sidebar
/>
</div>
</div>
</div>
)
}
}
import React from 'react';
export default class Comment extends React.Component {
render() {
// The Comment component receives a single prop.
// This prop has three fields on it:
// - commentAuthor
// - commentBody
// - postDate
// Try using ES6's "destructuring" syntax to quickly
// define all three as variables. For instance, given
// an object like:
//
// var obj = { name: "Me", age: 99 }
//
// I can use:
//
// var { name, age } = obj;
//
// To quickly set both variables.
//
// Do the same with `author`, `body`, and `date`, and replace
// the static text below with the values from these
// variables.
//
return (
<div>
<h5>Author</h5>
<p>Body</p>
<p><small>Date</small></p>
</div>
)
}
}
import React from 'react';
import ReactDOM from 'react-dom';
import { shallow } from 'enzyme';
import Comment from './Comment';
const comment = { commentAuthor: "Kristian", commentBody: "Hi", postDate: new Date().toString() }
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Comment comment={comment} />, div);
});
it('<Comment> renders props', () => {
const wrapper = shallow(
<Comment comment={comment} />
);
expect(wrapper.text().includes("Kristian")).toEqual(true);
expect(wrapper.text().includes("Hi")).toEqual(true);
});
import React from 'react';
export default class Header extends React.Component {
render() {
// The Header component receives two props that
// you should have defined previously, in the Blog
// component. Set these props to variables, and replace
// "Title" and "Author" with those values in the
// return portion of this function.
return (
<div style={{ background: "#eee", padding: "1em 4em" }}>
<h1>Title</h1>
<h2>Author</h2>
</div>
)
}
}
import React from 'react';
import ReactDOM from 'react-dom';
import { shallow } from 'enzyme';
import Header from './Header';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Header />, div);
});
it('<Header> renders props', () => {
const wrapper = shallow(
<Header blogAuthor="Kristian" blogTitle="Hi" />
);
expect(wrapper.text().includes("Kristian")).toEqual(true);
expect(wrapper.text().includes("Hi")).toEqual(true);
});
import React from 'react';
import Comment from './Comment';
export default class Post extends React.Component {
render() {
// The Post component receives one prop. That prop
// contains three pieces of data that we care about:
//
// - postTitle
// - postContent
// - comments
//
// Assign each of these to a variable of your choice.
// Remember that because they are _on_ the passed-in
// prop, you'll call them in a format like:
// var myProp = this.props.myProp;
// var myField = myProp.myField;
// In the return portion of render, replace the static
// "Title" with an <h1> tag containing the value of your
// postContent variable.
//
// Replace the static "Body" with an <p> tag containing
// the value of your postTitle variable.
//
// Replace the static CHANGE_ME in line 38 by mapping through your
// comments variable, rendering a <Comment> component
// with the prop comment. This will look somewhat like
// the following:
//
// {myArray.map((value, index) =>
// <Subcomponent key={index} prop={value} />
// )}
return (
<div style={{padding: "2em"}}>
<h1>Title</h1>
<p>Content</p>
{CHANGE_ME.map((comment, index) =>
<Comment
key={index}
{/* what value are we not passing in yet? */}
/>
)}
</div>
);
}
}
import React from 'react';
export default class Sidebar extends React.Component {
render() {
// When you have replaced CHANGE_ME later in the
// render function, you can remove the below line.
var CHANGE_ME;
// The Sidebar component receives one prop that
// you should have defined previously, in the Blog
// component.
//
// Set this prop to a variable, and then "loop"
// through it using `map`. In the map function, return
// a <li> tag with the post title for each post. A
// post has the format:
//
// { postTitle: "Title", ... }
//
// To display the post title, you'll want to use
// post.postTitle in your map function.
//
// You may want to look at the map call in the Blog
// component's render function, to see a similar
// pattern.
//
return (
<div style={{background: "#eee", padding: "1em"}}>
<h3>Recent posts</h3>
<ul>
</ul>
</div>
)
}
}
import React from 'react';
import ReactDOM from 'react-dom';
import { shallow } from 'enzyme';
import Sidebar from './Sidebar';
const posts = [{ postTitle: "Hi" }];
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Sidebar posts={posts} />, div);
});
it('<Sidebar> renders props', () => {
const wrapper = shallow(
<Sidebar posts={posts} />
);
expect(wrapper.text().includes("Hi")).toEqual(true);
});
import React from 'react';
import ReactDOM from 'react-dom';
import Blog from './Blog';
const root = document.getElementById("root");
if (root) { ReactDOM.render(<Blog />, root); }
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment