|
| 1 | +import 'vscode-test'; |
| 2 | +import 'mocha'; |
| 3 | +import * as chaiAsPromised from 'chai-as-promised'; |
| 4 | +import * as sinon from 'sinon'; |
| 5 | +import * as chai from 'chai'; |
| 6 | +import { window } from 'vscode'; |
| 7 | +import * as pq from 'proxyquire'; |
| 8 | + |
| 9 | +const proxyquire = pq.noPreserveCache(); |
| 10 | +chai.use(chaiAsPromised); |
| 11 | +const expect = chai.expect; |
| 12 | + |
| 13 | +describe('run-remote-query', function() { |
| 14 | + |
| 15 | + describe('getRepositories', () => { |
| 16 | + let sandbox: sinon.SinonSandbox; |
| 17 | + let quickPickSpy: sinon.SinonStub; |
| 18 | + let showInputBoxSpy: sinon.SinonStub; |
| 19 | + let getRemoteRepositoryListsSpy: sinon.SinonStub; |
| 20 | + let mod: any; |
| 21 | + beforeEach(() => { |
| 22 | + sandbox = sinon.createSandbox(); |
| 23 | + quickPickSpy = sandbox.stub(window, 'showQuickPick'); |
| 24 | + showInputBoxSpy = sandbox.stub(window, 'showInputBox'); |
| 25 | + getRemoteRepositoryListsSpy = sandbox.stub(); |
| 26 | + mod = proxyquire('../../run-remote-query', { |
| 27 | + './config': { |
| 28 | + getRemoteRepositoryLists: getRemoteRepositoryListsSpy |
| 29 | + } |
| 30 | + }); |
| 31 | + |
| 32 | + }); |
| 33 | + |
| 34 | + afterEach(() => { |
| 35 | + sandbox.restore(); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should return a repo list that you chose from your pre-defined config', async () => { |
| 39 | + // fake return values |
| 40 | + quickPickSpy.resolves( |
| 41 | + { repoList: ['foo/bar', 'foo/baz'] } |
| 42 | + ); |
| 43 | + getRemoteRepositoryListsSpy.returns( |
| 44 | + { |
| 45 | + 'list1': ['foo/bar', 'foo/baz'], |
| 46 | + 'list2': [], |
| 47 | + } |
| 48 | + ); |
| 49 | + |
| 50 | + // make the function call |
| 51 | + const repoList = await mod.getRepositories(); |
| 52 | + |
| 53 | + // Check that the return value is correct |
| 54 | + expect(repoList).to.deep.eq( |
| 55 | + ['foo/bar', 'foo/baz'] |
| 56 | + ); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should show a textbox if you have no repo lists configured', async () => { |
| 60 | + // fake return values |
| 61 | + showInputBoxSpy.resolves('foo/bar'); |
| 62 | + getRemoteRepositoryListsSpy.returns({}); |
| 63 | + |
| 64 | + // make the function call |
| 65 | + const repoList = await mod.getRepositories(); |
| 66 | + |
| 67 | + // Check that the return value is correct |
| 68 | + expect(repoList).to.deep.equal( |
| 69 | + ['foo/bar'] |
| 70 | + ); |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
| 74 | + describe('runRemoteQuery', () => { |
| 75 | + // TODO |
| 76 | + }); |
| 77 | +}); |
0 commit comments