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

Ports - Faiza #41

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
"devDependencies": {
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"enzyme-to-json": "^3.3.5",
"gh-pages": "^2.0.1"
},
"jest": {
"snapshotSerializers": [
"enzyme-to-json/serializer"
]
}
}
4 changes: 2 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class App extends Component {
<h1 className="header__h1"><span className="header__text">Inspiration Board</span></h1>
</header>
<Board
url="https://inspiration-board.herokuapp.com/boards/"
boardName={`Ada-Lovelace`}
url="https://inspiration-board.herokuapp.com/"
boardName={`Faiza`}
/>
</section>
);
Expand Down
18 changes: 17 additions & 1 deletion src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import App from './App';

describe('App', () => {
describe('<App />', () => {

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
});

describe('<App />', () => {
test('that it renders App with shallow rendering', () => {
const wrapper = shallow(<App />);
expect(wrapper).toMatchSnapshot();
});

test('will match the last snapshot with deep rendering', () => {
const wrapper = mount(<App />);
expect(wrapper).toMatchSnapshot();

// Remove the component from the DOM (save memory and prevent side effects).
wrapper.unmount();
});
});

137 changes: 137 additions & 0 deletions src/__snapshots__/App.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<App /> that it renders App with shallow rendering 1`] = `
<section>
<header
className="header"
>
<h1
className="header__h1"
>
<span
className="header__text"
>
Inspiration Board
</span>
</h1>
</header>
<Board
boardName="Faiza"
url="https://inspiration-board.herokuapp.com/"
/>
</section>
`;

exports[`<App /> will match the last snapshot with deep rendering 1`] = `
<App>
<section>
<header
className="header"
>
<h1
className="header__h1"
>
<span
className="header__text"
>
Inspiration Board
</span>
</h1>
</header>
<Board
boardName="Faiza"
url="https://inspiration-board.herokuapp.com/"
>
<div
className="board"
>
<NewCardForm
addCardCallback={[Function]}
>
<form
className="new-card-form"
onSubmit={[Function]}
>
<h3>
Add a Card
</h3>
<div>
<label
htmlFor="text"
>
Text:
</label>
<input
name="text"
onChange={[Function]}
type="text"
value=""
/>
<label
htmlFor="emoji"
/>
<select
name="emoji"
onChange={[Function]}
type="text"
value=""
>
<option
value=""
>
Add emojis to your message!
</option>
<option
value=""
>
None
</option>
<option
value="heart_eyes"
>
Heart Eyes
</option>
<option
value="beer"
>
Beer
</option>
<option
value="clap"
>
Clap
</option>
<option
value="sparkling_heart"
>
Sparkling Heart
</option>
<option
value="heart_eyes_cat"
>
Heart Eyes Cat
</option>
<option
value="dog"
>
Dog
</option>
</select>
</div>
<div
className=".new-card-form__form-button"
>
<input
className="btn btn-success new-card-form--submit"
name="submit"
type="submit"
value="Add a Card"
/>
</div>
</form>
</NewCardForm>
</div>
</Board>
</section>
</App>
`;
109 changes: 100 additions & 9 deletions src/components/Board.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,120 @@ import axios from 'axios';
import './Board.css';
import Card from './Card';
import NewCardForm from './NewCardForm';
import CARD_DATA from '../data/card-data.json';
// import CARD_DATA from '../data/card-data.json';
// import { isExpressionWrapper, throwStatement } from '@babel/types';

class Board extends Component {
constructor() {
super();
constructor(props) {
super(props);

this.state = {
cards: [],
error: null
};
}

componentDidMount() {
const {url, boardName } = this.props;
axios.get(`${url}boards/${boardName}/cards`)
.then((response) => {
console.log('In .then!!!!');

const allCards = response.data.map(element => {
const card = {
...element.card,
}
return card;
});

this.setState({
cards: allCards,
});
})
.catch((error) => {
this.setState({
error: error.message
});
})
}

deleteCard = (id) => {
console.log(id);

const updatedCards = this.state.cards.filter((card) => card.id !== id);

this.setState({
cards: updatedCards,
});

axios.delete(`https://inspiration-board.herokuapp.com/cards/${id}`)
.then((response) => {
console.log('ID of card deleted:', response.data.card.id);
})
.catch((error) => {
this.setState({
error: error.message
});
});
}

addCard = (card) => {
const { url, boardName } = this.props;

const newCardData = {
text: card.text,
emoji: card.emoji,
};

axios.post(`${url}boards/${boardName}/cards`, newCardData)
.then((response) => {

console.log("This is what response.data looks like from the API on a successful response", response.data);

let updatedCards = this.state.cards;

updatedCards.unshift({
id: response.data.card.id,
text: card.text,
emoji: card.emoji,
});

this.setState({
cards: updatedCards,
});
})
.catch((error) => {
this.setState({
error: error.message,
});
});
}

render() {
return (
<div>
Board
const allCards = this.state.cards.map((card, i) => {
return <Card
key={i}
{...card}
onDeleteCard={this.deleteCard}
/>
});

return(
<div className="board">
<NewCardForm
addCardCallback={this.addCard}
/>

{allCards}

</div>
)
);
}

}

Board.propTypes = {

url: PropTypes.string.isRequired,
boardName: PropTypes.string.isRequired
};

export default Board;
11 changes: 11 additions & 0 deletions src/components/Board.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import NewCardForm from './NewCardForm';
import { shallow } from 'enzyme';

describe('<Board />', () => {
test('that it matches as existing snapshot', () => {
const wrapper = shallow(<NewCardForm addCardCallback={() => { }} />);

expect(wrapper).toMatchSnapshot();
});
});
Loading