Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(chat): Prompt to connect when a disconnected user tries to run code from participant VSCODE-618 #872

Merged
merged 1 commit into from
Nov 19, 2024
Merged
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
9 changes: 6 additions & 3 deletions src/editors/playgroundController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,13 @@ export default class PlaygroundController {
.get('confirmRunCopilotCode');

if (!this._connectionController.isCurrentlyConnected()) {
// TODO(VSCODE-618): Prompt user to connect when clicked.
void vscode.window.showErrorMessage(connectBeforeRunningMessage);
const successfullyConnected =
await this._connectionController.changeActiveConnection();

return false;
if (!successfullyConnected) {
void vscode.window.showErrorMessage(connectBeforeRunningMessage);
return false;
}
}

if (shouldConfirmRunCopilotCode === true) {
Expand Down
83 changes: 83 additions & 0 deletions src/test/suite/editors/playgroundController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,60 @@ suite('Playground Controller Test Suite', function () {
expectedMessage
);
});

suite('running code from the participant', function () {
beforeEach(function () {
sinon
.stub(testPlaygroundController, '_evaluateWithCancelModal')
.resolves({ result: '123' } as any);
sinon.stub(testPlaygroundController, '_openInResultPane').resolves();

showInformationMessageStub.resolves('Yes');
});

afterEach(() => sinon.restore());

test('prompts to connect to a database and succeeds with selection', async () => {
const changeActiveConnectionStub = sinon.stub(
testPlaygroundController._connectionController,
'changeActiveConnection'
);
// Mocks the user selecting a connection.
changeActiveConnectionStub.resolves(true);

const result = await testPlaygroundController.evaluateParticipantCode(
'console.log("test");'
);

expect(showErrorMessageStub.notCalled).is.true;

expect(changeActiveConnectionStub.calledOnce).is.true;

expect(result).is.true;
});

test('prompts to connect to a database and errors if not selected', async () => {
const changeActiveConnectionStub = sinon.stub(
testPlaygroundController._connectionController,
'changeActiveConnection'
);
// Mocks the user selecting a connection.
changeActiveConnectionStub.resolves(false);

const result = await testPlaygroundController.evaluateParticipantCode(
'console.log("test");'
);

const expectedMessage =
'Please connect to a database before running a playground.';
await testPlaygroundController.runAllOrSelectedPlaygroundBlocks();
expect(showErrorMessageStub.firstCall.args[0]).to.be.equal(
expectedMessage
);

expect(result).is.false;
});
});
});

suite('user is connected', () => {
Expand Down Expand Up @@ -431,6 +485,35 @@ suite('Playground Controller Test Suite', function () {
expect(result).to.be.false;
});
});

suite('running code from the participant', function () {
beforeEach(function () {
sinon
.stub(testPlaygroundController, '_evaluateWithCancelModal')
.resolves({ result: '123' } as any);
sinon.stub(testPlaygroundController, '_openInResultPane').resolves();

showInformationMessageStub.resolves('Yes');
});

afterEach(() => sinon.restore());

test('does not prompt to connect to the database', async () => {
const changeActiveConnectionStub = sinon.stub(
testPlaygroundController._connectionController,
'changeActiveConnection'
);
const result = await testPlaygroundController.evaluateParticipantCode(
'console.log("test");'
);

expect(showErrorMessageStub.notCalled).is.true;

expect(changeActiveConnectionStub.notCalled).is.true;

expect(result).is.true;
});
});
});
});
});
Loading