-
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 pull request #453 from AgileVentures/451_link_performances_to_b…
…ackend Linking performances to DB [WIP]
- Loading branch information
Showing
5 changed files
with
163 additions
and
58 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
68 changes: 41 additions & 27 deletions
68
src/containers/Performances/TrendingPerformances/TrendingPerformances.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
105 changes: 92 additions & 13 deletions
105
src/containers/Performances/TrendingPerformances/TrendingPerformances.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,22 +1,101 @@ | ||
import React from 'react' | ||
import TrendingPerformances from './TrendingPerformances' | ||
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 TrendingPerformances, { | ||
GET_TRENDING_PERFORMANCES_QUERY | ||
} from './TrendingPerformances' | ||
|
||
async function mountMockedProvider(result) { | ||
const mocks = [ | ||
{ | ||
request: { | ||
query: GET_TRENDING_PERFORMANCES_QUERY | ||
}, | ||
result | ||
} | ||
] | ||
jest.useFakeTimers() | ||
const component = mount( | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<Router> | ||
<TrendingPerformances /> | ||
</Router> | ||
</MockedProvider> | ||
) | ||
act(() => { | ||
jest.runAllTimers() | ||
}) | ||
component.update() | ||
return component | ||
} | ||
|
||
describe('<TrendingPerformances />', () => { | ||
let TrendingPerformancesWrapper | ||
beforeEach(() => { | ||
TrendingPerformancesWrapper = shallow(<TrendingPerformances />) | ||
let trendingPerformancesWrapper, data | ||
|
||
beforeEach(async () => { | ||
data = { | ||
data: { | ||
performances: [ | ||
{ | ||
id: 1, | ||
amountRaised: 5000, | ||
detail: 'Awesome Performance 1', | ||
isFeatured: true | ||
}, | ||
{ | ||
id: 2, | ||
amountRaised: 5000, | ||
detail: 'Awesome Performance 2', | ||
isFeatured: false | ||
}, | ||
{ | ||
id: 3, | ||
amountRaised: 2333, | ||
detail: 'Awesome Performance 3', | ||
isFeatured: false | ||
} | ||
] | ||
} | ||
} | ||
trendingPerformancesWrapper = await mountMockedProvider(data) | ||
}) | ||
describe('success', () => { | ||
it("has 'Trending Performances' title", () => { | ||
expect(trendingPerformancesWrapper.find('h1').text()).toEqual( | ||
'Trending Performances' | ||
) | ||
}) | ||
|
||
describe('PerformanceCard', () => { | ||
it('has 3 performance cards', () => { | ||
expect(trendingPerformancesWrapper.find('PerformanceCard').length).toEqual( | ||
3 | ||
) | ||
}) | ||
|
||
it('first performance card has correct description', () => { | ||
expect(trendingPerformancesWrapper.find('PerformanceCard').at(0).find('.performance-text p').text()).toEqual('Awesome Performance 1') | ||
}) | ||
|
||
it("has 'Trending Performances' title", () => { | ||
expect(TrendingPerformancesWrapper.find('h1').text()).toEqual( | ||
'Trending Performances' | ||
) | ||
it('second cause card has correct cause name', () => { | ||
expect(trendingPerformancesWrapper.find('PerformanceCard').at(1).find('.performance-text p').text()).toEqual('Awesome Performance 2') | ||
}) | ||
it('third cause card has correct cause name', () => { | ||
expect(trendingPerformancesWrapper.find('PerformanceCard').at(2).find('.performance-text p').text()).toEqual('Awesome Performance 3') | ||
}) | ||
}) | ||
}) | ||
|
||
it('has 3 performances featured in the top section', () => { | ||
expect(TrendingPerformancesWrapper.find('PerformanceCard').length).toEqual( | ||
3 | ||
) | ||
describe('error', () => { | ||
let result | ||
beforeEach(async () => { | ||
result = { error: new Error('aw shucks') } | ||
trendingPerformancesWrapper = await mountMockedProvider(result) | ||
}) | ||
it('displays error div', () => { | ||
expect(trendingPerformancesWrapper.find('div').text()).toEqual('Error') | ||
}) | ||
}) | ||
}) |