Skip to content

Commit

Permalink
test: add first status bar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
senyai committed Nov 25, 2024
1 parent 1c67fba commit 6672958
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/test/suite/commandSuites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export function StatusSuite(this: Suite): void {
const execStub = getExecStub(this.ctx.sandbox);
const status = fakeFossilStatus(execStub, 'EXTRA refresh.txt\n');
const branch = fakeFossilBranch(execStub, 'refresh');
const changes = fakeFossilChanges(execStub, '12 changes');
const changes = fakeFossilChanges(execStub, '12 files modified.');
await commands.executeCommand('fossil.refresh');
sinon.assert.calledThrice(execStub);
sinon.assert.calledOnce(status);
Expand Down
14 changes: 12 additions & 2 deletions src/test/suite/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,18 @@ export function fakeFossilStatus(execStub: ExecStub, status: string): ExecStub {
.resolves(fakeExecutionResult({ stdout: header + status, args }));
}

export function fakeFossilBranch(execStub: ExecStub, branch: string): ExecStub {
export function fakeFossilBranch(
execStub: ExecStub,
branch: 'refresh'
): ExecStub {
return execStub
.withArgs(['branch', 'current'])
.resolves(fakeExecutionResult({ stdout: branch }));
}

export function fakeFossilChanges(
execStub: ExecStub,
changes: string
changes: `${number} files modified.` | 'None. Already up-to-date'
): ExecStub {
return execStub
.withArgs(['update', '--dry-run', '--latest'])
Expand Down Expand Up @@ -380,3 +383,10 @@ export function assertGroups(
message
);
}

export function statusBarCommands() {
const repository = getRepository();
const commands = repository.sourceControl.statusBarCommands;
assert.ok(commands);
return commands;
}
56 changes: 56 additions & 0 deletions src/test/suite/stateSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import {
assertGroups,
cleanupFossil,
fakeExecutionResult,
fakeFossilChanges,
fakeFossilStatus,
getExecStub,
getRepository,
statusBarCommands,
} from './common';
import * as assert from 'assert/strict';
import * as fs from 'fs/promises';
Expand Down Expand Up @@ -148,8 +150,62 @@ function PullAndPushSuite(this: Suite): void {
});
}

export function StatusBarSuite(this: Suite): void {
let fakeTimers: sinon.SinonFakeTimers;
const N = new Date('2024-11-23T16:51:31.000Z');

before(() => {
fakeTimers = sinon.useFakeTimers({
now: N,
shouldClearNativeTimers: true,
});
});

after(() => {
fakeTimers.restore();
});

test('Status Bar Exists', async () => {
const [branchBar, syncBar] = statusBarCommands();
assert.equal(branchBar.command, 'fossil.branchChange');
assert.equal(branchBar.title, '$(git-branch) trunk');
assert.equal(branchBar.tooltip?.split('\n').pop(), 'Change Branch...');
assert.deepEqual(branchBar.arguments, [getRepository()]);
assert.equal(syncBar.command, 'fossil.update');
assert.equal(syncBar.title, '$(sync)');
assert.match(
syncBar.tooltip!,
/^None. Already up-to-date\nNext sync \d\d:\d\d:\d\d\nUpdate$/
);
assert.deepEqual(syncBar.arguments, [getRepository()]);
});

test('Sync', async () => {
const execStub = getExecStub(this.ctx.sandbox);
const syncCall = execStub.withArgs(['sync']).resolves();
const changesCall = fakeFossilChanges(execStub, '18 files modified.');
await commands.executeCommand('fossil.sync');
sinon.assert.calledOnceWithExactly(syncCall, ['sync'], undefined, {
logErrors: true,
});
sinon.assert.calledOnceWithExactly(
changesCall,
['update', '--dry-run', '--latest'],
'sync happened' as Reason,
{ logErrors: false }
);
const syncBar = statusBarCommands()[1];
assert.equal(syncBar.title, '$(sync) 18');
assert.equal(
syncBar.tooltip,
'18 files modified.\nNext sync 19:54:31\nUpdate'
);
});
}

export function UpdateSuite(this: Suite): void {
suite('Pull and Push', PullAndPushSuite);
suite('Status Bar', StatusBarSuite);

test('Change branch to trunk', async () => {
const execStub = getExecStub(this.ctx.sandbox);
Expand Down

0 comments on commit 6672958

Please sign in to comment.