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 402
/
Copy pathgithub-tab-header-container.test.js
90 lines (74 loc) · 3.04 KB
/
github-tab-header-container.test.js
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
import React from 'react';
import {shallow} from 'enzyme';
import {QueryRenderer} from 'react-relay';
import GithubTabHeaderContainer from '../../lib/containers/github-tab-header-container';
import {queryBuilder} from '../builder/graphql/query';
import {DOTCOM} from '../../lib/models/endpoint';
import {UNAUTHENTICATED, INSUFFICIENT} from '../../lib/shared/keytar-strategy';
import tabHeaderQuery from '../../lib/containers/__generated__/githubTabHeaderContainerQuery.graphql';
describe('GithubTabHeaderContainer', function() {
let atomEnv;
beforeEach(function() {
atomEnv = global.buildAtomEnvironment();
});
afterEach(function() {
atomEnv.destroy();
});
function buildApp(overrideProps = {}) {
return (
<GithubTabHeaderContainer
endpoint={DOTCOM}
token="1234"
currentWorkDir={null}
contextLocked={false}
changeWorkingDirectory={() => {}}
setContextLock={() => {}}
getCurrentWorkDirs={() => new Set()}
onDidChangeWorkDirs={() => {}}
{...overrideProps}
/>
);
}
it('renders a null user if the token is still loading', function() {
const wrapper = shallow(buildApp({token: null}));
assert.isFalse(wrapper.find('GithubTabHeaderController').prop('user').isPresent());
});
it('renders a null user if no token is found', function() {
const wrapper = shallow(buildApp({token: UNAUTHENTICATED}));
assert.isFalse(wrapper.find('GithubTabHeaderController').prop('user').isPresent());
});
it('renders a null user if the token has insufficient OAuth scopes', function() {
const wrapper = shallow(buildApp({token: INSUFFICIENT}));
assert.isFalse(wrapper.find('GithubTabHeaderController').prop('user').isPresent());
});
it('renders a null user if there was an error acquiring the token', function() {
const e = new Error('oops');
e.rawStack = e.stack;
const wrapper = shallow(buildApp({token: e}));
assert.isFalse(wrapper.find('GithubTabHeaderController').prop('user').isPresent());
});
it('renders a null user while the GraphQL query is being performed', function() {
const wrapper = shallow(buildApp());
const resultWrapper = wrapper.find(QueryRenderer).renderProp('render')({
error: null,
props: null,
retry: () => {},
});
assert.isFalse(resultWrapper.find('GithubTabHeaderController').prop('user').isPresent());
});
it('renders the controller once results have arrived', function() {
const wrapper = shallow(buildApp());
const props = queryBuilder(tabHeaderQuery)
.viewer(v => {
v.name('user');
v.email('[email protected]');
v.avatarUrl('https://imageurl.com/test.jpg');
v.login('us3rh4nd13');
})
.build();
const resultWrapper = wrapper.find(QueryRenderer).renderProp('render')({error: null, props, retry: () => {}});
const controller = resultWrapper.find('GithubTabHeaderController');
assert.isTrue(controller.prop('user').isPresent());
assert.strictEqual(controller.prop('user').getEmail(), '[email protected]');
});
});