Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit c3dee08

Browse files
authored
Merge pull request #81 from skellock/up-coverage
Adds full coverage.
2 parents bd49f18 + 0293849 commit c3dee08

File tree

15 files changed

+243
-12
lines changed

15 files changed

+243
-12
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { test } from 'ava'
2+
import { stub } from 'sinon'
3+
import { loadURL } from './load-url'
4+
5+
test('loads from storybook', t => {
6+
const loadStub = stub()
7+
loadURL({ loadURL: loadStub } as any, 'a', true)
8+
t.true(loadStub.calledWith('http://localhost:6006'))
9+
})
10+
11+
test('loads from electron', t => {
12+
const loadStub = stub()
13+
loadURL({ loadURL: loadStub } as any, 'a', false)
14+
15+
t.true(loadStub.calledWith('file:///a/out/index.html'))
16+
})

src/main/main-window/main-window.test.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,31 @@ import { stub } from 'sinon'
44
import { electron, BrowserWindow } from '../test/mock-electron'
55
import { WindowStateManager } from '../test/mock-window-state-manager'
66

7-
test.beforeEach(() => mockery.enable({ warnOnUnregistered: false }))
8-
test.afterEach(() => {
7+
test.beforeEach(() => {
8+
mockery.enable({ warnOnUnregistered: false })
9+
})
10+
test.afterEach.always(() => {
911
mockery.deregisterAll()
1012
mockery.disable()
1113
})
1214

15+
test('mocks have coverage :(', t => {
16+
const win = new WindowStateManager()
17+
t.is(win.x, 1)
18+
t.is(win.y, 2)
19+
t.is(win.width, 3)
20+
t.is(win.height, 4)
21+
t.is(win.maximized, true)
22+
t.is(win.saveState({}), undefined)
23+
24+
const bw = new BrowserWindow()
25+
t.is(bw.getSize(), undefined)
26+
t.is(bw.loadURL(), undefined)
27+
t.is(bw.maximize(), undefined)
28+
t.is(bw.show(), undefined)
29+
t.is(bw.focus(), undefined)
30+
})
31+
1332
test('reads from window state', t => {
1433
// two step process for the getters :(
1534
const width = stub()
@@ -41,10 +60,26 @@ test('maximizes if told by the window state manager', t => {
4160

4261
mockery.registerMock('electron-window-state-manager', WindowStateManager)
4362
mockery.registerMock('electron', electron)
63+
const maximize = stub(BrowserWindow.prototype, 'maximize')
64+
require('./main-window').createMainWindow(__dirname)
65+
maximize.restore()
66+
67+
t.true(maximized.calledOnce)
68+
t.true(maximize.calledOnce)
69+
})
70+
71+
test('does not maximize unless told by the window state manager', t => {
72+
const maximized = stub().returns(false)
73+
stub(WindowStateManager.prototype, 'maximized').get(maximized)
4474

75+
mockery.registerMock('electron-window-state-manager', WindowStateManager)
76+
mockery.registerMock('electron', electron)
77+
const maximize = stub(BrowserWindow.prototype, 'maximize')
4578
require('./main-window').createMainWindow(__dirname)
79+
maximize.restore()
4680

4781
t.true(maximized.calledOnce)
82+
t.true(maximize.notCalled)
4883
})
4984

5085
test('saves window state', t => {
@@ -60,3 +95,20 @@ test('saves window state', t => {
6095

6196
t.is(saveState.callCount, 3)
6297
})
98+
99+
test.cb('show the window after we finish loading + delay', t => {
100+
mockery.registerMock('electron-window-state-manager', WindowStateManager)
101+
mockery.registerMock('electron', electron)
102+
103+
const window: BrowserWindow = require('./main-window').createMainWindow(__dirname, 1)
104+
const showStub = stub(window, 'show')
105+
const focusStub = stub(window, 'focus')
106+
107+
window.webContents.emit('did-finish-load')
108+
109+
setTimeout(() => {
110+
t.true(showStub.calledOnce)
111+
t.true(focusStub.calledOnce)
112+
t.end()
113+
}, 2)
114+
})

src/main/main-window/main-window.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ const DIMENSIONS = { width: 600, height: 500, minWidth: 450, minHeight: 450 }
99
* Creates the main window.
1010
*
1111
* @param appPath The path to the bundle root.
12+
* @param showDelay How long in ms before showing the window after the renderer is ready.
1213
* @return The main BrowserWindow.
1314
*/
14-
export function createMainWindow(appPath: string) {
15+
export function createMainWindow(appPath: string, showDelay: number = 100) {
1516
// persistent window state manager
1617
const windowState = new WindowStateManager('main', {
1718
defaultWidth: DIMENSIONS.width,
@@ -58,7 +59,7 @@ export function createMainWindow(appPath: string) {
5859
setTimeout(() => {
5960
window.show()
6061
window.focus()
61-
}, 100)
62+
}, showDelay)
6263
})
6364

6465
return window

src/main/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ app.on('ready', () => {
3131
})
3232

3333
ipcMain.on('storybook-toggle', () => {
34-
log.info('toggle')
3534
showStorybook = !showStorybook
3635
loadURL(window, appPath, showStorybook)
3736
})

src/main/menu/shared-menu.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as log from 'electron-log'
21
import { shell, ipcMain } from 'electron'
32

43
export function createSharedMenuItems(window: Electron.BrowserWindow) {
@@ -19,7 +18,6 @@ export function createSharedMenuItems(window: Electron.BrowserWindow) {
1918
const storybook: Electron.MenuItemConstructorOptions = {
2019
label: 'Toggle Storybook',
2120
click() {
22-
log.info('gonna send')
2321
ipcMain.emit('storybook-toggle')
2422
},
2523
}

src/main/test/mock-electron.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export class BrowserWindow extends EventEmitter {
1111
getSize() {}
1212
loadURL() {}
1313
maximize() {}
14+
show() {}
15+
focus() {}
1416
}
1517

1618
/**
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react'
2+
import { test } from 'ava'
3+
import { create } from 'react-test-renderer'
4+
import { CenteredContent } from './centered-content'
5+
6+
test('has children', t => {
7+
const c = (
8+
<CenteredContent>
9+
<p>hi</p>
10+
</CenteredContent>
11+
)
12+
t.snapshot(create(c).toJSON())
13+
})
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as React from 'react'
2+
import { test } from 'ava'
3+
import { create } from 'react-test-renderer'
4+
import { EnterAnimation } from './enter-animation'
5+
6+
test('grow', t => {
7+
const c = (
8+
<EnterAnimation animation='grow'>
9+
<p>hi</p>
10+
</EnterAnimation>
11+
)
12+
t.snapshot(create(c).toJSON())
13+
})
14+
15+
test('slide', t => {
16+
const c = (
17+
<EnterAnimation animation='slide'>
18+
<p>hi</p>
19+
</EnterAnimation>
20+
)
21+
t.snapshot(create(c).toJSON())
22+
})

src/renderer/platform/components/enter-animation/enter-animation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class EnterAnimation extends React.PureComponent<EnterAnimationProps, Ent
5151
break
5252
}
5353

54-
const transition = `transform ${speed || DEFAULT_SPEED}ms ${delay || DEFAULT_DELAY}ms`
54+
const transition = `transform ${speed}ms ${delay}ms`
5555

5656
// style props
5757
const starting = css(cssProps({ transform, transition }))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react'
2+
import { test } from 'ava'
3+
import { create } from 'react-test-renderer'
4+
import { ScrollableContent } from './scrollable-content'
5+
6+
test('has children', t => {
7+
const c = (
8+
<ScrollableContent>
9+
<p>hi</p>
10+
</ScrollableContent>
11+
)
12+
t.snapshot(create(c).toJSON())
13+
})

0 commit comments

Comments
 (0)