This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 408
Expand file tree
/
Copy pathcreate-dialog-container.test.js
More file actions
92 lines (72 loc) · 3.58 KB
/
create-dialog-container.test.js
File metadata and controls
92 lines (72 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React from 'react';
import {QueryRenderer} from 'react-relay';
import {shallow} from 'enzyme';
import CreateDialogContainer from '../../lib/containers/create-dialog-container';
import CreateDialogController from '../../lib/controllers/create-dialog-controller';
import {dialogRequests} from '../../lib/controllers/dialogs-controller';
import {InMemoryStrategy} from '../../lib/shared/keytar-strategy';
import GithubLoginModel from '../../lib/models/github-login-model';
import {getEndpoint} from '../../lib/models/endpoint';
import {queryBuilder} from '../builder/graphql/query';
import query from '../../lib/containers/__generated__/createDialogContainerQuery.graphql';
const DOTCOM = getEndpoint('github.com');
describe('CreateDialogContainer', function() {
let atomEnv;
beforeEach(function() {
atomEnv = global.buildAtomEnvironment();
});
afterEach(function() {
atomEnv.destroy();
});
function buildApp(override = {}) {
return (
<CreateDialogContainer
loginModel={new GithubLoginModel(InMemoryStrategy)}
request={dialogRequests.create()}
inProgress={false}
currentWindow={atomEnv.getCurrentWindow()}
workspace={atomEnv.workspace}
commands={atomEnv.commands}
config={atomEnv.config}
{...override}
/>
);
}
it('renders nothing before the token is provided', function() {
const loginModel = new GithubLoginModel(InMemoryStrategy);
loginModel.setToken('https://api.github.com', 'good-token');
const wrapper = shallow(buildApp({loginModel}));
const tokenWrapper = wrapper.find('ObserveModel').renderProp('children')(null);
assert.isTrue(tokenWrapper.isEmptyRender());
});
it('fetches the login token from the login model', async function() {
const loginModel = new GithubLoginModel(InMemoryStrategy);
loginModel.setToken(DOTCOM.getLoginAccount(), 'good-token');
const wrapper = shallow(buildApp({loginModel}));
const observer = wrapper.find('ObserveModel');
assert.strictEqual(observer.prop('model'), loginModel);
assert.strictEqual(await observer.prop('fetchData')(loginModel), 'good-token');
});
it('renders the dialog controller in a loading state before the GraphQL query completes', function() {
const wrapper = shallow(buildApp());
const tokenWrapper = wrapper.find('ObserveModel').renderProp('children')('good-token');
const queryWrapper = tokenWrapper.find(QueryRenderer).renderProp('render')({error: null, props: null});
assert.isNull(queryWrapper.find(CreateDialogController).prop('user'));
assert.isTrue(queryWrapper.find(CreateDialogController).prop('isLoading'));
});
it('passes GraphQL errors to the dialog controller', function() {
const error = new Error('AAHHHHHHH');
const wrapper = shallow(buildApp());
const tokenWrapper = wrapper.find('ObserveModel').renderProp('children')('good-token');
const queryWrapper = tokenWrapper.find(QueryRenderer).renderProp('render')({error, props: null});
assert.isNull(queryWrapper.find(CreateDialogController).prop('user'));
assert.strictEqual(queryWrapper.find(CreateDialogController).prop('error'), error);
});
it('passes GraphQL query results to the dialog controller', function() {
const props = queryBuilder(query).build();
const wrapper = shallow(buildApp());
const tokenWrapper = wrapper.find('ObserveModel').renderProp('children')('good-token');
const queryWrapper = tokenWrapper.find(QueryRenderer).renderProp('render')({error: null, props});
assert.strictEqual(queryWrapper.find(CreateDialogController).prop('user'), props.viewer);
});
});