Conversation
WalkthroughThe pull request adds a single new line to the Changes
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
README.md (1)
41-42: New Line Addition in README.md
The new line "Code rabbit" has been appended at the end as intended. Please verify that this placement and formatting meet your branding or messaging objectives; if additional emphasis is desired, consider using markdown formatting (e.g., a header or bold text).
|
@coderabbitai generate unit testing code for this file |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 1798 🏁 Script executed: Length of output: 3046 @BharathRavi27 Based on the code I examined, I'll generate unit tests for the VS Code extension. Here are comprehensive tests for both commands: import * as assert from 'assert';
import * as sinon from 'sinon';
import * as vscode from 'vscode';
import { switchDisposable, switchSpecDisposable } from '../../disposables';
suite('Extension Test Suite', () => {
let sandbox: sinon.SinonSandbox;
let openTextDocumentStub: sinon.SinonStub;
let showTextDocumentStub: sinon.SinonStub;
let showWarningMessageStub: sinon.SinonStub;
let activeTextEditorStub: sinon.SinonStub;
const mockDocument = {
uri: {
fsPath: ''
}
};
const mockEditor = {
document: mockDocument
};
const mockTextDocument = {};
setup(() => {
sandbox = sinon.createSandbox();
// Stub VS Code API calls
openTextDocumentStub = sandbox.stub(vscode.workspace, 'openTextDocument').resolves(mockTextDocument as any);
showTextDocumentStub = sandbox.stub(vscode.window, 'showTextDocument').resolves();
showWarningMessageStub = sandbox.stub(vscode.window, 'showWarningMessage');
// Initially stub with no active editor
activeTextEditorStub = sandbox.stub(vscode.window, 'activeTextEditor').value(undefined);
});
teardown(() => {
sandbox.restore();
});
suite('switchDisposable Tests', () => {
test('should switch from TS to HTML', async () => {
// Setup
mockDocument.uri.fsPath = '/path/to/my.component.ts';
activeTextEditorStub.value(mockEditor);
// Execute
await vscode.commands.executeCommand('ng-switch.switch');
// Assert
assert.strictEqual(openTextDocumentStub.calledOnce, true);
assert.strictEqual(openTextDocumentStub.firstCall.args[0].fsPath, '/path/to/my.component.html');
assert.strictEqual(showTextDocumentStub.calledOnce, true);
});
test('should switch from HTML to TS', async () => {
// Setup
mockDocument.uri.fsPath = '/path/to/my.component.html';
activeTextEditorStub.value(mockEditor);
// Execute
await vscode.commands.executeCommand('ng-switch.switch');
// Assert
assert.strictEqual(openTextDocumentStub.calledOnce, true);
assert.strictEqual(openTextDocumentStub.firstCall.args[0].fsPath, '/path/to/my.component.ts');
assert.strictEqual(showTextDocumentStub.calledOnce, true);
});
test('should switch from CSS to HTML', async () => {
// Setup
mockDocument.uri.fsPath = '/path/to/my.component.css';
activeTextEditorStub.value(mockEditor);
// Execute
await vscode.commands.executeCommand('ng-switch.switch');
// Assert
assert.strictEqual(openTextDocumentStub.calledOnce, true);
assert.strictEqual(openTextDocumentStub.firstCall.args[0].fsPath, '/path/to/my.component.html');
assert.strictEqual(showTextDocumentStub.calledOnce, true);
});
test('should switch from SCSS to HTML', async () => {
// Setup
mockDocument.uri.fsPath = '/path/to/my.component.scss';
activeTextEditorStub.value(mockEditor);
// Execute
await vscode.commands.executeCommand('ng-switch.switch');
// Assert
assert.strictEqual(openTextDocumentStub.calledOnce, true);
assert.strictEqual(openTextDocumentStub.firstCall.args[0].fsPath, '/path/to/my.component.html');
assert.strictEqual(showTextDocumentStub.calledOnce, true);
});
test('should show warning when not in an Angular component file', async () => {
// Setup
mockDocument.uri.fsPath = '/path/to/regular-file.ts';
activeTextEditorStub.value(mockEditor);
// Execute
await vscode.commands.executeCommand('ng-switch.switch');
// Assert
assert.strictEqual(showWarningMessageStub.calledOnce, true);
assert.strictEqual(showWarningMessageStub.firstCall.args[0], 'You are probably not inside an Angular component file');
assert.strictEqual(openTextDocumentStub.called, false);
});
test('should handle empty file path', async () => {
// Setup
activeTextEditorStub.value(undefined);
// Execute
await vscode.commands.executeCommand('ng-switch.switch');
// Assert
assert.strictEqual(showWarningMessageStub.calledOnce, true);
assert.strictEqual(openTextDocumentStub.called, false);
});
});
suite('switchSpecDisposable Tests', () => {
test('should switch from TS to spec file', async () => {
// Setup
mockDocument.uri.fsPath = '/path/to/my.service.ts';
activeTextEditorStub.value(mockEditor);
// Execute
await vscode.commands.executeCommand('ng-switch.switchspec');
// Assert
assert.strictEqual(openTextDocumentStub.calledOnce, true);
assert.strictEqual(openTextDocumentStub.firstCall.args[0].fsPath, '/path/to/my.service.spec.ts');
assert.strictEqual(showTextDocumentStub.calledOnce, true);
});
test('should switch from spec file to TS', async () => {
// Setup
mockDocument.uri.fsPath = '/path/to/my.service.spec.ts';
activeTextEditorStub.value(mockEditor);
// Execute
await vscode.commands.executeCommand('ng-switch.switchspec');
// Assert
assert.strictEqual(openTextDocumentStub.calledOnce, true);
assert.strictEqual(openTextDocumentStub.firstCall.args[0].fsPath, '/path/to/my.service.ts');
assert.strictEqual(showTextDocumentStub.calledOnce, true);
});
test('should handle empty file path', async () => {
// Setup
activeTextEditorStub.value(undefined);
// Execute
await vscode.commands.executeCommand('ng-switch.switchspec');
// Assert
assert.strictEqual(openTextDocumentStub.called, false);
});
});
});You'll need to install the npm install --save-dev sinon @types/sinonThis test suite covers:
Let me know if you need any adjustments or have questions about the implementation! |
Summary by CodeRabbit