Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pierreabreup/1db2a38b539492917e94e221367b8b26 to your computer and use it in GitHub Desktop.
Save pierreabreup/1db2a38b539492917e94e221367b8b26 to your computer and use it in GitHub Desktop.
import React from 'react'
import { mount } from 'enzyme'
import { MockedProvider } from "react-apollo/test-utils"
import { InMemoryCache } from 'apollo-cache-inmemory'
import { BrowserRouter } from 'react-router-dom'
import { TrailDetails } from 'views'
import { GRAPHQL_MOCKS_TRAILS } from '__mocks__/TrailDetails/GraphqlMocks.js'
import {IntrospectionFragmentMatcher} from 'apollo-cache-inmemory';
import introspectionQueryResultData from '../../../mobyGraphqlSchema.json';
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData
});
const waitForExpect = require('wait-for-expect')
describe('When <TrailDetails /> is rendering', () => {
describe('and there are unpublished trail nodes', () => {
it ('show unavailable content info message', async () => {
const props = {
match: {
url: '/trails/cordados-sarah'
},
location: {
hash: "#1472"
}
}
const wrapper = mount(
<BrowserRouter>
<MockedProvider mocks={GRAPHQL_MOCKS_TRAILS.unpublishedNodes} addTypename={true} cache={new InMemoryCache({ fragmentMatcher })}>
<TrailDetails {...props}/>
</MockedProvider>
</BrowserRouter>
)
await waitForExpect(() => {
wrapper.update()
expect(wrapper.text()).toMatch("There is no published content available")
})
})
})
describe('and there are published trail nodes', () => {
it ('show trail title', async () => {
const props = {
match: {
url: '/trails/e-preciso-tratar-agua'
},
location: {
hash: "#1471"
}
}
const trailTitle = GRAPHQL_MOCKS_TRAILS.publishedNodes[0].result.data.route.entity.name
const wrapper = mount(
<BrowserRouter>
<MockedProvider mocks={GRAPHQL_MOCKS_TRAILS.publishedNodes} addTypename={true} cache={new InMemoryCache({ fragmentMatcher })}>
<TrailDetails {...props}/>
</MockedProvider>
</BrowserRouter>
)
await waitForExpect(() => {
wrapper.update()
expect(wrapper.text()).toMatch(trailTitle)
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment