-
Notifications
You must be signed in to change notification settings - Fork 45
Naheed Edges #35
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
base: master
Are you sure you want to change the base?
Naheed Edges #35
Changes from all commits
0a17718
aa3c60a
b85df08
f74016e
0662206
d3426d6
f9dd00a
8089ab8
18be08b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,14 +16,56 @@ class Board extends Component { | |
| }; | ||
| } | ||
|
|
||
| componentDidMount() { | ||
| this.getCards() | ||
| } | ||
|
|
||
| getCards = () => { | ||
| axios.get('https://inspiration-board.herokuapp.com/boards/Naheed/cards') | ||
| .then((response) => { | ||
| this.setState({ cards: response.data }); | ||
| }) | ||
| .catch((error) => { | ||
| this.setState({ error: error.message }); | ||
| }); | ||
| } | ||
|
|
||
| addCard = (text, emoji) => { | ||
| axios.post(`https://inspiration-board.herokuapp.com/boards/Naheed/cards?text=${text}&emoji=${emoji}`) | ||
| .then((response) => { | ||
| this.getCards() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of making another get request via |
||
| }); | ||
| } | ||
|
|
||
| deleteCard = (id) => { | ||
| axios.delete(`https://inspiration-board.herokuapp.com/cards/${id}`, id) | ||
| .then((response) => { | ||
| this.getCards() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like above ... instead of making another get request via
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I initially tried to update state, but it wouldn't re-render with the changes. When I did a hard refresh the new card would show/delete, but it wouldn't show up on its own after using setState. I wasn't able to find a solution so I went with another get request, but any ideas why setState wouldn't render? |
||
| }); | ||
| } | ||
|
|
||
|
|
||
| render() { | ||
| const allCards = this.state.cards.map((card) => { | ||
| return <Card | ||
| key={card.card.id} | ||
| id={card.card.id} | ||
| text={card.card.text} | ||
| emoji={card.card.emoji} | ||
| deleteCardCallback={this.deleteCard} | ||
| addCardCallback={this.addCard}/> | ||
| }); | ||
|
|
||
| return ( | ||
| <div> | ||
| Board | ||
| <div > | ||
| <h3 className="new-card-form__header">Make a new card</h3> | ||
| <NewCardForm cards={this.state.cards} addCardCallback={this.addCard}/> | ||
| <div className="board"> | ||
| {allCards} | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| Board.propTypes = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import React from 'react'; | ||
| import Board from '../Board'; | ||
| import { shallow, mount } from 'enzyme'; | ||
|
|
||
| const CARDS = [ | ||
| { | ||
| name: "test card 1", | ||
| emoji: "emoji" | ||
| }, | ||
| { | ||
| name: "test card 2", | ||
| emoji: "emoji" | ||
| } | ||
| ]; | ||
|
|
||
| describe('Board', () => { | ||
| test('that it matches an existing snapshot', () => { | ||
| // First Mount the Component in the testing DOM | ||
| // Arrange | ||
|
|
||
| const cards = CARDS; | ||
| const wrapper = shallow( | ||
| <Board | ||
| cards={cards} | ||
| /> | ||
| ); | ||
|
|
||
| // Assert that it looks like the last snapshot | ||
| expect(wrapper).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('renders without crashing even with no cards', () => { | ||
| // First Mount the Component in the testing DOM | ||
| // Arrange | ||
|
|
||
| const cards = []; | ||
| const wrapper = shallow( | ||
| <Board | ||
| cards={cards} | ||
| /> | ||
| ); | ||
|
|
||
| // Assert that it looks like the last snapshot | ||
| expect(wrapper).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('successfully deep mounts', () => { | ||
| // First Mount the Component in the testing DOM | ||
| // Arrange | ||
| const wrapper = mount( | ||
| <Board | ||
| cards={CARDS} | ||
| /> | ||
| ); | ||
|
|
||
| // Assert that it looks like the last snapshot | ||
| expect(wrapper).toMatchSnapshot(); | ||
|
|
||
| wrapper.unmount(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import React from 'react'; | ||
| import Card from '../Card'; | ||
| import { shallow } from 'enzyme'; | ||
|
|
||
| describe('Card', () => { | ||
| test('that it matches an existing snapshot', () => { | ||
| // First Mount the Component in the testing DOM | ||
| // Arrange | ||
| const wrapper = shallow( | ||
| <Card | ||
| text="test name" | ||
| emoji="test emoji" | ||
| /> | ||
| ); | ||
|
|
||
| // Assert that it looks like the last snapshot | ||
| expect(wrapper).toMatchSnapshot(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import React from 'react'; | ||
| import NewCardForm from '../NewCardForm'; | ||
| import { shallow } from 'enzyme'; | ||
|
|
||
| describe('NewCardForm', () => { | ||
| test('that it matches an existing snapshot', () => { | ||
| // First Mount the Component in the testing DOM | ||
| // Arrange | ||
| const wrapper = shallow( <NewCardForm addCardCallback={() => {} } />); | ||
|
|
||
| // Assert that it looks like the last snapshot | ||
| expect(wrapper).toMatchSnapshot(); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be nice if you used the
props passed intoBoardfromApp--urlandboardName!