Files
openchamber/packages/vscode/src/bridge-git-runtime.test.js
T
Paolo InsognaandBohdan Triapitsyn e16097b05d feat: Redesign git changes to split stage/unstaged files. (#1359)
* feat: Redesign git changes to split stage/unstaged files.

Signed-off-by: Paolo Insogna <paolo@cowtech.it>

* fixup

Signed-off-by: Paolo Insogna <paolo@cowtech.it>

* fixup

Signed-off-by: Paolo Insogna <paolo@cowtech.it>

* refactor: streamline git changes panel

* fix: label staged and working diff tabs

* fix: isolate staged and working diff files

* fix: scope staged and working diff updates

* fix: scope git row revert to working changes

---------

Signed-off-by: Paolo Insogna <paolo@cowtech.it>
Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
2026-05-24 00:49:38 +03:00

73 lines
2.3 KiB
JavaScript

import { beforeEach, describe, expect, it, mock } from 'bun:test';
const gitService = {
stageGitFiles: mock(),
unstageGitFiles: mock(),
};
mock.module('./gitService', () => gitService);
const { handleStandardGitBridgeMessage } = await import('./bridge-git-runtime');
describe('bridge git runtime index mutations', () => {
beforeEach(() => {
gitService.stageGitFiles.mockReset();
gitService.unstageGitFiles.mockReset();
});
it('accepts legacy stage path payloads', async () => {
const response = await handleStandardGitBridgeMessage({
id: '1',
type: 'api:git/stage',
payload: { directory: '/repo', path: 'a.ts' },
});
expect(response).toEqual({ id: '1', type: 'api:git/stage', success: true, data: { success: true } });
expect(gitService.stageGitFiles).toHaveBeenCalledWith('/repo', ['a.ts']);
});
it('accepts bulk stage paths payloads', async () => {
const response = await handleStandardGitBridgeMessage({
id: '1',
type: 'api:git/stage',
payload: { directory: '/repo', paths: ['a.ts', 'b.ts'] },
});
expect(response?.success).toBe(true);
expect(gitService.stageGitFiles).toHaveBeenCalledWith('/repo', ['a.ts', 'b.ts']);
});
it('accepts legacy unstage path payloads', async () => {
const response = await handleStandardGitBridgeMessage({
id: '1',
type: 'api:git/unstage',
payload: { directory: '/repo', path: 'a.ts' },
});
expect(response).toEqual({ id: '1', type: 'api:git/unstage', success: true, data: { success: true } });
expect(gitService.unstageGitFiles).toHaveBeenCalledWith('/repo', ['a.ts']);
});
it('accepts bulk unstage paths payloads', async () => {
const response = await handleStandardGitBridgeMessage({
id: '1',
type: 'api:git/unstage',
payload: { directory: '/repo', paths: ['a.ts', 'b.ts'] },
});
expect(response?.success).toBe(true);
expect(gitService.unstageGitFiles).toHaveBeenCalledWith('/repo', ['a.ts', 'b.ts']);
});
it('rejects invalid path payloads', async () => {
const response = await handleStandardGitBridgeMessage({
id: '1',
type: 'api:git/stage',
payload: { directory: '/repo', paths: [' ', null] },
});
expect(response?.success).toBe(false);
expect(gitService.stageGitFiles).not.toHaveBeenCalled();
});
});