Created
July 21, 2019 18:18
-
-
Save pierreabreup/1db2a38b539492917e94e221367b8b26 to your computer and use it in GitHub Desktop.
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
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