|
@@ -1,19 +1,19 @@
|
|
|
import * as React from 'react';
|
|
import * as React from 'react';
|
|
|
-import {shallow, mount, render, ReactWrapper, ShallowWrapper} from 'enzyme';
|
|
|
|
|
|
|
+import {shallow, mount, ReactWrapper, ShallowWrapper} from 'enzyme';
|
|
|
import {createMockEnvironment, MockPayloadGenerator} from 'relay-test-utils';
|
|
import {createMockEnvironment, MockPayloadGenerator} from 'relay-test-utils';
|
|
|
import {QueryRenderer, graphql} from 'react-relay';
|
|
import {QueryRenderer, graphql} from 'react-relay';
|
|
|
-import ReactTestRenderer from 'react-test-renderer';
|
|
|
|
|
|
|
+import * as ReactTestRenderer from 'react-test-renderer';
|
|
|
|
|
|
|
|
// FIXME: imports in this manner work fine via `yarn test` but fails in-editor for code completion
|
|
// FIXME: imports in this manner work fine via `yarn test` but fails in-editor for code completion
|
|
|
-//import FragmentedPokemonShow, {PokemonShow} from 'packs/frontend/components/pages/pokemon/Show';
|
|
|
|
|
-//import {Show_pokemon as ShowPokemon} from 'packs/frontend/__generated__/Show_pokemon.graphql';
|
|
|
|
|
|
|
+//import FragmentedPokemonShow, {PokemonShow, Props} from 'packs/frontend/components/pages/pokemon/Show';
|
|
|
|
|
+//import {Show_pokemon} from 'packs/frontend/components/pages/pokemon/__generated__/Show_pokemon.graphql';
|
|
|
import FragmentedPokemonShow, {
|
|
import FragmentedPokemonShow, {
|
|
|
PokemonShow,
|
|
PokemonShow,
|
|
|
Props,
|
|
Props,
|
|
|
} from '../../../../../../app/javascript/packs/frontend/components/pages/pokemon/Show';
|
|
} from '../../../../../../app/javascript/packs/frontend/components/pages/pokemon/Show';
|
|
|
-import {Show_pokemon as ShowPokemon} from '../../../../../../app/javascript/packs/frontend/components/pages/pokemon/__generated__/Show_pokemon.graphql';
|
|
|
|
|
|
|
+import {Show_pokemon} from '../../../../../../app/javascript/packs/frontend/components/pages/pokemon/__generated__/Show_pokemon.graphql';
|
|
|
|
|
|
|
|
-const pokemon: ShowPokemon = {
|
|
|
|
|
|
|
+const pokemon: Show_pokemon = {
|
|
|
id: '1',
|
|
id: '1',
|
|
|
iid: 'x1',
|
|
iid: 'x1',
|
|
|
nickname: 'Bulbasaur',
|
|
nickname: 'Bulbasaur',
|
|
@@ -33,28 +33,34 @@ function mountSetup(props = defaultProps): ReactWrapper {
|
|
|
return mount(<PokemonShow {...props} />);
|
|
return mount(<PokemonShow {...props} />);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-describe('<PokemonShow />', (): void => {
|
|
|
|
|
- it('displays a pokemon', (): void => {
|
|
|
|
|
|
|
+describe('<PokemonShow />', () => {
|
|
|
|
|
+ it('displays a pokemon', () => {
|
|
|
const wrapper = setup();
|
|
const wrapper = setup();
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('requests data from a GraphQL fragment', () => {
|
|
it('requests data from a GraphQL fragment', () => {
|
|
|
const environment = createMockEnvironment();
|
|
const environment = createMockEnvironment();
|
|
|
|
|
+ const mockId = 'mock-id-1';
|
|
|
|
|
+
|
|
|
const TestRenderer = () => (
|
|
const TestRenderer = () => (
|
|
|
<QueryRenderer
|
|
<QueryRenderer
|
|
|
environment={environment}
|
|
environment={environment}
|
|
|
query={graphql`
|
|
query={graphql`
|
|
|
- query Show_pokemonSuccessQuery @relay_test_operation {
|
|
|
|
|
- pokemon(id: "mock-id-1") {
|
|
|
|
|
|
|
+ query Show_pokemonSuccessQuery($mockId: ID!) @relay_test_operation {
|
|
|
|
|
+ pokemon: node(id: $mockId) {
|
|
|
...Show_pokemon
|
|
...Show_pokemon
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
`}
|
|
`}
|
|
|
- variables={{}}
|
|
|
|
|
- render={({error, props}) => {
|
|
|
|
|
|
|
+ variables={{mockId}}
|
|
|
|
|
+ render={args => {
|
|
|
|
|
+ const {error, props} = args as {error: Error; props: Props};
|
|
|
if (props) {
|
|
if (props) {
|
|
|
- return <PokemonShow pokemon={(props as {pokemon: ShowPokemon}).pokemon} />;
|
|
|
|
|
|
|
+ // Prevent TS Compiler from complaining about unsupplied props
|
|
|
|
|
+ const Component = FragmentedPokemonShow as any;
|
|
|
|
|
+
|
|
|
|
|
+ return <Component pokemon={props.pokemon} />;
|
|
|
} else if (error) {
|
|
} else if (error) {
|
|
|
return error.message;
|
|
return error.message;
|
|
|
}
|
|
}
|
|
@@ -62,9 +68,19 @@ describe('<PokemonShow />', (): void => {
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
|
);
|
|
);
|
|
|
- const renderer = mount(<TestRenderer />);
|
|
|
|
|
- environment.mock.resolveMostRecentOperation(operation => MockPayloadGenerator.generate(operation));
|
|
|
|
|
|
|
|
|
|
|
|
+ environment.mock.queueOperationResolver(operation =>
|
|
|
|
|
+ MockPayloadGenerator.generate(operation, {
|
|
|
|
|
+ Pokemon: () => ({
|
|
|
|
|
+ id: mockId,
|
|
|
|
|
+ iid: '1',
|
|
|
|
|
+ nickname: 'Bulba',
|
|
|
|
|
+ pokedexNumber: 3,
|
|
|
|
|
+ }),
|
|
|
|
|
+ })
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ const renderer = ReactTestRenderer.create(<TestRenderer />);
|
|
|
expect(renderer).toMatchSnapshot();
|
|
expect(renderer).toMatchSnapshot();
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|