@@ -3,25 +3,21 @@ import {shallow} from 'enzyme';
3
3
import { QueryRenderer } from 'react-relay' ;
4
4
5
5
import RemoteContainer from '../../lib/containers/remote-container' ;
6
- import * as reporterProxy from '../../lib/reporter-proxy' ;
7
6
import { queryBuilder } from '../builder/graphql/query' ;
8
7
import Remote from '../../lib/models/remote' ;
9
8
import RemoteSet from '../../lib/models/remote-set' ;
10
9
import Branch , { nullBranch } from '../../lib/models/branch' ;
11
10
import BranchSet from '../../lib/models/branch-set' ;
12
- import GithubLoginModel from '../../lib/models/github-login-model' ;
13
- import { getEndpoint } from '../../lib/models/endpoint' ;
11
+ import { DOTCOM } from '../../lib/models/endpoint' ;
14
12
import Refresher from '../../lib/models/refresher' ;
15
- import { InMemoryStrategy , INSUFFICIENT , UNAUTHENTICATED } from '../../lib/shared/keytar-strategy' ;
16
13
17
14
import remoteQuery from '../../lib/containers/__generated__/remoteContainerQuery.graphql' ;
18
15
19
16
describe ( 'RemoteContainer' , function ( ) {
20
- let atomEnv , model ;
17
+ let atomEnv ;
21
18
22
19
beforeEach ( function ( ) {
23
20
atomEnv = global . buildAtomEnvironment ( ) ;
24
- model = new GithubLoginModel ( InMemoryStrategy ) ;
25
21
} ) ;
26
22
27
23
afterEach ( function ( ) {
@@ -36,45 +32,30 @@ describe('RemoteContainer', function() {
36
32
37
33
return (
38
34
< RemoteContainer
39
- loginModel = { model }
40
- endpoint = { getEndpoint ( 'github.com' ) }
35
+ endpoint = { DOTCOM }
36
+ token = "1234"
41
37
42
38
refresher = { new Refresher ( ) }
39
+ pushInProgress = { false }
43
40
workingDirectory = { __dirname }
44
- notifications = { atomEnv . notifications }
45
41
workspace = { atomEnv . workspace }
46
42
remote = { origin }
47
43
remotes = { remotes }
48
44
branches = { branches }
49
-
50
45
aheadCount = { 0 }
51
- pushInProgress = { false }
52
46
47
+ handleLogin = { ( ) => { } }
48
+ handleLogout = { ( ) => { } }
53
49
onPushBranch = { ( ) => { } }
54
50
55
51
{ ...overrideProps }
56
52
/>
57
53
) ;
58
54
}
59
55
60
- it ( 'renders a loading spinner while the token is being fetched ' , function ( ) {
56
+ it ( 'renders a loading spinner while the GraphQL query is being performed ' , function ( ) {
61
57
const wrapper = shallow ( buildApp ( ) ) ;
62
- const tokenWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( null ) ;
63
- assert . isTrue ( tokenWrapper . exists ( 'LoadingView' ) ) ;
64
- } ) ;
65
-
66
- it ( 'renders a loading spinner while the GraphQL query is being performed' , async function ( ) {
67
- model . setToken ( 'https://api.github.com' , '1234' ) ;
68
-
69
- sinon . spy ( model , 'getToken' ) ;
70
- sinon . stub ( model , 'getScopes' ) . resolves ( GithubLoginModel . REQUIRED_SCOPES ) ;
71
-
72
- const wrapper = shallow ( buildApp ( ) ) ;
73
-
74
- assert . strictEqual ( await wrapper . find ( 'ObserveModel' ) . prop ( 'fetchData' ) ( model ) , '1234' ) ;
75
- const tokenWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
76
-
77
- const resultWrapper = tokenWrapper . find ( QueryRenderer ) . renderProp ( 'render' ) ( {
58
+ const resultWrapper = wrapper . find ( QueryRenderer ) . renderProp ( 'render' ) ( {
78
59
error : null ,
79
60
props : null ,
80
61
retry : ( ) => { } ,
@@ -83,68 +64,18 @@ describe('RemoteContainer', function() {
83
64
assert . isTrue ( resultWrapper . exists ( 'LoadingView' ) ) ;
84
65
} ) ;
85
66
86
- it ( 'renders a login prompt if no token is found' , function ( ) {
87
- const wrapper = shallow ( buildApp ( ) ) ;
88
- const tokenWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( UNAUTHENTICATED ) ;
89
- assert . isTrue ( tokenWrapper . exists ( 'GithubLoginView' ) ) ;
90
- } ) ;
91
-
92
- it ( 'renders a login prompt if the token has insufficient OAuth scopes' , function ( ) {
93
- const wrapper = shallow ( buildApp ( ) ) ;
94
- const tokenWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( INSUFFICIENT ) ;
95
-
96
- assert . match ( tokenWrapper . find ( 'GithubLoginView' ) . find ( 'p' ) . text ( ) , / s u f f i c i e n t / ) ;
97
- } ) ;
98
-
99
- it ( 'renders an offline view if the user is offline' , function ( ) {
100
- sinon . spy ( model , 'didUpdate' ) ;
101
-
102
- const wrapper = shallow ( buildApp ( ) ) ;
103
- const e = new Error ( 'oh no' ) ;
104
- const tokenWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( e ) ;
105
- assert . isTrue ( tokenWrapper . exists ( 'QueryErrorView' ) ) ;
106
-
107
- tokenWrapper . find ( 'QueryErrorView' ) . prop ( 'retry' ) ( ) ;
108
- assert . isTrue ( model . didUpdate . called ) ;
109
- } ) ;
110
-
111
67
it ( 'renders an error message if the GraphQL query fails' , function ( ) {
112
68
const wrapper = shallow ( buildApp ( ) ) ;
113
- const tokenWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
114
69
115
70
const error = new Error ( 'oh shit!' ) ;
116
71
error . rawStack = error . stack ;
117
- const resultWrapper = tokenWrapper . find ( QueryRenderer ) . renderProp ( 'render' ) ( { error, props : null , retry : ( ) => { } } ) ;
72
+ const resultWrapper = wrapper . find ( QueryRenderer ) . renderProp ( 'render' ) ( { error, props : null , retry : ( ) => { } } ) ;
118
73
119
74
assert . strictEqual ( resultWrapper . find ( 'QueryErrorView' ) . prop ( 'error' ) , error ) ;
120
75
} ) ;
121
76
122
- it ( 'increments a counter on login' , function ( ) {
123
- const incrementCounterStub = sinon . stub ( reporterProxy , 'incrementCounter' ) ;
124
-
125
- const wrapper = shallow ( buildApp ( ) ) ;
126
- const tokenWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( UNAUTHENTICATED ) ;
127
-
128
- tokenWrapper . find ( 'GithubLoginView' ) . prop ( 'onLogin' ) ( ) ;
129
- assert . isTrue ( incrementCounterStub . calledOnceWith ( 'github-login' ) ) ;
130
- } ) ;
131
-
132
- it ( 'increments a counter on logout' , function ( ) {
133
- const wrapper = shallow ( buildApp ( ) ) ;
134
- const tokenWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
135
-
136
- const error = new Error ( 'just show the logout button' ) ;
137
- error . rawStack = error . stack ;
138
- const resultWrapper = tokenWrapper . find ( QueryRenderer ) . renderProp ( 'render' ) ( { error, props : null , retry : ( ) => { } } ) ;
139
-
140
- const incrementCounterStub = sinon . stub ( reporterProxy , 'incrementCounter' ) ;
141
- resultWrapper . find ( 'QueryErrorView' ) . prop ( 'logout' ) ( ) ;
142
- assert . isTrue ( incrementCounterStub . calledOnceWith ( 'github-logout' ) ) ;
143
- } ) ;
144
-
145
77
it ( 'renders the controller once results have arrived' , function ( ) {
146
78
const wrapper = shallow ( buildApp ( ) ) ;
147
- const tokenWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
148
79
149
80
const props = queryBuilder ( remoteQuery )
150
81
. repository ( r => {
@@ -155,10 +86,9 @@ describe('RemoteContainer', function() {
155
86
} ) ;
156
87
} )
157
88
. build ( ) ;
158
- const resultWrapper = tokenWrapper . find ( QueryRenderer ) . renderProp ( 'render' ) ( { error : null , props, retry : ( ) => { } } ) ;
89
+ const resultWrapper = wrapper . find ( QueryRenderer ) . renderProp ( 'render' ) ( { error : null , props, retry : ( ) => { } } ) ;
159
90
160
91
const controller = resultWrapper . find ( 'RemoteController' ) ;
161
- assert . strictEqual ( controller . prop ( 'token' ) , '1234' ) ;
162
92
assert . deepEqual ( controller . prop ( 'repository' ) , {
163
93
id : 'the-repo' ,
164
94
defaultBranchRef : {
0 commit comments