1
1
require (" ../../spec_helper" )
2
2
3
3
_ = require (" lodash" )
4
+ path = require (" path" )
4
5
Promise = require (" bluebird" )
5
6
EE = require (" events" ).EventEmitter
6
7
BrowserWindow = require (" electron" ).BrowserWindow
8
+ cyDesktop = require (" @packages/desktop-gui" )
9
+ user = require (" #{ root} ../lib/user" )
7
10
Windows = require (" #{ root} ../lib/gui/windows" )
8
11
savedState = require (" #{ root} ../lib/saved_state" )
9
12
10
13
describe " lib/gui/windows" , ->
11
14
beforeEach ->
15
+ Windows .reset ()
16
+
12
17
@win = new EE ()
18
+ @win .loadURL = @sandbox .stub ()
19
+ @win .destroy = @sandbox .stub ()
13
20
@win .getSize = @sandbox .stub ().returns ([1 , 2 ])
14
21
@win .getPosition = @sandbox .stub ().returns ([3 , 4 ])
15
22
@win .webContents = new EE ()
@@ -18,6 +25,9 @@ describe "lib/gui/windows", ->
18
25
19
26
@sandbox .stub (Windows, " _newBrowserWindow" ).returns (@win )
20
27
28
+ afterEach ->
29
+ Windows .reset ()
30
+
21
31
context " .getBrowserAutomation" , ->
22
32
beforeEach ->
23
33
@sandbox .stub (Windows, " automation" )
@@ -37,6 +47,66 @@ describe "lib/gui/windows", ->
37
47
BrowserWindow .fromWebContents .withArgs (" foo" ).returns (" bar" )
38
48
expect (Windows .getByWebContents (" foo" )).to .eq (" bar" )
39
49
50
+ context " .open" , ->
51
+ beforeEach ->
52
+ @sandbox .stub (Windows, " create" ).returns (@win )
53
+
54
+ it " sets default options" , ->
55
+ options = {
56
+ type : " INDEX"
57
+ }
58
+
59
+ Windows .open (" /path/to/project" , options)
60
+ .then (win) ->
61
+ expect (options).to .deep .eq ({
62
+ height : 500
63
+ width : 600
64
+ type : " INDEX"
65
+ show : true
66
+ url : cyDesktop .getPathToIndex ()
67
+ webPreferences : {
68
+ preload : path .resolve (" lib" , " ipc" , " ipc.js" )
69
+ }
70
+ })
71
+
72
+ expect (win .loadURL ).to .be .calledWith (cyDesktop .getPathToIndex ())
73
+
74
+ it " resolves with code on GITHUB_LOGIN for will-navigate" , ->
75
+ options = {
76
+ type : " GITHUB_LOGIN"
77
+ }
78
+
79
+ url = " https://github.com/login"
80
+ url2 = " https://github.com?code=code123"
81
+
82
+ @sandbox .stub (user, " getLoginUrl" ).resolves (url)
83
+
84
+ @sandbox .stub (@win .webContents , " on" ).withArgs (" will-navigate" ).yieldsAsync ({}, url2)
85
+
86
+ Windows .open (" /path/to/project" , options)
87
+ .then (code) =>
88
+ expect (code).to .eq (" code123" )
89
+ expect (options .type ).eq (" GITHUB_LOGIN" )
90
+ expect (@win .loadURL ).to .be .calledWith (url)
91
+
92
+ it " resolves with code on GITHUB_LOGIN for did-get-redirect-request" , ->
93
+ options = {
94
+ type : " GITHUB_LOGIN"
95
+ }
96
+
97
+ url = " https://github.com/login"
98
+ url2 = " https://github.com?code=code123"
99
+
100
+ @sandbox .stub (user, " getLoginUrl" ).resolves (url)
101
+
102
+ @sandbox .stub (@win .webContents , " on" ).withArgs (" did-get-redirect-request" ).yieldsAsync ({}, " foo" , url2)
103
+
104
+ Windows .open (" /path/to/project" , options)
105
+ .then (code) =>
106
+ expect (code).to .eq (" code123" )
107
+ expect (options .type ).eq (" GITHUB_LOGIN" )
108
+ expect (@win .loadURL ).to .be .calledWith (url)
109
+
40
110
context " .create" , ->
41
111
it " opens dev tools if saved state is open" , ->
42
112
Windows .create (" /foo/" , {devTools : true })
0 commit comments