Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions test/unit/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

### Rules & Expectations

- Do not edit application/source files unless the refactor demands it. Confirm before editing files outside of /test/unit, and justify why you need to make those changes.
- Do not edit application/source files unless writing effective unit tests demands it. Confirm before editing files outside of /test/unit, and justify why you need to make those changes.
- Use Sinon, not TypeMoq. If easily possible, replace TypeMoq mocks/stubs/helpers with Sinon equivalents.
- Use a Sinon sandbox (setup/teardown with sinon.createSandbox()); keep helper closures (e.g., createServer) inside setup where the
sandbox is created.
- Default to chai.expect; when checking Sinon interactions, use sinon-chai.
- Use chai's `expect` for assertions; when checking Sinon interactions, use sinon-chai. Avoid `sinon.assert` and Node's `assert` in favor of `expect(...).to.have.been...` helpers.
- Avoid Object.defineProperty hacks and (if possible) fake/partial plain objects; use sandbox.createStubInstance(type) and sandbox.stub(obj, 'prop').value(...).
- Add shared Sinon helpers to test/unit/utils.ts when they’ll be reused.
- If updating preexisting tests, preserve relevant inline comments from the original tests.
- When introducing a Sinon helper to replace a TypeMoq helper (e.g., capabilities mock), follow the utils.ts pattern: accept an optional
sandbox, create stub instances, and return them.
- Avoid unnecessary casts, like `myVar as unknown as MyType` when myVar is already a sinon-stubbed instance of MyType.
- Maintain existing formatting conventions, line endings, and text encoding.
- Nest test suits as necessary to group tests in a logical manner.
- Nest test suites as necessary to group tests in a logical manner.
- Always await async prompt helpers (for example, `await prompt.render()`) so sinon stubs execute before assertions.
- If the class under test relies on VS Code services (event emitters, secret storage, etc.), stub their accessors via the sandbox (e.g., `sandbox.stub(obj, 'prop').get(() => emitter)` or provide a real `new vscode.EventEmitter()`) rather than providing a plain object.

### Process

Expand Down
260 changes: 116 additions & 144 deletions test/unit/chatCommands.test.ts

Large diffs are not rendered by default.

80 changes: 43 additions & 37 deletions test/unit/checkbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,73 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as TypeMoq from "typemoq";
import * as sinon from "sinon";
import sinonChai from "sinon-chai";
import { expect } from "chai";
import * as chai from "chai";
import * as figures from "figures";
import VscodeWrapper from "../../src/controllers/vscodeWrapper";
import CheckboxPrompt from "../../src/prompts/checkbox";

chai.use(sinonChai);

// @cssuh 10/22 - commented this test because it was throwing some random undefined errors
suite("Test Checkbox prompt", () => {
test("Test checkbox prompt with simple question", () => {
let question = {
let sandbox: sinon.SinonSandbox;

setup(() => {
sandbox = sinon.createSandbox();
});

teardown(() => {
sandbox.restore();
});

test("Test checkbox prompt with simple question", async () => {
const question = {
choices: [
{ name: "test1", checked: true },
{ name: "test2", checked: false },
],
};
let vscodeWrapper = TypeMoq.Mock.ofType(VscodeWrapper, TypeMoq.MockBehavior.Loose);
vscodeWrapper
.setup((v) => v.showQuickPickStrings(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => Promise.resolve("test1"));
let checkbox = new CheckboxPrompt(question, vscodeWrapper.object);
checkbox.render();
vscodeWrapper.verify(
(v) => v.showQuickPickStrings(TypeMoq.It.isAny(), TypeMoq.It.isAny()),
TypeMoq.Times.once(),
);
const vscodeWrapper = sandbox.createStubInstance(VscodeWrapper);
vscodeWrapper.showQuickPickStrings.resolves(figures.tick);

const checkbox = new CheckboxPrompt(question, vscodeWrapper);
await checkbox.render();

expect(vscodeWrapper.showQuickPickStrings).to.have.been.calledOnce;
});

test("Test Checkbox prompt with error", () => {
let question = {
test("Test Checkbox prompt with error", async () => {
const question = {
choices: [
{ name: "test1", checked: true },
{ name: "test2", checked: false },
],
};
let vscodeWrapper = TypeMoq.Mock.ofType(VscodeWrapper, TypeMoq.MockBehavior.Loose);
vscodeWrapper
.setup((v) => v.showQuickPickStrings(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => Promise.resolve(undefined));
let checkbox = new CheckboxPrompt(question, vscodeWrapper.object);
checkbox.render();
vscodeWrapper.verify(
(v) => v.showQuickPickStrings(TypeMoq.It.isAny(), TypeMoq.It.isAny()),
TypeMoq.Times.once(),
);
const vscodeWrapper = sandbox.createStubInstance(VscodeWrapper);
vscodeWrapper.showQuickPickStrings.resolves(undefined);

const checkbox = new CheckboxPrompt(question, vscodeWrapper);
await checkbox.render().catch(() => undefined);

expect(vscodeWrapper.showQuickPickStrings).to.have.been.calledOnce;
});

test("Test Checkbox prompt with checked answer", () => {
let question = {
test("Test Checkbox prompt with checked answer", async () => {
const question = {
choices: [
{ name: "test1", checked: true },
{ name: "test2", checked: false },
],
};
let vscodeWrapper = TypeMoq.Mock.ofType(VscodeWrapper, TypeMoq.MockBehavior.Loose);
vscodeWrapper
.setup((v) => v.showQuickPickStrings(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => Promise.resolve(figures.tick));
let checkbox = new CheckboxPrompt(question, vscodeWrapper.object);
checkbox.render();
vscodeWrapper.verify(
(v) => v.showQuickPickStrings(TypeMoq.It.isAny(), TypeMoq.It.isAny()),
TypeMoq.Times.once(),
);
const vscodeWrapper = sandbox.createStubInstance(VscodeWrapper);
vscodeWrapper.showQuickPickStrings.resolves(figures.tick);

const checkbox = new CheckboxPrompt(question, vscodeWrapper);
await checkbox.render();

expect(vscodeWrapper.showQuickPickStrings).to.have.been.calledOnce;
});
});
Loading