forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-dialog-spec.ts
155 lines (126 loc) · 5.01 KB
/
api-dialog-spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { expect } from 'chai'
import { dialog, BrowserWindow } from 'electron'
import { closeAllWindows } from './window-helpers'
import { ifit } from './spec-helpers'
describe('dialog module', () => {
describe('showOpenDialog', () => {
afterEach(closeAllWindows)
ifit(process.platform !== 'win32')('should not throw for valid cases', () => {
expect(() => {
dialog.showOpenDialog({ title: 'i am title' })
}).to.not.throw()
expect(() => {
const w = new BrowserWindow()
dialog.showOpenDialog(w, { title: 'i am title' })
}).to.not.throw()
})
it('throws errors when the options are invalid', () => {
expect(() => {
dialog.showOpenDialog({ properties: false as any })
}).to.throw(/Properties must be an array/)
expect(() => {
dialog.showOpenDialog({ title: 300 as any })
}).to.throw(/Title must be a string/)
expect(() => {
dialog.showOpenDialog({ buttonLabel: [] as any })
}).to.throw(/Button label must be a string/)
expect(() => {
dialog.showOpenDialog({ defaultPath: {} as any })
}).to.throw(/Default path must be a string/)
expect(() => {
dialog.showOpenDialog({ message: {} as any })
}).to.throw(/Message must be a string/)
})
})
describe('showSaveDialog', () => {
afterEach(closeAllWindows)
ifit(process.platform !== 'win32')('should not throw for valid cases', () => {
expect(() => {
dialog.showSaveDialog({ title: 'i am title' })
}).to.not.throw()
expect(() => {
const w = new BrowserWindow()
dialog.showSaveDialog(w, { title: 'i am title' })
}).to.not.throw()
})
it('throws errors when the options are invalid', () => {
expect(() => {
dialog.showSaveDialog({ title: 300 as any })
}).to.throw(/Title must be a string/)
expect(() => {
dialog.showSaveDialog({ buttonLabel: [] as any })
}).to.throw(/Button label must be a string/)
expect(() => {
dialog.showSaveDialog({ defaultPath: {} as any })
}).to.throw(/Default path must be a string/)
expect(() => {
dialog.showSaveDialog({ message: {} as any })
}).to.throw(/Message must be a string/)
expect(() => {
dialog.showSaveDialog({ nameFieldLabel: {} as any })
}).to.throw(/Name field label must be a string/)
})
})
describe('showMessageBox', () => {
afterEach(closeAllWindows);
// parentless message boxes are synchronous on macOS
// dangling message boxes on windows cause a DCHECK: https://cs.chromium.org/chromium/src/base/win/message_window.cc?l=68&rcl=7faa4bf236a866d007dc5672c9ce42660e67a6a6
ifit(process.platform !== 'darwin' && process.platform !== 'win32')('should not throw for a parentless message box', () => {
expect(() => {
dialog.showMessageBox({ message: 'i am message' })
}).to.not.throw()
})
ifit(process.platform !== 'win32')('should not throw for valid cases', () => {
expect(() => {
const w = new BrowserWindow()
dialog.showMessageBox(w, { message: 'i am message' })
}).to.not.throw()
})
it('throws errors when the options are invalid', () => {
expect(() => {
dialog.showMessageBox(undefined as any, { type: 'not-a-valid-type', message: '' })
}).to.throw(/Invalid message box type/)
expect(() => {
dialog.showMessageBox(null as any, { buttons: false as any, message: '' })
}).to.throw(/Buttons must be an array/)
expect(() => {
dialog.showMessageBox({ title: 300 as any, message: '' })
}).to.throw(/Title must be a string/)
expect(() => {
dialog.showMessageBox({ message: [] as any })
}).to.throw(/Message must be a string/)
expect(() => {
dialog.showMessageBox({ detail: 3.14 as any, message: '' })
}).to.throw(/Detail must be a string/)
expect(() => {
dialog.showMessageBox({ checkboxLabel: false as any, message: '' })
}).to.throw(/checkboxLabel must be a string/)
})
})
describe('showErrorBox', () => {
it('throws errors when the options are invalid', () => {
expect(() => {
(dialog.showErrorBox as any)()
}).to.throw(/Insufficient number of arguments/)
expect(() => {
dialog.showErrorBox(3 as any, 'four')
}).to.throw(/Error processing argument at index 0/)
expect(() => {
dialog.showErrorBox('three', 4 as any)
}).to.throw(/Error processing argument at index 1/)
})
})
describe('showCertificateTrustDialog', () => {
it('throws errors when the options are invalid', () => {
expect(() => {
(dialog.showCertificateTrustDialog as any)()
}).to.throw(/options must be an object/)
expect(() => {
dialog.showCertificateTrustDialog({} as any)
}).to.throw(/certificate must be an object/)
expect(() => {
dialog.showCertificateTrustDialog({ certificate: {} as any, message: false as any })
}).to.throw(/message must be a string/)
})
})
})