-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from gerpanese/create-flashcard
Create flashcard (Frontend)
- Loading branch information
Showing
18 changed files
with
464 additions
and
59 deletions.
There are no files selected for viewing
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,3 @@ | ||
{ | ||
"presets": ["es2015", "react", "stage-3"] | ||
} |
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,3 @@ | ||
module.exports = { | ||
setupFiles: ['raf/polyfill'], | ||
}; |
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 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 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,53 @@ | ||
import { | ||
updateFrontText, | ||
updateBackText, | ||
saveCard, | ||
discardCard, | ||
} from '../../actions/createCard'; | ||
|
||
describe('src/__tests__/actions/createCard.js', () => { | ||
describe('updateFrontText', () => { | ||
it('should create an action to update front side text', () => { | ||
const fakeText = 'Test updateFrontText'; | ||
const expectedAction = { | ||
type: 'UPDATE_FRONT_TEXT', | ||
frontText: fakeText, | ||
}; | ||
const actualAction = updateFrontText(fakeText); | ||
expect(actualAction).toEqual(expectedAction); | ||
}); | ||
}); | ||
|
||
describe('updateBackText', () => { | ||
it('should create an action to update back side text', () => { | ||
const fakeText = 'Test updateBackText'; | ||
const expectedAction = { | ||
type: 'UPDATE_BACK_TEXT', | ||
backText: fakeText, | ||
}; | ||
const actualAction = updateBackText(fakeText); | ||
expect(actualAction).toEqual(expectedAction); | ||
}); | ||
}); | ||
|
||
describe('saveCard', () => { | ||
// Need to add test for POST /cards feature | ||
it('should create an action to save card to database', async () => { | ||
const expectedAction = { | ||
type: 'SAVE_CARD', | ||
}; | ||
const actualAction = await saveCard(); | ||
expect(actualAction).toEqual(expectedAction); | ||
}); | ||
}); | ||
|
||
describe('discardCard', () => { | ||
it('should create an action to discard card', () => { | ||
const expectedAction = { | ||
type: 'DISCARD_CARD', | ||
}; | ||
const actualAction = discardCard(); | ||
expect(actualAction).toEqual(expectedAction); | ||
}); | ||
}); | ||
}); |
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,69 @@ | ||
import React from 'react'; | ||
import Enzyme, { mount } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
import CreateCard from '../../components/CreateCard'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
const setup = () => { | ||
const props = { | ||
frontText: '', | ||
backText: '', | ||
updateFrontText: jest.fn(), | ||
updateBackText: jest.fn(), | ||
saveCard: jest.fn(), | ||
discardCard: jest.fn(), | ||
}; | ||
const enzymeWrapper = mount(<CreateCard {...props} />); | ||
return { | ||
props, | ||
enzymeWrapper, | ||
}; | ||
}; | ||
|
||
describe('src/components/CreateCard.jsx', () => { | ||
it('should render CreateCard component', () => { | ||
const { enzymeWrapper } = setup(); | ||
expect(enzymeWrapper.find('.CreateCard').hasClass('CreateCard')).toBe(true); | ||
}); | ||
|
||
it('should call updateFrontText if front side text is changed', () => { | ||
const { enzymeWrapper, props } = setup(); | ||
const frontTextInput = enzymeWrapper.find('#frontText'); | ||
expect(props.updateFrontText.mock.calls.length).toBe(0); | ||
frontTextInput.instance().value = 'Updated FrontText'; | ||
frontTextInput.simulate('change'); | ||
expect(props.updateFrontText.mock.calls.length).toBe(1); | ||
}); | ||
|
||
it('should call updateBackText if back side text is changed', () => { | ||
const { enzymeWrapper, props } = setup(); | ||
const backTextInput = enzymeWrapper.find('#backText'); | ||
expect(props.updateBackText.mock.calls.length).toBe(0); | ||
backTextInput.instance().value = 'Updated BackText'; | ||
backTextInput.simulate('change'); | ||
expect(props.updateBackText.mock.calls.length).toBe(1); | ||
}); | ||
|
||
it('should call discardCard if back side text is changed', () => { | ||
const { enzymeWrapper, props } = setup(); | ||
const discardButton = enzymeWrapper.find('#discardButton'); | ||
expect(props.discardCard.mock.calls.length).toBe(0); | ||
discardButton.simulate('click'); | ||
expect(props.discardCard.mock.calls.length).toBe(1); | ||
}); | ||
|
||
it('should call Web Speech Api method on click', () => { | ||
// Should be implemented later | ||
expect(1).toBe(1); | ||
}); | ||
|
||
it('should call saveCard if save button on click', () => { | ||
const { enzymeWrapper, props } = setup(); | ||
const saveButton = enzymeWrapper.find('#saveButton'); | ||
expect(props.saveCard.mock.calls.length).toBe(0); | ||
saveButton.simulate('click'); | ||
expect(props.saveCard.mock.calls.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,8 @@ | ||
import CreateCardContainer from '../../containers/CreateCard'; | ||
import CreateCardComponent from '../../components/CreateCard'; | ||
|
||
describe('src/containers/CreateCard', () => { | ||
it('should includes CreateCard component as a wrapped component', () => { | ||
expect(CreateCardContainer.WrappedComponent).toEqual(CreateCardComponent); | ||
}); | ||
}); |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import reducer from '../../reducers/index'; | ||
|
||
describe('todos reducer', () => { | ||
it('should return the default state', () => { | ||
// Setup | ||
const expected = { | ||
frontText: '', | ||
backText: '', | ||
}; | ||
|
||
// Exercise | ||
const actual = reducer(undefined, {}); | ||
|
||
// Assert | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should handle UPDATE_FRONT_TEXT', () => { | ||
// Setup | ||
const expected = { | ||
frontText: 'test front text', | ||
}; | ||
const mockAction = { | ||
type: 'UPDATE_FRONT_TEXT', | ||
frontText: 'test front text', | ||
}; | ||
|
||
// Exercise | ||
const actual = reducer({}, mockAction); | ||
|
||
// Assert | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should handle UPDATE_BACK_TEXT', () => { | ||
// Setup | ||
const expected = { | ||
backText: 'test back text', | ||
}; | ||
const mockAction = { | ||
type: 'UPDATE_BACK_TEXT', | ||
backText: 'test back text', | ||
}; | ||
|
||
// Exercise | ||
const actual = reducer({}, mockAction); | ||
|
||
// Assert | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should handle SAVE_CARD', () => { | ||
// Setup | ||
const initialState = { | ||
frontText: 'Existing test back text', | ||
backText: 'Existing test back text', | ||
}; | ||
const expected = { | ||
frontText: '', | ||
backText: '', | ||
}; | ||
const mockAction = { | ||
type: 'SAVE_CARD', | ||
}; | ||
|
||
// Exercise | ||
const actual = reducer(initialState, mockAction); | ||
|
||
// Assert | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should handle DISCARD_CARD', () => { | ||
// Setup | ||
const initialState = { | ||
frontText: 'Existing test back text', | ||
backText: 'Existing test back text', | ||
}; | ||
const expected = { | ||
frontText: '', | ||
backText: '', | ||
}; | ||
const mockAction = { | ||
type: 'DISCARD_CARD', | ||
}; | ||
|
||
// Exercise | ||
const actual = reducer(initialState, mockAction); | ||
|
||
// Assert | ||
expect(actual).toEqual(expected); | ||
}); | ||
}); |
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 @@ | ||
const updateFrontText = frontText => ({ | ||
type: 'UPDATE_FRONT_TEXT', | ||
frontText, | ||
}); | ||
|
||
const updateBackText = backText => ({ | ||
type: 'UPDATE_BACK_TEXT', | ||
backText, | ||
}); | ||
|
||
const saveCard = () => ({ | ||
type: 'SAVE_CARD', | ||
}); | ||
|
||
const discardCard = () => ({ | ||
type: 'DISCARD_CARD', | ||
}); | ||
|
||
export { | ||
updateFrontText, | ||
updateBackText, | ||
saveCard, | ||
discardCard, | ||
}; |
This file was deleted.
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
Oops, something went wrong.