Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('mount the InterestSection with two interests', async t => {
const realStore = makeStore(initStore)
const myMock = fetchMock.sandbox()
reduxApi.use('fetch', adapterFetch(myMock))
myMock.getOnce(`${API_URL}/interests/?op=${opid}`, interests)
myMock.putOnce(`${API_URL}/interests/${interestid}`, invitedAndrew)
const wrapper = await mountWithIntl(
)
await sleep(1) // allow asynch fetch to complete
wrapper.update()
t.is(wrapper.find('tbody tr').length, 2)
t.regex(wrapper.find('tbody tr td').at(1).text(), /avowkind/)
t.regex(wrapper.find('tbody tr').at(1).find('td').at(1).text(), /Dali/)
// test invite button
test.serial('mount the InterestSection with two interests', async t => {
const realStore = makeStore(initStore)
const myMock = fetchMock.sandbox()
reduxApi.use('fetch', adapterFetch(myMock))
myMock.getOnce(`${API_URL}/interestsArchived/?op=${opid}`, interests)
myMock.putOnce(`${API_URL}/interestsArchived/${interests[0]._id}`, markAndrewAsPresent)
const wrapper = await mountWithIntl(
)
await sleep(1) // allow asynch fetch to complete
wrapper.update()
t.is(wrapper.find('h2').text(), 'Volunteers') // there are two cards on the screen
t.is(wrapper.find('tbody tr').length, 2)
t.is(wrapper.find('tbody tr td').at(0).text().trim(), people[0].nickname)
t.is(wrapper.find('tbody tr td').at(1).text().trim(), interests[0].comment)
t.is(wrapper.find('tbody tr td').at(2).text().trim(), interests[0].status)
test.serial('test filter by date is called, no op is shown', async t => {
const realStore = makeStore(initStore)
const myMock = fetchMock.sandbox()
reduxApi.use('fetch', adapterFetch(myMock))
const api = `${API_URL}/opportunities/?search=Growing`
myMock.get(api, ops)
const wrapper = await mountWithIntl(
{}} handleDeleteOp={() => {}} filter={filterDateState} dateFilterType={DatePickerType.IndividualDate} />
)
await sleep(1) // allow asynch fetch to complete
wrapper.update()
t.is(wrapper.find('OpCard').length, 0) // there are no cards on the screen
t.truthy(myMock.done())
myMock.restore()
})
test.serial('test filter by week is called. No opportunities shown', async t => {
const realStore = makeStore(initStore)
const monthFilterValue = {
date: [
'2019-03-02T00:00:00+00:00', // Sat, 02 Mar 2019 00:00:00
'2019-03-02T00:00:00+00:00' // Sat, 02 Mar 2019 00:00:00
]
}
const myMock = fetchMock.sandbox()
reduxApi.use('fetch', adapterFetch(myMock))
const api = `${API_URL}/opportunities/?search=Growing`
myMock.getOnce(api, [ops[0]])
const wrapper = await mountWithIntl(
{}} handleDeleteOp={() => {}} filter={monthFilterValue} dateFilterType={DatePickerType.WeekRange} />
)
await sleep(1) // allow asynch fetch to complete
wrapper.update()
t.is(wrapper.find('OpCard').length, 1)
t.truthy(myMock.done())
myMock.restore()
})
test.serial('mount RegisterInterestSection with op and me', async t => {
const realStore = makeStore(initStore)
const myMock = fetchMock.sandbox()
reduxApi.use('fetch', adapterFetch(myMock))
const getmyinterests = `${API_URL}/interests/?op=${opid}&me=${meid}`
myMock.getOnce(getmyinterests, interests[0])
const wrapper = await mountWithIntl(
)
// before api completes the loading spinner should show.
t.is(wrapper.find('img').prop('src'), '/static/loading.svg')
await sleep(1) // allow asynch fetch to complete
wrapper.update()
test.serial('mount RegisterInterestSection with with no existing interest', async t => {
const realStore = makeStore(initStore)
const myMock = fetchMock.sandbox()
reduxApi.use('fetch', adapterFetch(myMock))
const getmyinterests = `${API_URL}/interests/?op=${opid}&me=${meid}`
myMock.getOnce(getmyinterests, [])
const wrapper = await mountWithIntl(
)
await sleep(1) // allow asynch fetch to complete
wrapper.update()
// we should see "i'm interested"
t.is(wrapper.find('button').first().text(), "I'm Interested")
test.before('Setup fixtures', t => {
fixture(t)
const initStore = {
members: {
loading: false,
data: [ ]
},
session: {
me: t.context.people[1]
}
}
t.context.store = makeStore(initStore)
t.context.fetchMock = fetchMock.sandbox()
t.context.fetchMock.config.overwriteRoutes = false
reduxApi.use('fetch', adapterFetch(t.context.fetchMock))
t.context.orgMembers = (status, who) => [
{
_id: objectid().toString(),
person: t.context.people[who],
organisation: t.context.orgs[0],
status
}
]
})
test.serial('mount the InterestSection with no interests', async t => {
const realStore = makeStore(initStore)
const myMock = fetchMock.sandbox()
const fakeObjectId = mongoose.Types.ObjectId().toString()
reduxApi.use('fetch', adapterFetch(myMock))
myMock.getOnce(`${API_URL}/interestsArchived/?op=${fakeObjectId}`, [])
const wrapper = await mountWithIntl(
)
t.is(wrapper.find('p').text(), 'No Data')
})
test.before('Setup fixtures', t => {
fixture(t)
const initStore = {
members: {
loading: false,
data: []
},
session: {
me: t.context.people[0]
}
}
t.context.store = makeStore(initStore)
t.context.fetchMock = fetchMock.sandbox()
t.context.fetchMock.config.overwriteRoutes = false
reduxApi.use('fetch', adapterFetch(t.context.fetchMock))
})
test.serial('retrieve completed archived opportunities', async t => {
const props = {
me: t.context.me
}
const { fetchMock } = require('fetch-mock')
const myMock = fetchMock.sandbox()
myMock.get(API_URL + '/archivedOpportunities/', { body: { archivedOpportunities } })
reduxApi.use('fetch', adapterFetch(myMock))
const wrapper = mountWithIntl(
)
const res = await wrapper.find('PersonHomePage').first().instance().getArchivedOpportunitiesByStatus('completed')
t.is(res.length, 3)
t.is(res[0], archivedOpportunities[0])
t.is(res[1], archivedOpportunities[1])
})