-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMockDownloadItem.ts
56 lines (51 loc) · 1.71 KB
/
MockDownloadItem.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
import { DownloadItem } from 'electron'
import * as sinon from 'sinon'
import { EventEmitter } from 'events'
// https://www.electronjs.org/docs/latest/api/download-item
export class MockDownloadItem extends EventEmitter implements DownloadItem {
_filename: string
_URL: string
savePath = ''
_receivedBytes = 0
_totalBytes = 1000
_state: 'completed' | 'cancelled' | 'interrupted' | 'progressing' =
'completed'
_canResume = true
_isPaused = false
cancel = sinon.spy()
canResume = sinon.spy()
getContentDisposition = sinon.spy(() => '')
getETag = sinon.spy(() => '')
getFilename = sinon.spy(() => this._filename)
getLastModifiedTime = sinon.spy(() => '')
getMimeType = sinon.spy(() => '')
getReceivedBytes = sinon.spy(() => this._receivedBytes)
getSavePath = sinon.spy(() => this.savePath)
getStartTime = sinon.spy(() => Date.now())
getState = sinon.spy(() => this._state)
getTotalBytes = sinon.spy(() => this._totalBytes)
getURL = sinon.spy(() => this._URL)
getURLChain = sinon.spy(() => [this._URL])
hasUserGesture = sinon.spy(() => false)
isPaused = sinon.spy(() => this._isPaused)
pause = sinon.spy(() => {
this._isPaused = true
})
resume = sinon.spy(() => {
this._isPaused = false
})
setSaveDialogOptions = sinon.spy()
getSaveDialogOptions = sinon.spy(() => ({}))
setSavePath = sinon.spy((path: string) => {
this.savePath = path
})
// for Electron 32 update
getCurrentBytesPerSecond = sinon.spy(() => 100)
getEndTime = sinon.spy(() => Date.now() + 5000)
getPercentComplete = sinon.spy(() => this._receivedBytes / this._totalBytes)
constructor(url: string) {
super()
this._URL = url
this._filename = url.split('?')[0].split('/').pop() || ''
}
}