Skip to content

Commit 6bf425e

Browse files
committed
Update specs for new about modal and saved demos
1 parent 8f74d19 commit 6bf425e

File tree

1 file changed

+49
-17
lines changed

1 file changed

+49
-17
lines changed

tests/index.js

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var Application = require('spectron').Application
22
var chai = require('chai')
33
var chaiAsPromised = require('chai-as-promised')
44
var path = require('path')
5+
var fs = require('fs')
56

67
chai.should()
78
chai.use(chaiAsPromised)
@@ -14,46 +15,74 @@ var it = global.it
1415
describe('demo app', function () {
1516
this.timeout(30000)
1617

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({
1936
path: path.join(__dirname, '..', 'node_modules', '.bin', 'electron'),
2037
args: [
2138
path.join(__dirname, '..')
2239
],
2340
waitTimeout: 10000
2441
})
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+
}
2755

2856
before(function () {
29-
chaiAsPromised.transferPromiseness = this.app.client.transferPromiseness
57+
removeStoredPreferences()
58+
return startApp()
3059
})
3160

3261
after(function () {
33-
if (this.app && this.app.isRunning()) {
34-
return this.app.stop()
62+
if (app && app.isRunning()) {
63+
return app.stop()
3564
}
3665
})
3766

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)
4169
.isWindowMinimized().should.eventually.be.false
4270
.isWindowDevToolsOpened().should.eventually.be.false
4371
.isWindowVisible().should.eventually.be.true
4472
.isWindowFocused().should.eventually.be.true
4573
.getWindowWidth().should.eventually.be.above(0)
4674
.getWindowHeight().should.eventually.be.above(0)
4775
.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
5181
})
5282

5383
describe('when clicking on a section from the nav bar', function () {
5484
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
5786
.click('button[data-section="windows"]').pause(100)
5887
.waitForVisible('#windows-section')
5988
.isExisting('button.is-selected[data-section="windows"]').should.eventually.be.true
@@ -71,12 +100,15 @@ describe('demo app', function () {
71100
var onlyFirstVisible = Array(21).fill(false)
72101
onlyFirstVisible[0] = true
73102

74-
return this.app.client.waitUntilWindowLoaded()
75-
.click('button[data-section="windows"]')
103+
return app.client.click('button[data-section="windows"]')
76104
.waitForVisible('#windows-section')
77105
.click('.js-container-target')
78106
.waitForVisible('.toggle-content')
79107
.isVisible('.toggle-content').should.eventually.deep.equal(onlyFirstVisible)
108+
.then(restartApp)
109+
.then(function () {
110+
return app.client.waitForVisible('#windows-section')
111+
})
80112
})
81113
})
82114
})

0 commit comments

Comments
 (0)