Created
October 30, 2017 04:32
-
-
Save lmatteis/a9f6b9d4df7fd5b92c22ff953b41bce1 to your computer and use it in GitHub Desktop.
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 React from 'react' | |
import { mount } from 'enzyme'; | |
import { generate } from 'apiEndpoint'; | |
import fetchMock from 'fetch-mock'; | |
import xhrMock from 'xhr-mock'; | |
xhrMock.setup() | |
import { BoostApp, store } from '../../bundles/hootsuite-boost'; | |
import boostResponses from './fixtures/boost_responses'; | |
import LoadingScreen from '../components/LoadingScreen'; | |
import Campaign from '../components/boost/Campaign'; | |
function nextTick(done, fn) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
try { | |
resolve() | |
} catch(e) { | |
reject(e) | |
done.fail(e) | |
} | |
}) | |
}) | |
} | |
describe('BoostApp', () => { | |
it('should test campaign creation flow', async (done) => { | |
fetchMock.mock(generate('new_api_me'), boostResponses['new_api_me']); | |
const wrapper = mount(BoostApp); | |
expect(wrapper.find(LoadingScreen)).toHaveLength(1) | |
await nextTick(done) | |
expect(wrapper.find(LoadingScreen)).toHaveLength(0) | |
fetchMock.mock(generate('new_api_campaigns?'), boostResponses['new_api_campaigns?']); | |
// click Overview | |
wrapper.findWhere(node => node.props().to === '/overview').find('a').simulate('click', { button: 0 }); | |
expect(wrapper.contains(<div className="hs-msg hs-msg-loading">Loading campaigns...</div>)).toEqual(true) | |
await nextTick(done) | |
expect(wrapper.find(Campaign).length).toEqual(boostResponses['new_api_campaigns?'].items.length) | |
// gotta use xhrMock because some parts use XMLHttpRequest instead of fetch | |
xhrMock.get(generate('new_api_me_ad_accounts'), (req, res) => { | |
return res | |
.status(201) | |
.header('Content-Type', 'application/json') | |
.body(boostResponses['new_api_me_ad_accounts']); | |
}) | |
// click on Manage accounts | |
wrapper.findWhere(node => node.props().to === '/manage-accounts').find('a').simulate('click', { button: 0 }); | |
expect(store.getState().accounts.fetching).toEqual(true) | |
await nextTick(done) | |
expect(store.getState().accounts.fetching).toEqual(false) | |
expect(wrapper.find('tbody tr')).toHaveLength(2) | |
done(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment