-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from spaceagetv/feat/download+updater
Feat: DownloadItem + AutoUpdater
- Loading branch information
Showing
15 changed files
with
2,997 additions
and
1,474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { AutoUpdater } from 'electron' | ||
import * as sinon from 'sinon' | ||
import { EventEmitter } from 'events' | ||
|
||
export class MockAutoUpdater extends EventEmitter implements AutoUpdater { | ||
_feedURL: string | ||
_headers: Record<string, string> | ||
_serverType: string | ||
|
||
checkForUpdates = sinon.spy() | ||
quitAndInstall = sinon.spy() | ||
|
||
setFeedURL = sinon.spy(({ url, headers, serverType }) => { | ||
this._feedURL = url | ||
this._headers = headers | ||
this._serverType = serverType | ||
}) | ||
|
||
getFeedURL() { | ||
return this._feedURL | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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 | ||
}) | ||
|
||
constructor(url: string) { | ||
super() | ||
this._URL = url | ||
this._filename = url.split('?')[0].split('/').pop() || '' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
export * from './MockAutoUpdater' | ||
export * from './MockBrowserWindow' | ||
export * from './MockDialog' | ||
export * from './MockDisplay' | ||
export * from './MockDownloadItem' | ||
export * from './MockIpcMain' | ||
export * from './MockIpcRenderer' | ||
export * from './MockWebContents' | ||
export * from './MockScreen' | ||
export * from './MockDisplay' | ||
export * from './MockDialog' | ||
export * from './MockWebContents' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { MockAutoUpdater } from '../src' | ||
import chai, { expect } from 'chai' | ||
import sinonChai from 'sinon-chai' | ||
|
||
chai.use(sinonChai) | ||
|
||
describe('MockAutoUpdater', () => { | ||
it('should be defined', () => { | ||
expect(MockAutoUpdater).to.be.not.undefined | ||
}) | ||
|
||
it('should be a class', () => { | ||
expect(typeof MockAutoUpdater).to.equal('function') | ||
}) | ||
|
||
it('should instantiate', () => { | ||
const mockAutoUpdater = new MockAutoUpdater() | ||
expect(mockAutoUpdater).to.be.not.undefined | ||
}) | ||
|
||
it('should be able to setUrl()', () => { | ||
const mockAutoUpdater = new MockAutoUpdater() as Electron.AutoUpdater | ||
mockAutoUpdater.setFeedURL({ | ||
url: 'https://example.com', | ||
headers: { | ||
'User-Agent': 'MockAutoUpdater', | ||
}, | ||
serverType: 'json', | ||
}) | ||
expect(mockAutoUpdater.getFeedURL()).to.equal('https://example.com') | ||
}) | ||
|
||
it('should be able to call checkForUpdates()', () => { | ||
const mockAutoUpdater = new MockAutoUpdater() as Electron.AutoUpdater | ||
mockAutoUpdater.checkForUpdates() | ||
expect(mockAutoUpdater.checkForUpdates).to.have.been.calledOnce | ||
}) | ||
|
||
it('should be able to call quitAndInstall()', () => { | ||
const mockAutoUpdater = new MockAutoUpdater() as Electron.AutoUpdater | ||
mockAutoUpdater.quitAndInstall() | ||
expect(mockAutoUpdater.quitAndInstall).to.have.been.calledOnce | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { MockDownloadItem } from '../src' | ||
import chai, { expect } from 'chai' | ||
import sinonChai from 'sinon-chai' | ||
|
||
chai.use(sinonChai) | ||
|
||
describe('MockDownloadItem', () => { | ||
it('should create an instance', () => { | ||
const mockDownloadItem = new MockDownloadItem( | ||
'https://example.com', | ||
) as Electron.DownloadItem | ||
expect(mockDownloadItem).to.be.not.undefined | ||
}) | ||
|
||
it('should be able to get the URL', () => { | ||
const mockDownloadItem = new MockDownloadItem( | ||
'https://example.com', | ||
) as Electron.DownloadItem | ||
expect(mockDownloadItem.getURL()).to.equal('https://example.com') | ||
}) | ||
|
||
it('should be able to get the filename', () => { | ||
const mockDownloadItem = new MockDownloadItem( | ||
'https://example.com/example.txt?foo=bar&baz=qux', | ||
) as Electron.DownloadItem | ||
expect(mockDownloadItem.getFilename()).to.equal('example.txt') | ||
}) | ||
|
||
it('should be able to set/get the save path', () => { | ||
const mockDownloadItem = new MockDownloadItem( | ||
'https://example.com', | ||
) as Electron.DownloadItem | ||
mockDownloadItem.setSavePath('/tmp/example.txt') | ||
expect(mockDownloadItem.getSavePath()).to.equal('/tmp/example.txt') | ||
}) | ||
}) |
Oops, something went wrong.