@@ -2,6 +2,7 @@ var Application = require('spectron').Application
2
2
var chai = require ( 'chai' )
3
3
var chaiAsPromised = require ( 'chai-as-promised' )
4
4
var path = require ( 'path' )
5
+ var fs = require ( 'fs' )
5
6
6
7
chai . should ( )
7
8
chai . use ( chaiAsPromised )
@@ -14,46 +15,74 @@ var it = global.it
14
15
describe ( 'demo app' , function ( ) {
15
16
this . timeout ( 30000 )
16
17
17
- before ( function ( ) {
18
- this . app = new Application ( {
18
+ var app
19
+
20
+ var removeStoredPreferences = function ( ) {
21
+ var userDataPath = path . join ( process . env . HOME , 'Library' , 'Application Support' , 'electron-api-demos' )
22
+ try {
23
+ fs . unlinkSync ( path . join ( userDataPath , 'activeDemoButtonId.json' ) )
24
+ } catch ( error ) {
25
+ if ( error . code !== 'ENOENT' ) throw error
26
+ }
27
+ try {
28
+ fs . unlinkSync ( path . join ( userDataPath , 'activeSectionButtonId.json' ) )
29
+ } catch ( error ) {
30
+ if ( error . code !== 'ENOENT' ) throw error
31
+ }
32
+ }
33
+
34
+ var startApp = function ( ) {
35
+ app = new Application ( {
19
36
path : path . join ( __dirname , '..' , 'node_modules' , '.bin' , 'electron' ) ,
20
37
args : [
21
38
path . join ( __dirname , '..' )
22
39
] ,
23
40
waitTimeout : 10000
24
41
} )
25
- return this . app . start ( )
26
- } )
42
+
43
+ return app . start ( ) . then ( function ( ) {
44
+ chaiAsPromised . transferPromiseness = app . client . transferPromiseness
45
+ } ) . then ( function ( ) {
46
+ return app . client . waitUntilWindowLoaded ( )
47
+ } )
48
+ }
49
+
50
+ var restartApp = function ( ) {
51
+ return app . stop ( ) . then ( function ( ) {
52
+ return startApp ( )
53
+ } )
54
+ }
27
55
28
56
before ( function ( ) {
29
- chaiAsPromised . transferPromiseness = this . app . client . transferPromiseness
57
+ removeStoredPreferences ( )
58
+ return startApp ( )
30
59
} )
31
60
32
61
after ( function ( ) {
33
- if ( this . app && this . app . isRunning ( ) ) {
34
- return this . app . stop ( )
62
+ if ( app && app . isRunning ( ) ) {
63
+ return app . stop ( )
35
64
}
36
65
} )
37
66
38
- it ( 'opens a window displaying the about page and nav bar' , function ( ) {
39
- return this . app . client . waitUntilWindowLoaded ( )
40
- . getWindowCount ( ) . should . eventually . equal ( 1 )
67
+ it ( 'opens a window displaying the about page' , function ( ) {
68
+ return app . client . getWindowCount ( ) . should . eventually . equal ( 1 )
41
69
. isWindowMinimized ( ) . should . eventually . be . false
42
70
. isWindowDevToolsOpened ( ) . should . eventually . be . false
43
71
. isWindowVisible ( ) . should . eventually . be . true
44
72
. isWindowFocused ( ) . should . eventually . be . true
45
73
. getWindowWidth ( ) . should . eventually . be . above ( 0 )
46
74
. getWindowHeight ( ) . should . eventually . be . above ( 0 )
47
75
. getTitle ( ) . should . eventually . equal ( 'Electron API Demos' )
48
- . isVisible ( '#about-section' ) . should . eventually . be . true
49
- . isVisible ( '#section-nav' ) . should . eventually . be . true
50
- . click ( 'button[id="get-started"]' ) . pause ( 100 )
76
+ . waitForVisible ( '#about-modal' ) . should . eventually . be . true
77
+ . isVisible ( '.section-nav' ) . should . eventually . be . false
78
+ . click ( 'button[id="get-started"]' ) . pause ( 500 )
79
+ . isVisible ( '#about-modal' ) . should . eventually . be . false
80
+ . isVisible ( '.section-nav' ) . should . eventually . be . true
51
81
} )
52
82
53
83
describe ( 'when clicking on a section from the nav bar' , function ( ) {
54
84
it ( 'shows the selected section in the main area' , function ( ) {
55
- return this . app . client . waitUntilWindowLoaded ( )
56
- . isVisible ( '#windows-section' ) . should . eventually . be . true
85
+ return app . client . isVisible ( '#windows-section' ) . should . eventually . be . true
57
86
. click ( 'button[data-section="windows"]' ) . pause ( 100 )
58
87
. waitForVisible ( '#windows-section' )
59
88
. isExisting ( 'button.is-selected[data-section="windows"]' ) . should . eventually . be . true
@@ -71,12 +100,15 @@ describe('demo app', function () {
71
100
var onlyFirstVisible = Array ( 21 ) . fill ( false )
72
101
onlyFirstVisible [ 0 ] = true
73
102
74
- return this . app . client . waitUntilWindowLoaded ( )
75
- . click ( 'button[data-section="windows"]' )
103
+ return app . client . click ( 'button[data-section="windows"]' )
76
104
. waitForVisible ( '#windows-section' )
77
105
. click ( '.js-container-target' )
78
106
. waitForVisible ( '.toggle-content' )
79
107
. isVisible ( '.toggle-content' ) . should . eventually . deep . equal ( onlyFirstVisible )
108
+ . then ( restartApp )
109
+ . then ( function ( ) {
110
+ return app . client . waitForVisible ( '#windows-section' )
111
+ } )
80
112
} )
81
113
} )
82
114
} )
0 commit comments