-
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 23, 2018
1 parent
3c36271
commit 40a4f86
Showing
22 changed files
with
605 additions
and
46 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ out | |
node_modules | ||
.vscode-test/ | ||
*.vsix | ||
.DS_STORE |
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,175 @@ | ||
// tslint:disable:no-any no-unsafe-any no-magic-numbers | ||
import { commands, window } from 'vscode'; | ||
|
||
import { logger } from '../../logger'; | ||
import { profiles } from '../../profiles'; | ||
|
||
const debugSpy = jest.spyOn(logger, 'debug'); | ||
|
||
const executeCommandSpy = jest.spyOn(commands, 'executeCommand'); | ||
const showQuickPickSpy = jest.spyOn(window, 'showQuickPick'); | ||
const showInformationMessageSpy = jest.spyOn(window, 'showInformationMessage'); | ||
const showInputBoxSpy = jest.spyOn(window, 'showInputBox'); | ||
|
||
import { | ||
clearProfiles, | ||
createProfile, | ||
selectProfile | ||
} from '../profile.commands'; | ||
|
||
const mockProfile = { | ||
key: '111', | ||
name: 'GHE', | ||
url: 'http://foo.bar.bas' | ||
}; | ||
|
||
describe('Profile Commands Tests', () => { | ||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
describe('#clearProfiles', () => { | ||
test('should clear profiles', () => { | ||
expect.assertions(1); | ||
|
||
clearProfiles(); | ||
|
||
expect(executeCommandSpy).toHaveBeenCalledWith( | ||
'extension.updateStatusBar' | ||
); | ||
}); | ||
}); | ||
describe('#createProfile', () => { | ||
test('should show information message prompt', async () => { | ||
expect.assertions(2); | ||
|
||
showInformationMessageSpy.mockResolvedValue({ | ||
isCloseAffordance: true, | ||
title: 'GitHub.com (common)' | ||
}); | ||
|
||
await createProfile(); | ||
|
||
expect(showInformationMessageSpy).toHaveBeenCalledTimes(1); | ||
expect(showInformationMessageSpy).toHaveBeenCalledWith( | ||
'Which GitHub Platform?', | ||
{ modal: true }, | ||
{ title: 'GitHub.com (common)', isCloseAffordance: true }, | ||
{ title: 'GitHub Enterprise' } | ||
); | ||
}); | ||
test('should gather information from the user', async () => { | ||
expect.assertions(1); | ||
|
||
showInformationMessageSpy.mockResolvedValue({ | ||
title: 'GitHub Enterprise' | ||
}); | ||
|
||
showInputBoxSpy.mockResolvedValueOnce('foo'); | ||
showInputBoxSpy.mockResolvedValueOnce('bar'); | ||
showInputBoxSpy.mockResolvedValueOnce('bat'); | ||
|
||
await createProfile(); | ||
|
||
expect(showInputBoxSpy).toHaveBeenCalledTimes(3); | ||
}); | ||
test('should log stuff when a user exits without entering "url"', async () => { | ||
expect.assertions(2); | ||
|
||
showInformationMessageSpy.mockResolvedValue({ | ||
title: 'GitHub Enterprise' | ||
}); | ||
|
||
showInputBoxSpy.mockResolvedValueOnce(undefined); | ||
|
||
await createProfile(); | ||
|
||
expect(debugSpy).toHaveBeenCalledTimes(1); | ||
expect(debugSpy.mock.calls[0][0]).toContain('"url"'); | ||
}); | ||
test('should log stuff when a user exits without entering "key"', async () => { | ||
expect.assertions(2); | ||
|
||
showInformationMessageSpy.mockResolvedValue({ | ||
title: 'GitHub Enterprise' | ||
}); | ||
|
||
showInputBoxSpy.mockResolvedValueOnce('foo'); | ||
showInputBoxSpy.mockResolvedValueOnce(undefined); | ||
|
||
await createProfile(); | ||
|
||
expect(debugSpy).toHaveBeenCalledTimes(1); | ||
expect(debugSpy.mock.calls[0][0]).toContain('"key"'); | ||
}); | ||
test('should log stuff when a user exits without entering "name"', async () => { | ||
expect.assertions(2); | ||
|
||
showInformationMessageSpy.mockResolvedValue({ | ||
title: 'GitHub Enterprise' | ||
}); | ||
|
||
showInputBoxSpy.mockResolvedValueOnce('foo'); | ||
showInputBoxSpy.mockResolvedValueOnce('bar'); | ||
showInputBoxSpy.mockResolvedValueOnce(undefined); | ||
|
||
await createProfile(); | ||
|
||
expect(debugSpy).toHaveBeenCalledTimes(1); | ||
expect(debugSpy.mock.calls[0][0]).toContain('"name"'); | ||
}); | ||
}); | ||
describe('#selectProfile', () => { | ||
test('should open quick pick to select a profile', async () => { | ||
expect.assertions(1); | ||
|
||
const getAllSpy = jest.spyOn(profiles, 'getAll'); | ||
|
||
getAllSpy.mockReturnValue([mockProfile]); | ||
|
||
await selectProfile(); | ||
|
||
expect(showQuickPickSpy.mock.calls[0].length).toBe(1); | ||
}); | ||
test('should open create profile dialog if zero profiles found', async () => { | ||
expect.assertions(3); | ||
|
||
const getAllSpy = jest.spyOn(profiles, 'getAll'); | ||
|
||
await selectProfile(); | ||
|
||
expect(getAllSpy).toHaveBeenCalledTimes(1); | ||
expect(getAllSpy.mock.results[0].value).toBeUndefined(); | ||
expect(executeCommandSpy).toBeCalledWith('extension.createProfile'); | ||
}); | ||
test('should open create profile dialog if chooses', async () => { | ||
expect.assertions(2); | ||
|
||
const getAllSpy = jest.spyOn(profiles, 'getAll'); | ||
getAllSpy.mockReturnValue([mockProfile]); | ||
|
||
showQuickPickSpy.mockResolvedValue({ label: 'Create New Profile' }); | ||
|
||
await selectProfile(); | ||
|
||
expect(getAllSpy).toHaveBeenCalledTimes(1); | ||
expect(executeCommandSpy).toBeCalledWith('extension.createProfile'); | ||
}); | ||
test('should update gist access key', async () => { | ||
expect.assertions(1); | ||
|
||
const getAllSpy = jest.spyOn(profiles, 'getAll'); | ||
|
||
getAllSpy.mockReturnValue([mockProfile]); | ||
|
||
showQuickPickSpy.mockResolvedValueOnce({ | ||
profile: mockProfile | ||
}); | ||
|
||
await selectProfile(); | ||
|
||
expect(executeCommandSpy).toHaveBeenLastCalledWith( | ||
'extension.updateGistAccessKey' | ||
); | ||
}); | ||
}); | ||
}); |
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 +1,3 @@ | ||
export * from './gists.commands'; | ||
export * from './profile.commands'; | ||
export * from './status-bar.commands'; |
Oops, something went wrong.