@@ -4,18 +4,16 @@ import {QueryRenderer} from 'react-relay';
4
4
5
5
import GithubTabHeaderContainer from '../../lib/containers/github-tab-header-container' ;
6
6
import { queryBuilder } from '../builder/graphql/query' ;
7
- import GithubLoginModel from '../../lib/models/github-login-model' ;
8
- import { getEndpoint } from '../../lib/models/endpoint' ;
9
- import { InMemoryStrategy , INSUFFICIENT , UNAUTHENTICATED } from '../../lib/shared/keytar-strategy' ;
7
+ import { DOTCOM } from '../../lib/models/endpoint' ;
8
+ import { UNAUTHENTICATED , INSUFFICIENT } from '../../lib/shared/keytar-strategy' ;
10
9
11
10
import tabHeaderQuery from '../../lib/containers/__generated__/githubTabHeaderContainerQuery.graphql' ;
12
11
13
12
describe ( 'GithubTabHeaderContainer' , function ( ) {
14
- let atomEnv , model ;
13
+ let atomEnv ;
15
14
16
15
beforeEach ( function ( ) {
17
16
atomEnv = global . buildAtomEnvironment ( ) ;
18
- model = new GithubLoginModel ( InMemoryStrategy ) ;
19
17
} ) ;
20
18
21
19
afterEach ( function ( ) {
@@ -25,65 +23,56 @@ describe('GithubTabHeaderContainer', function() {
25
23
function buildApp ( overrideProps = { } ) {
26
24
return (
27
25
< GithubTabHeaderContainer
28
- loginModel = { model }
29
- endpoint = { getEndpoint ( 'github.com' ) }
26
+ endpoint = { DOTCOM }
27
+ token = "1234"
28
+
30
29
currentWorkDir = { null }
31
30
contextLocked = { false }
32
31
changeWorkingDirectory = { ( ) => { } }
33
32
setContextLock = { ( ) => { } }
34
33
getCurrentWorkDirs = { ( ) => new Set ( ) }
34
+
35
35
onDidChangeWorkDirs = { ( ) => { } }
36
36
{ ...overrideProps }
37
37
/>
38
38
) ;
39
39
}
40
40
41
- it ( 'renders a null user while the GraphQL query is being performed' , async function ( ) {
42
- model . setToken ( 'https://api.github.com' , '1234' ) ;
43
-
44
- sinon . spy ( model , 'getToken' ) ;
45
- sinon . stub ( model , 'getScopes' ) . resolves ( GithubLoginModel . REQUIRED_SCOPES ) ;
46
-
47
- const wrapper = shallow ( buildApp ( ) ) ;
48
-
49
- assert . strictEqual ( await wrapper . find ( 'ObserveModel' ) . prop ( 'fetchData' ) ( model ) , '1234' ) ;
50
- const tokenWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
51
-
52
- const resultWrapper = tokenWrapper . find ( QueryRenderer ) . renderProp ( 'render' ) ( {
53
- error : null ,
54
- props : null ,
55
- retry : ( ) => { } ,
56
- } ) ;
57
-
58
- assert . isFalse ( resultWrapper . find ( 'GithubTabHeaderController' ) . prop ( 'user' ) . isPresent ( ) ) ;
41
+ it ( 'renders a null user if the token is still loading' , function ( ) {
42
+ const wrapper = shallow ( buildApp ( { token : null } ) ) ;
43
+ assert . isFalse ( wrapper . find ( 'GithubTabHeaderController' ) . prop ( 'user' ) . isPresent ( ) ) ;
59
44
} ) ;
60
45
61
46
it ( 'renders a null user if no token is found' , function ( ) {
62
- const wrapper = shallow ( buildApp ( ) ) ;
63
- const tokenWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( UNAUTHENTICATED ) ;
64
- assert . isFalse ( tokenWrapper . find ( 'GithubTabHeaderController' ) . prop ( 'user' ) . isPresent ( ) ) ;
47
+ const wrapper = shallow ( buildApp ( { token : UNAUTHENTICATED } ) ) ;
48
+ assert . isFalse ( wrapper . find ( 'GithubTabHeaderController' ) . prop ( 'user' ) . isPresent ( ) ) ;
65
49
} ) ;
66
50
67
51
it ( 'renders a null user if the token has insufficient OAuth scopes' , function ( ) {
68
- const wrapper = shallow ( buildApp ( ) ) ;
69
- const tokenWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( INSUFFICIENT ) ;
70
-
71
- assert . isFalse ( tokenWrapper . find ( 'GithubTabHeaderController' ) . prop ( 'user' ) . isPresent ( ) ) ;
52
+ const wrapper = shallow ( buildApp ( { token : INSUFFICIENT } ) ) ;
53
+ assert . isFalse ( wrapper . find ( 'GithubTabHeaderController' ) . prop ( 'user' ) . isPresent ( ) ) ;
72
54
} ) ;
73
55
74
- it ( 'renders a null user if the user is offline' , function ( ) {
75
- sinon . spy ( model , 'didUpdate' ) ;
56
+ it ( 'renders a null user if there was an error acquiring the token' , function ( ) {
57
+ const e = new Error ( 'oops' ) ;
58
+ e . rawStack = e . stack ;
59
+ const wrapper = shallow ( buildApp ( { token : e } ) ) ;
60
+ assert . isFalse ( wrapper . find ( 'GithubTabHeaderController' ) . prop ( 'user' ) . isPresent ( ) ) ;
61
+ } ) ;
76
62
63
+ it ( 'renders a null user while the GraphQL query is being performed' , function ( ) {
77
64
const wrapper = shallow ( buildApp ( ) ) ;
78
- const e = new Error ( 'oh no' ) ;
79
- const tokenWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( e ) ;
80
- assert . isFalse ( tokenWrapper . find ( 'GithubTabHeaderController' ) . prop ( 'user' ) . isPresent ( ) ) ;
65
+ const resultWrapper = wrapper . find ( QueryRenderer ) . renderProp ( 'render' ) ( {
66
+ error : null ,
67
+ props : null ,
68
+ retry : ( ) => { } ,
69
+ } ) ;
70
+
71
+ assert . isFalse ( resultWrapper . find ( 'GithubTabHeaderController' ) . prop ( 'user' ) . isPresent ( ) ) ;
81
72
} ) ;
82
73
83
74
it ( 'renders the controller once results have arrived' , function ( ) {
84
75
const wrapper = shallow ( buildApp ( ) ) ;
85
- const tokenWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
86
-
87
76
const props = queryBuilder ( tabHeaderQuery )
88
77
. viewer ( v => {
89
78
v . name ( 'user' ) ;
@@ -92,7 +81,7 @@ describe('GithubTabHeaderContainer', function() {
92
81
v . login ( 'us3rh4nd13' ) ;
93
82
} )
94
83
. build ( ) ;
95
- const resultWrapper = tokenWrapper . find ( QueryRenderer ) . renderProp ( 'render' ) ( { error : null , props, retry : ( ) => { } } ) ;
84
+ const resultWrapper = wrapper . find ( QueryRenderer ) . renderProp ( 'render' ) ( { error : null , props, retry : ( ) => { } } ) ;
96
85
97
86
const controller = resultWrapper . find ( 'GithubTabHeaderController' ) ;
98
87
assert . isTrue ( controller . prop ( 'user' ) . isPresent ( ) ) ;
0 commit comments