Skip to content

Commit

Permalink
fix: Fix tests for openReferenceBeside
Browse files Browse the repository at this point in the history
  • Loading branch information
ez4gis committed Jan 20, 2021
1 parent c1d3066 commit 1050a94
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/commands/openReferenceBeside.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import {
openTextDocument,
rndName,
toPlainObject,
waitForExpect,
} from '../test/testUtils';

describe('openReferenceBeside command', () => {
beforeEach(closeEditorsAndCleanWorkspace);
afterEach(closeEditorsAndCleanWorkspace);

it('should call open command-line tool when editor selection is within the reference', async () => {
it('should execute vscode.open when editor selection is within the reference', async () => {
const executeCommandSpy = jest.spyOn(commands, 'executeCommand');

const name0 = rndName();
Expand All @@ -39,14 +40,14 @@ describe('openReferenceBeside command', () => {
path: expect.toEndWith(`${name0}.md`),
scheme: 'file',
}),
-2, // ViewColumn.Beside
ViewColumn.Beside,
],
]);

executeCommandSpy.mockRestore();
});

it('should NOT call open command-line tool when editor selection is outside of the reference', async () => {
it('should NOT execute vscode.open when editor selection is outside of the reference', async () => {
const executeCommandSpy = jest.spyOn(commands, 'executeCommand');

const name0 = rndName();
Expand Down Expand Up @@ -74,22 +75,19 @@ describe('openReferenceBeside command', () => {
const name1 = rndName();

await createFile(`${name0}.md`);
await createFile(`${name1}.md`, `[[${name0}.md]]`);
await createFile(`${name1}.md`, `[[${name0}]]`);

const doc = await openTextDocument(`${name1}.md`);
const editor = await window.showTextDocument(doc);

editor.selection = new Selection(0, 2, 0, 2);

expect(window.activeTextEditor === editor).toBeTrue();
expect(window.activeTextEditor!.viewColumn === ViewColumn.One).toBeTrue();

await openReferenceBeside();

console.log('visibleTextEditors.length', window.visibleTextEditors.length);
console.log('activeTextEditor.viewColumn', window.activeTextEditor?.viewColumn);
console.log('activeTextEditor.document.filename', window.activeTextEditor?.document.fileName);
// TODO: openReferenceBeside appears to work in vscode,
// but the following checks in testing script always fail!:(
expect(window.visibleTextEditors.length === 2).toBeTrue();
await waitForExpect(() => expect(window.visibleTextEditors.length === 2).toBeTrue());
expect(window.activeTextEditor!.viewColumn === ViewColumn.Two).toBeTrue();
});
});

0 comments on commit 1050a94

Please sign in to comment.