DeepCodeGeniusWeb-vscode/test/context/contextCodeSelected.test.ts
bobo.yang b2bd118e33 feat: Update tests and remove deprecated tests for Claude3 integration
- Comment out mocha imports in various tests to prep for new test strategy
- Replace `before` with `beforeEach` and `after` with `afterEach` for consistency
- Remove deprecated `commandsBase.test.ts` and `dtm.test.ts` files to reflect focus on new functionality
2024-03-10 16:36:28 +08:00

43 lines
1.6 KiB
TypeScript

import { expect } from 'chai';
// import { describe, it, afterEach, beforeEach } from 'mocha';
import { handleCodeSelected } from '../../src/context/contextCodeSelected';
import * as path from 'path';
import { UiUtilWrapper } from '../../src/util/uiUtil';
import sinon from 'sinon';
describe('handleCodeSelected', () => {
let languageIdStub: sinon.SinonStub;
let workspaceFoldersFirstPathStub: sinon.SinonStub;
let writeFileStub: sinon.SinonStub;
beforeEach(() => {
// Mock UiUtilWrapper functions
languageIdStub = sinon.stub(UiUtilWrapper, 'languageId').resolves('typescript');
workspaceFoldersFirstPathStub = sinon.stub(UiUtilWrapper, 'workspaceFoldersFirstPath').returns('test');
writeFileStub = sinon.stub(UiUtilWrapper, 'writeFile').resolves();
});
afterEach(() => {
// Restore the original functions after each test
languageIdStub.restore();
workspaceFoldersFirstPathStub.restore();
writeFileStub.restore();
});
it('should create a context file with the correct content', async () => {
const fileSelected = path.join(__dirname, 'testFile.ts');
const codeSelected = 'console.log("Hello, world!");';
const contextFile = await handleCodeSelected(fileSelected, codeSelected, 0);
// Check if the mocked functions were called with the correct arguments
expect(languageIdStub.calledWith(fileSelected)).to.be.true;
expect(workspaceFoldersFirstPathStub.called).to.be.true;
expect(writeFileStub.called).to.be.true;
// Extract the temp file path from the context string
const tempFilePath = contextFile.match(/\[context\|(.*?)\]/)?.[1];
expect(tempFilePath).to.not.be.undefined;
});
});