Skip to content

Commit

Permalink
App Loader test
Browse files Browse the repository at this point in the history
  • Loading branch information
maspinguin committed Sep 24, 2019
1 parent 6ce4f80 commit 340f49a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/component/AppLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class AppLoader extends React.Component {
`}
render={({ error, props }) => {
if(error) {
console.log('error', error)
// console.log('error', error)
return <div>error</div>
}
else if(props) {
return <App viewer={props.viewer}/>
}
return 'loading...';
return <div>loading...</div>;
}}
></QueryRenderer>
)
Expand Down
4 changes: 2 additions & 2 deletions src/component/Client/ClientListLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ClientListLoader extends React.Component{
query={query}
render={({ error, props }) => {
if(error) {
console.log('error', error)
// console.log('error', error)
return <div>error</div>
}
else if(props) {
Expand All @@ -27,7 +27,7 @@ class ClientListLoader extends React.Component{
viewer={props.viewer}
/>
}
return 'loading...';
return <div>loading...</div>;
}}
></QueryRenderer>
)
Expand Down
39 changes: 36 additions & 3 deletions src/component/__tests__/AppLoader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import TestHelper from '../../helper/TestHelper';

import AppLoader from '../AppLoader';

import App from "../App";

// Mock relayService.environment with createMockEnvironment;
import RelayService from '../../services/RelayService';
import App from "../App";
jest.mock('../../services/RelayService');

describe('AppLoader', () => {
Expand All @@ -25,12 +24,46 @@ describe('AppLoader', () => {
<AppLoader/>
);

const loading = wrapper.root
.findAllByType('div')
.find(TestHelper.findInChildren(node => node === 'loading...'));
expect(loading).not.toEqual(undefined);
});

it('should render error of App Loader', async () => {
const wrapper = create(
<AppLoader/>
);

const newError = new Error('Network Error');
environment.mock.rejectMostRecentOperation(newError);

const queryError = wrapper.root
.findAllByType('div')
.find(TestHelper.findInChildren(node => node === 'error'));
expect(queryError).not.toEqual(undefined);
});
})

it('should render success of App Loader', async () => {
const wrapper = create(
<AppLoader/>
);

environment.mock.resolveMostRecentOperation(operation =>
MockPayloadGenerator.generate(operation, {
String(context, generateId) {
if(context.name === 'id') {
return generateId;
}
if(context.name === 'plainId'){
return '1';
}
}
})
);

const AppWrapper = wrapper.root.findByType(App);
expect(AppWrapper).not.toEqual(undefined);

})
});

0 comments on commit 340f49a

Please sign in to comment.