forked from finos/SymphonyElectron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
protocol handle unit test (finos#576)
- Loading branch information
1 parent
83b6a6c
commit cab3576
Showing
1 changed file
with
75 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
jest.mock('../src/app/window-actions', () => { | ||
return { | ||
activate: jest.fn(), | ||
}; | ||
}); | ||
|
||
jest.mock('../src/common/utils', () => { | ||
return { | ||
getCommandLineArgs: jest.fn(() => 'symphony://?userId=22222'), | ||
}; | ||
}); | ||
|
||
jest.mock('../src/common/env', () => { | ||
return { | ||
isWindowsOS: false, | ||
}; | ||
}); | ||
|
||
describe('protocol handler', () => { | ||
let protocolHandlerInstance; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
const { protocolHandler } = require('../src/app/protocol-handler'); | ||
protocolHandlerInstance = protocolHandler; | ||
}); | ||
|
||
it('protocol uri should be null by default', () => { | ||
expect(protocolHandlerInstance.protocolUri).toBeNull(); | ||
}); | ||
|
||
it('protocol action should be called when uri is correct', () => { | ||
protocolHandlerInstance.preloadWebContents = { send: jest.fn() }; | ||
|
||
const spy: jest.SpyInstance = jest.spyOn(protocolHandlerInstance.preloadWebContents, 'send'); | ||
const uri: string = 'symphony://?userId=123456'; | ||
const protocolAction: string = 'protocol-action'; | ||
|
||
protocolHandlerInstance.sendProtocol(uri); | ||
|
||
expect(spy).toBeCalledWith(protocolAction, 'symphony://?userId=123456'); | ||
}); | ||
|
||
it('protocol action not should be called when uri is incorrect', () => { | ||
protocolHandlerInstance.preloadWebContents = { send: jest.fn() }; | ||
|
||
const spy: jest.SpyInstance = jest.spyOn(protocolHandlerInstance.preloadWebContents, 'send'); | ||
const uri: string = 'symphony---://?userId=123456'; | ||
const protocolAction: string = 'protocol-action'; | ||
|
||
protocolHandlerInstance.sendProtocol(uri); | ||
|
||
expect(spy).not.toBeCalledWith(protocolAction, 'symphony://?userId=123456'); | ||
}); | ||
|
||
it('protocol should get uri from `processArgv` when `getCommandLineArgs` is called', () => { | ||
const { getCommandLineArgs } = require('../src/common/utils'); | ||
|
||
protocolHandlerInstance.processArgv(''); | ||
|
||
expect(getCommandLineArgs).toBeCalled(); | ||
}); | ||
|
||
it('should be called `sendProtocol` when is windowsOS on `processArgs`', () => { | ||
const env = require('../src/common/env'); | ||
env.isWindowsOS = true; | ||
|
||
const spy: jest.SpyInstance = jest.spyOn(protocolHandlerInstance, 'sendProtocol'); | ||
|
||
protocolHandlerInstance.processArgv(''); | ||
|
||
expect(spy).toBeCalled(); | ||
}); | ||
|
||
}); |