This file contains hidden or 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
| function loadProfile(serverApi) { | |
| return function (dispatch) { | |
| return serverApi.getProfile().then((json) => { | |
| return dispatch({ | |
| type: types.GET_PROFILE, | |
| profile: json | |
| }); | |
| }); | |
| }; | |
| } |
This file contains hidden or 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
| function saveAddress(address, serverApi) { | |
| return function(dispatch, getState) { | |
| dispatch({ | |
| type: types.SAVE_ADDRESS, | |
| address: address | |
| }); | |
| let cleanAddress = getState().address; | |
| return serverApi.saveAddress(cleanAddress).then((json) => { | |
| if (areEmailsDifferent(cleanAddress, address)) { | |
| let response = Object.assign({}, json); |
This file contains hidden or 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
| it('deletes email when button is clicked', () => { | |
| let address = addressBuilder().withEmails([email0, email1]).build(); | |
| form.setProps({address: address}); | |
| actions.updateEmails = jest.fn((value) => { | |
| expect(value).toEqual(email1); | |
| }); | |
| const buttons = form.find(inputByClass(deleteEmailCss)); | |
| simulateClick(buttons.first()); |
This file contains hidden or 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
| beforeEach(()=> { | |
| form = shallow(<AddressForm | |
| address={{}} | |
| actions={actions} | |
| />); | |
| }); | |
| it('contains exactly one email input for every address email', () => { | |
| let address = addressBuilder().withEmails([email0, email1]).build(); | |
| form.setProps({address: address}); |
This file contains hidden or 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
| beforeEach(function () { | |
| spyRouter = { push: jest.fn() }; | |
| initialState = {profile: {id: '123456789H'}}; | |
| store = configureStore(initialState); | |
| }); | |
| it("clears store's state on logout", (done) => { | |
| expect(store.getState().profile.id).toEqual(initialState.profile.id); | |
| store.subscribe(() => { | |
| expect(store.getState().profile.id).toEqual(''); |
This file contains hidden or 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
| it("populates the store with server data", (done) => { | |
| const invoice = { | |
| reference: '0001', | |
| amount: '10.00', | |
| }; | |
| store.subscribe(() => { | |
| expect(store.getState().billing.invoices[0]).toEqual(invoice); | |
| done(); | |
| }); | |
| stubApi.getInvoices = () =>{ |
This file contains hidden or 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
| it("renders the invoice coming from server", (done) => { | |
| const invoice = { | |
| reference: '0001', | |
| amount: '10.00', | |
| }; | |
| spyNotifier.slowOperationFinished = () => { | |
| let billRow = page.find(BillsTable).first().find(BillRow); | |
| expect(billRow.length).toBe(1); | |
| done(); | |
| }; |
This file contains hidden or 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
| it("saves the profile in the backend", (done) => { | |
| simulateChangeInPhone(change); | |
| let savedProfile = spyOnSaveProfile(); | |
| eventually(() => { | |
| expect(savedProfile.phone).toEqual(change); | |
| }, done); | |
| saveProfileButton().simulate("click"); | |
| }); |
This file contains hidden or 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
| it("saves the profile in the backend", (done) => { | |
| simulateChangeInPhone(change); | |
| let actualProfile; | |
| spyNotifier.slowOperationFinished = () => { | |
| expect(actualProfile.phone).toEqual(change); | |
| done(); | |
| }; | |
| stubApi.saveProfile = (profile) => { | |
| actualProfile = profile; | |
| return Promise.resolve({message: 'Success'}); |
This file contains hidden or 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
| import * as actionTypes from '../constants/actionTypes'; | |
| import initialState from './initialState'; | |
| export default function profileReducer(profile = initialState.profile, action) { | |
| if (action.type == actionTypes.GET_PROFILE) { | |
| return Object.assign({}, profile, action.profile); | |
| } | |
| return profile; | |
| } |