|
| 1 | +// |
| 2 | +// Note: This example test is leveraging the Mocha test framework. |
| 3 | +// Please refer to their documentation on https://mochajs.org/ for help. |
| 4 | +// |
| 5 | + |
| 6 | +// The module 'assert' provides assertion methods from node |
| 7 | +import * as assert from "assert"; |
| 8 | + |
| 9 | +// You can import and use all API from the 'vscode' module |
| 10 | +// as well as import your extension to test it |
| 11 | +import * as fs from "fs"; |
| 12 | +import * as path from "path"; |
| 13 | +import * as vscode from "vscode"; |
| 14 | +import * as testUtil from "./testUtil"; |
| 15 | +import { |
| 16 | + Uri, |
| 17 | + commands, |
| 18 | + workspace, |
| 19 | + window, |
| 20 | + InputBoxOptions, |
| 21 | + CancellationToken, |
| 22 | + QuickPickOptions, |
| 23 | + QuickPickItem |
| 24 | +} from "vscode"; |
| 25 | +import { Svn } from "../svn"; |
| 26 | +import { Model } from "../model"; |
| 27 | +import { SvnFinder, ISvn } from "../svnFinder"; |
| 28 | +import { Repository } from "../repository"; |
| 29 | +import { timeout } from "../util"; |
| 30 | +import { SvnResourceGroup } from "../resource"; |
| 31 | + |
| 32 | +// Defines a Mocha test suite to group tests of similar kind together |
| 33 | +suite("Commands Tests", () => { |
| 34 | + let repoUri: Uri; |
| 35 | + let checkoutDir: Uri; |
| 36 | + let model: Model; |
| 37 | + |
| 38 | + suiteSetup(async () => { |
| 39 | + await testUtil.activeExtension(); |
| 40 | + |
| 41 | + repoUri = await testUtil.createRepoServer(); |
| 42 | + await testUtil.createStandardLayout(testUtil.getSvnUrl(repoUri)); |
| 43 | + checkoutDir = await testUtil.createRepoCheckout( |
| 44 | + testUtil.getSvnUrl(repoUri) + "/trunk" |
| 45 | + ); |
| 46 | + |
| 47 | + model = (await commands.executeCommand( |
| 48 | + "svn._getModel", |
| 49 | + checkoutDir |
| 50 | + )) as Model; |
| 51 | + |
| 52 | + await model.tryOpenRepository(checkoutDir.fsPath); |
| 53 | + }); |
| 54 | + |
| 55 | + suiteTeardown(() => { |
| 56 | + model.openRepositories.forEach(repository => repository.dispose()); |
| 57 | + testUtil.destroyAllTempPaths(); |
| 58 | + }); |
| 59 | + |
| 60 | + test("File Open", async function() { |
| 61 | + const file = path.join(checkoutDir.fsPath, "new.txt"); |
| 62 | + fs.writeFileSync(file, "test"); |
| 63 | + |
| 64 | + await commands.executeCommand("svn.fileOpen", Uri.file(file)); |
| 65 | + }); |
| 66 | + |
| 67 | + test("Add File", async function() { |
| 68 | + const repository = model.getRepository(checkoutDir) as Repository; |
| 69 | + |
| 70 | + await commands.executeCommand("svn.refresh"); |
| 71 | + assert.equal(repository.unversioned.resourceStates.length, 1); |
| 72 | + assert.equal(repository.changes.resourceStates.length, 0); |
| 73 | + |
| 74 | + const resource = repository.unversioned.resourceStates[0]; |
| 75 | + |
| 76 | + await commands.executeCommand("svn.add", resource); |
| 77 | + |
| 78 | + assert.equal(repository.unversioned.resourceStates.length, 0); |
| 79 | + assert.equal(repository.changes.resourceStates.length, 1); |
| 80 | + }); |
| 81 | + |
| 82 | + test("Commit File", async function() { |
| 83 | + const repository = model.getRepository(checkoutDir) as Repository; |
| 84 | + repository.inputBox.value = "First Commit"; |
| 85 | + |
| 86 | + await commands.executeCommand("svn.commitWithMessage"); |
| 87 | + }); |
| 88 | + |
| 89 | + test("Update", async function() { |
| 90 | + await commands.executeCommand("svn.update"); |
| 91 | + }); |
| 92 | + |
| 93 | + test("Show Log", async function() { |
| 94 | + await commands.executeCommand("svn.log"); |
| 95 | + }); |
| 96 | + |
| 97 | + test("Open Changes", async function() { |
| 98 | + const file = path.join(checkoutDir.fsPath, "new.txt"); |
| 99 | + fs.writeFileSync(file, "test 2"); |
| 100 | + const uri = Uri.file(file); |
| 101 | + |
| 102 | + await commands.executeCommand("svn.refresh"); |
| 103 | + await commands.executeCommand("svn.openChangeBase", uri); |
| 104 | + await commands.executeCommand("svn.openChangeHead", uri); |
| 105 | + }); |
| 106 | + |
| 107 | + test("Open File", async function() { |
| 108 | + const file = path.join(checkoutDir.fsPath, "new.txt"); |
| 109 | + const uri = Uri.file(file); |
| 110 | + |
| 111 | + await commands.executeCommand("svn.openFile", uri); |
| 112 | + await commands.executeCommand("svn.openHEADFile", uri); |
| 113 | + }); |
| 114 | + |
| 115 | + test("Open Diff (Double click o source control)", async function() { |
| 116 | + const repository = model.getRepository(checkoutDir) as Repository; |
| 117 | + |
| 118 | + await commands.executeCommand("svn.refresh"); |
| 119 | + assert.equal(repository.changes.resourceStates.length, 1); |
| 120 | + |
| 121 | + const resource = repository.changes.resourceStates[0]; |
| 122 | + |
| 123 | + await commands.executeCommand("svn.openResourceBase", resource); |
| 124 | + await commands.executeCommand("svn.openResourceHead", resource); |
| 125 | + }); |
| 126 | + |
| 127 | + test("Add Changelist", async function() { |
| 128 | + const repository = model.getRepository(checkoutDir) as Repository; |
| 129 | + |
| 130 | + await commands.executeCommand("svn.refresh"); |
| 131 | + assert.equal(repository.changes.resourceStates.length, 1); |
| 132 | + |
| 133 | + const resource = repository.changes.resourceStates[0]; |
| 134 | + |
| 135 | + testUtil.overrideNextShowQuickPick(0); |
| 136 | + testUtil.overrideNextShowInputBox("changelist-test"); |
| 137 | + |
| 138 | + await commands.executeCommand("svn.addChangelist", resource); |
| 139 | + assert.ok(repository.changelists.has("changelist-test")); |
| 140 | + }); |
| 141 | + |
| 142 | + test("Remove Changelist", async function() { |
| 143 | + const repository = model.getRepository(checkoutDir) as Repository; |
| 144 | + |
| 145 | + const group = repository.changelists.get( |
| 146 | + "changelist-test" |
| 147 | + ) as SvnResourceGroup; |
| 148 | + const resource = group.resourceStates[0]; |
| 149 | + |
| 150 | + await commands.executeCommand("svn.removeChangelist", resource); |
| 151 | + assert.equal(group.resourceStates.length, 0); |
| 152 | + }); |
| 153 | + |
| 154 | + test("Show Patch", async function() { |
| 155 | + await commands.executeCommand("svn.patch"); |
| 156 | + }); |
| 157 | + |
| 158 | + test("Commit Selected File", async function() { |
| 159 | + const repository = model.getRepository(checkoutDir) as Repository; |
| 160 | + |
| 161 | + await commands.executeCommand("svn.refresh"); |
| 162 | + assert.equal(repository.changes.resourceStates.length, 1); |
| 163 | + |
| 164 | + const resource = repository.changes.resourceStates[0]; |
| 165 | + |
| 166 | + testUtil.overrideNextShowInputBox("Second Commit"); |
| 167 | + await commands.executeCommand("svn.commit", resource); |
| 168 | + |
| 169 | + assert.equal(repository.changes.resourceStates.length, 0); |
| 170 | + }); |
| 171 | + |
| 172 | + test("Commit File", async function() { |
| 173 | + const repository = model.getRepository(checkoutDir) as Repository; |
| 174 | + repository.inputBox.value = "First Commit"; |
| 175 | + |
| 176 | + await commands.executeCommand("svn.commitWithMessage"); |
| 177 | + }); |
| 178 | + |
| 179 | + test("New Branch", async function() { |
| 180 | + testUtil.overrideNextShowInputBox("test"); |
| 181 | + await commands.executeCommand("svn.branch"); |
| 182 | + |
| 183 | + const repository = model.getRepository(checkoutDir) as Repository; |
| 184 | + assert.equal(await repository.getCurrentBranch(), "test"); |
| 185 | + }); |
| 186 | + |
| 187 | + test("Switch Branch", async function() { |
| 188 | + testUtil.overrideNextShowQuickPick(1); |
| 189 | + await commands.executeCommand("svn.switchBranch"); |
| 190 | + |
| 191 | + const repository = model.getRepository(checkoutDir) as Repository; |
| 192 | + assert.equal(await repository.getCurrentBranch(), "trunk"); |
| 193 | + }); |
| 194 | +}); |
0 commit comments