-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ken Howard
committed
Nov 21, 2018
1 parent
0865240
commit 3c9c0d7
Showing
7 changed files
with
81 additions
and
10 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
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
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 { window } from 'vscode'; | ||
|
||
import { notify } from '../notify'; | ||
|
||
let showErrorSpy: jest.SpyInstance<typeof window.showErrorMessage>; | ||
let showInfoSpy: jest.SpyInstance< | ||
typeof window.showInformationMessage | ||
> = jest.spyOn(window, 'showInformationMessage'); | ||
|
||
describe('Notify Tests', () => { | ||
beforeEach(() => { | ||
showErrorSpy = jest.spyOn(window, 'showErrorMessage'); | ||
showInfoSpy = jest.spyOn(window, 'showInformationMessage'); | ||
}); | ||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
describe('#error', () => { | ||
test('should notify user of error', () => { | ||
expect.assertions(1); | ||
|
||
notify.error('Foo', 'Bar'); | ||
|
||
expect(showErrorSpy.mock.calls[0][0]).toBe('GIST ERROR: Foo > Bar'); | ||
}); | ||
}); | ||
describe('#info', () => { | ||
test('should notify user of info', () => { | ||
expect.assertions(1); | ||
|
||
notify.info('Foo', 'Bar'); | ||
|
||
expect(showInfoSpy.mock.calls[0][0]).toBe('GIST: Foo > Bar'); | ||
}); | ||
}); | ||
}); |
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 +1,2 @@ | ||
export * from './file'; | ||
export * from './notify'; |
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,32 @@ | ||
import { window } from 'vscode'; | ||
|
||
import { logger } from '../logger'; | ||
|
||
const _notify = (type: 'error' | 'info', ...messages: string[]): void => { | ||
const formattedMessage = [...messages] | ||
.filter((m?: string) => typeof m !== 'undefined') | ||
.join(' > '); | ||
switch (type) { | ||
case 'error': | ||
window.showErrorMessage(`GIST ERROR: ${formattedMessage}`); | ||
break; | ||
case 'info': | ||
window.showInformationMessage(`GIST: ${formattedMessage}`); | ||
break; | ||
default: | ||
logger.error(`Invalid Notify Type "${type}"`); | ||
} | ||
}; | ||
|
||
const error = (...messages: string[]): void => { | ||
_notify('error', ...messages); | ||
}; | ||
|
||
const info = (...messages: string[]): void => { | ||
_notify('info', ...messages); | ||
}; | ||
|
||
export const notify = { | ||
error, | ||
info | ||
}; |