-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into 426_Empty_card
- Loading branch information
Showing
12 changed files
with
302 additions
and
164 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
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
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
105 changes: 91 additions & 14 deletions
105
src/containers/Causes/CampaignsEndingSoon/CampaignEndingSoon.test.js
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 |
---|---|---|
@@ -1,24 +1,101 @@ | ||
import React from 'react' | ||
import CampaignsEndingSoon from './CampaignsEndingSoon' | ||
import { shallow } from 'enzyme' | ||
import { mount } from 'enzyme' | ||
import { MockedProvider } from '@apollo/react-testing' | ||
import { act } from 'react-dom/test-utils' | ||
import { MemoryRouter as Router } from 'react-router-dom' | ||
import CampaignsEndingSoon, { GET_CAUSES_ENDING_SOON_QUERY } from './CampaignsEndingSoon' | ||
|
||
describe('<CampaignsEndingSoon />', () => { | ||
let campaignsEndingSoonWrapper | ||
beforeEach(() => { | ||
campaignsEndingSoonWrapper = shallow(<CampaignsEndingSoon />) | ||
async function mountMockedProvider(result) { | ||
const mocks = [ | ||
{ | ||
request: { | ||
query: GET_CAUSES_ENDING_SOON_QUERY, | ||
variables: { 'scope': 'ending_soon' } | ||
}, | ||
result | ||
} | ||
] | ||
jest.useFakeTimers() | ||
const component = mount( | ||
<MockedProvider | ||
mocks={mocks} | ||
addTypename={false} | ||
> | ||
<Router> | ||
<CampaignsEndingSoon /> | ||
</Router> | ||
</MockedProvider>) | ||
act(() => { | ||
jest.runAllTimers() | ||
}) | ||
component.update() | ||
return component | ||
} | ||
|
||
it("has 'Campaign Ending Soon' title", () => { | ||
expect(campaignsEndingSoonWrapper.find('h3').text()).toEqual( | ||
'Campaigns ending soon' | ||
) | ||
describe('<CampaignsEndingSoon />', () => { | ||
let campaignsEndingSoonWrapper, data | ||
beforeEach(async() => { | ||
data = { | ||
'data': { | ||
'causes': [ | ||
{ | ||
amountRaised: 5000, | ||
endDate: new Date('2019-12-12'), | ||
id: 3, | ||
name: 'Awesome Cause 1', | ||
targetAmount: 1000 | ||
}, | ||
{ | ||
amountRaised: 5000, | ||
endDate: new Date('2019-12-18'), | ||
id: 4, | ||
name: 'Awesome Cause 2', | ||
targetAmount: 1000 | ||
} | ||
] | ||
} | ||
} | ||
campaignsEndingSoonWrapper = await mountMockedProvider(data) | ||
}) | ||
|
||
it('has 2 campaign cards that end soon showing underneath', () => { | ||
expect(campaignsEndingSoonWrapper.find('CauseCard').length).toEqual(2) | ||
describe('data resolves with no error', () => { | ||
it("has 'Campaign Ending Soon' title", () => { | ||
expect(campaignsEndingSoonWrapper.find('h3').text()).toEqual( | ||
'Campaigns ending soon' | ||
) | ||
}) | ||
|
||
it('has 2 campaign cards that end soon showing underneath', () => { | ||
expect(campaignsEndingSoonWrapper.find('CauseCard').length).toEqual(2) | ||
}) | ||
|
||
it('has link to navigate to all ending causes', () => { | ||
expect(campaignsEndingSoonWrapper.find('NavLink').length).toEqual(1) | ||
}) | ||
|
||
describe('CauseCard', () => { | ||
it('has two cause cards cause card', () => { | ||
expect(campaignsEndingSoonWrapper.find('CauseCard').length).toEqual(2) | ||
}) | ||
|
||
it('first cause card has correct cause name', () => { | ||
expect(campaignsEndingSoonWrapper.find('CauseCard').at(0).find('.cause-card-name').text()).toEqual('Awesome Cause 1') | ||
}) | ||
|
||
it('second cause card has correct cause name', () => { | ||
expect(campaignsEndingSoonWrapper.find('CauseCard').at(1).find('.cause-card-name').text()).toEqual('Awesome Cause 2') | ||
}) | ||
}) | ||
}) | ||
|
||
it('has link to navigate to all ending causes', () => { | ||
expect(campaignsEndingSoonWrapper.find('NavLink').length).toEqual(1) | ||
describe('data resolved with error', () => { | ||
let result | ||
beforeEach(async () => { | ||
result = { error: new Error('aw shucks') } | ||
campaignsEndingSoonWrapper = await mountMockedProvider(result) | ||
}) | ||
it('displays error div', () => { | ||
expect(campaignsEndingSoonWrapper.find('div').text()).toEqual('Error') | ||
}) | ||
}) | ||
}) |
73 changes: 49 additions & 24 deletions
73
src/containers/Causes/CampaignsEndingSoon/CampaignsEndingSoon.js
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
Oops, something went wrong.