Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik committed Nov 29, 2024
1 parent efb1432 commit 93fb8f8
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/test/suite/participant/participant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import {
} from './participantHelpers';
import EditDocumentCodeLensProvider from '../../../editors/editDocumentCodeLensProvider';
import PlaygroundResultProvider from '../../../editors/playgroundResultProvider';
import { CollectionTreeItem, DatabaseTreeItem } from '../../../explorer';
import type { SendMessageToParticipantOptions } from '../../../participant/participantTypes';

// The Copilot's model in not available in tests,
// therefore we need to mock its methods and returning values.
Expand Down Expand Up @@ -1802,6 +1804,87 @@ Schema:
});
});

suite('opened from tree view', function () {
let sendMessageToParticipantStub: SinonStub<
[options: SendMessageToParticipantOptions],
Promise<unknown>
>;

beforeEach(function () {
sendMessageToParticipantStub = sinon.stub(
testParticipantController,
'sendMessageToParticipant'
);
});

suite('with a database item', function () {
const mockDatabaseItem = Object.assign(
Object.create(DatabaseTreeItem.prototype),
{
databaseName: 'testDb',
} as DatabaseTreeItem
);

test('opens the chat and sends a message to set database context', async function () {
expect(sendMessageToParticipantStub).not.called;

await testParticipantController.askCopilotFromTreeItem(
mockDatabaseItem
);

expect(sendMessageToParticipantStub).has.callCount(2);

expect(sendMessageToParticipantStub.getCall(0).args).deep.equals([
{
message: `I want to ask questions about the \`${mockDatabaseItem.databaseName}\` database.`,
isNewChat: true,
},
]);

expect(sendMessageToParticipantStub.getCall(1).args).deep.equals([
{
message: '',
isPartialQuery: true,
},
]);
});
});

suite('with a collection item', function () {
const mockCollectionItem = Object.assign(
Object.create(CollectionTreeItem.prototype),
{
databaseName: 'testDb',
collectionName: 'testColl',
} as CollectionTreeItem
);

test('opens the chat and sends a message to set database and collection context', async function () {
expect(sendMessageToParticipantStub).not.called;

await testParticipantController.askCopilotFromTreeItem(
mockCollectionItem
);

expect(sendMessageToParticipantStub).has.callCount(2);

expect(sendMessageToParticipantStub.getCall(0).args).deep.equals([
{
message: `I want to ask questions about the \`${mockCollectionItem.databaseName}\` database's \`${mockCollectionItem.collectionName}\` collection.`,
isNewChat: true,
},
]);

expect(sendMessageToParticipantStub.getCall(1).args).deep.equals([
{
message: '',
isPartialQuery: true,
},
]);
});
});
});

suite('determining the namespace', function () {
['query', 'schema'].forEach(function (command) {
suite(`${command} command`, function () {
Expand Down

0 comments on commit 93fb8f8

Please sign in to comment.