Skip to content

Commit

Permalink
Merge pull request #13 from spaceagetv/feat/mock-app
Browse files Browse the repository at this point in the history
feat: MockApp
  • Loading branch information
jjeff authored Dec 8, 2024
2 parents b933b55 + 8449d6b commit b059356
Show file tree
Hide file tree
Showing 4 changed files with 527 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ It's still very rough, so please help contribute to help make this functionality

Currently implemented:

- [MockApp](src/MockApp.ts)
- [MockBrowserWindow](src/MockBrowserWindow.ts)
- [MockWebContents](src/MockWebContents.ts)
- [MockView](src/MockView.ts)
Expand All @@ -31,6 +32,7 @@ Currently implemented:
- [MockDisplay](src/MockDisplay.ts)
- [MockAutoUpdater](src/MockAutoUpdater.ts)
- [MockDownloadItem](src/MockDownloadItem.ts)
- [MockView](src/MockView.ts)

All methods are implemented and should return logical values. Additionally, methods are wrapped in [sinon.spy()]([url](https://sinonjs.org/releases/latest/spies/)) so calls can be queried. All logical events should be emitted.

Expand Down
141 changes: 141 additions & 0 deletions src/MockApp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { EventEmitter } from 'events'
import sinon from 'sinon'

export class MockApp extends EventEmitter implements Electron.App {
quit = sinon.spy()
exit = sinon.spy()
relaunch = sinon.spy()
isReady = sinon.spy(() => true)
whenReady = sinon.spy(() => Promise.resolve())
focus = sinon.spy()
hide = sinon.spy()
isHidden = sinon.spy(() => false)
show = sinon.spy()
setAppLogsPath = sinon.spy()
getAppPath = sinon.spy(() => '/path/to/app')
getPath = sinon.spy((name: string) => `/path/to/${name}`)
// @todo: create a NativeImage mock and return it here
getFileIcon = sinon.spy(() => Promise.resolve(null))
setPath = sinon.spy()
getVersion = sinon.spy(() => '1.0.0')
getName = sinon.spy(() => 'MockApp')
setName = sinon.spy()
getLocale = sinon.spy(() => 'en-US')
getLocaleCountryCode = sinon.spy(() => 'US')
getSystemLocale = sinon.spy(() => 'en-US')
getPreferredSystemLanguages = sinon.spy(() => ['en-US'])
addRecentDocument = sinon.spy()
clearRecentDocuments = sinon.spy()
setAsDefaultProtocolClient = sinon.spy()
removeAsDefaultProtocolClient = sinon.spy()
isDefaultProtocolClient = sinon.spy(
() => true,
) as Electron.App['isDefaultProtocolClient'] & sinon.SinonSpy
getApplicationNameForProtocol = sinon.spy(
() => 'MockApp',
) as Electron.App['getApplicationNameForProtocol'] & sinon.SinonSpy
getApplicationInfoForProtocol = sinon.spy(() =>
Promise.resolve({
name: 'MockApp',
path: '/path/to/app',
icon: null,
}),
) as Electron.App['getApplicationInfoForProtocol'] & sinon.SinonSpy
setUserTasks = sinon.spy()
getJumpListSettings = sinon.spy(() => ({
minItems: 0,
removedItems: [],
}))
setJumpList = sinon.spy()
requestSingleInstanceLock = sinon.spy(() => true)
hasSingleInstanceLock = sinon.spy(() => true)
releaseSingleInstanceLock = sinon.spy()
setUserActivity = sinon.spy()
getCurrentActivityType = sinon.spy()
invalidateCurrentActivity = sinon.spy()
resignCurrentActivity = sinon.spy()
updateCurrentActivity = sinon.spy()
setAppUserModelId = sinon.spy()
setActivationPolicy = sinon.spy()
importCertificate = sinon.spy()
configureHostResolver = sinon.spy()
disableHardwareAcceleration = sinon.spy()
disableDomainBlockingFor3DAPIs = sinon.spy()
getAppMetrics = sinon.spy(() => [])
getGPUFeatureStatus = sinon.spy(() => ({}) as Electron.GPUFeatureStatus)
getGPUInfo = sinon.spy(() => Promise.resolve({}))
setBadgeCount = sinon.spy()
getBadgeCount = sinon.spy(() => 0)
isUnityRunning = sinon.spy(() => false)
private _loginItemSettings: Electron.LoginItemSettings = {
openAtLogin: false,
openAsHidden: false,
wasOpenedAtLogin: false,
wasOpenedAsHidden: false,
restoreState: false,
status: 'not-found',
executableWillLaunchAtLogin: true,
launchItems: [],
}
getLoginItemSettings = sinon.spy(() => this._loginItemSettings)
setLoginItemSettings = sinon.spy(
(settings: Partial<Electron.LoginItemSettings>) => {
Object.assign(this._loginItemSettings, settings)
},
)
isAccessibilitySupportEnabled = sinon.spy(
() => this.accessibilitySupportEnabled,
)
setAccessibilitySupportEnabled = sinon.spy(
(enabled: boolean) => (this.accessibilitySupportEnabled = enabled),
)
showAboutPanel = sinon.spy()
setAboutPanelOptions = sinon.spy()
isEmojiPanelSupported = sinon.spy(() => true)
showEmojiPanel = sinon.spy()
startAccessingSecurityScopedResource = sinon.spy(
// fun!
() => () => Promise.resolve(''),
)
enableSandbox = sinon.spy()
isInApplicationsFolder = sinon.spy(() => true)
moveToApplicationsFolder = sinon.spy()
isSecureKeyboardEntryEnabled = sinon.spy(() => false)
setSecureKeyboardEntryEnabled = sinon.spy()
setProxy = sinon.spy()
resolveProxy = sinon.spy((url: string) => Promise.resolve(url))
setClientCertRequestPasswordHandler = sinon.spy()

// Properties
accessibilitySupportEnabled = false
applicationMenu: Electron.Menu = null
commandLine = {
appendSwitch: sinon.spy(),
appendArgument: sinon.spy(),
hasSwitch: sinon.spy(),
getSwitchValue: sinon.spy(),
removeSwitch: sinon.spy(),
}
dock = {
bounce: sinon.spy(),
cancelBounce: sinon.spy(),
downloadFinished: sinon.spy(),
setBadge: sinon.spy(),
getBadge: sinon.spy(),
hide: sinon.spy(),
show: sinon.spy(),
isVisible: sinon.spy(),
setMenu: sinon.spy(),
getMenu: sinon.spy(),
setIcon: sinon.spy(),
}
badgeCount: number = 0
isPackaged: boolean = true
name = 'MockApp'
userAgentFallback = 'MockApp'
runningUnderARM64Translation = false

constructor() {
super()
}
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './MockApp'
export * from './MockAutoUpdater'
export * from './MockBrowserWindow'
export * from './MockDialog'
Expand All @@ -6,4 +7,5 @@ export * from './MockDownloadItem'
export * from './MockIpcMain'
export * from './MockIpcRenderer'
export * from './MockScreen'
export * from './MockView'
export * from './MockWebContents'
Loading

0 comments on commit b059356

Please sign in to comment.