-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcqlProject.loadState.test.ts
More file actions
78 lines (68 loc) · 2.94 KB
/
Copy pathcqlProject.loadState.test.ts
File metadata and controls
78 lines (68 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { expect } from 'chai';
import * as vscode from 'vscode';
import { Uri, workspace } from 'vscode';
import { CqlLibrary, CqlProject } from '../../../model/cqlProject';
import { CqlTestCasesLoadingTreeItem } from '../../../cql-explorer/cqlProjectTreeDataProvider';
suite('CqlLibrary — initial load state', () => {
test('CqlLibrary starts as not-loaded', () => {
const wsRoot = workspace.workspaceFolders![0].uri;
const lib = new CqlLibrary(Uri.joinPath(wsRoot, 'input/cql/SimpleMeasure.cql'));
expect(lib.testCaseLoadState).to.equal('not-loaded');
});
});
suite('CqlProject.loadTestCasesForLibrary', () => {
let project: CqlProject;
let lib: CqlLibrary;
setup(() => {
const wsRoot = workspace.workspaceFolders![0].uri;
project = new CqlProject(wsRoot.fsPath, []);
lib = new CqlLibrary(Uri.joinPath(wsRoot, 'input/cql/SimpleMeasure.cql'));
});
test('transitions from not-loaded to loaded', async () => {
expect(lib.testCaseLoadState).to.equal('not-loaded');
await project.loadTestCasesForLibrary(lib, []);
expect(lib.testCaseLoadState).to.equal('loaded');
});
test('emits LIBRARY_TESTCASES_LOADED event after load completes', async () => {
let emittedLibrary: CqlLibrary | undefined;
project.on(CqlProject.Events.LIBRARY_TESTCASES_LOADED, (l: CqlLibrary) => {
emittedLibrary = l;
});
await project.loadTestCasesForLibrary(lib, []);
expect(emittedLibrary).to.equal(lib);
});
test('is idempotent — second call when already loaded is a no-op', async () => {
await project.loadTestCasesForLibrary(lib, []);
expect(lib.testCaseLoadState).to.equal('loaded');
let eventCount = 0;
project.on(CqlProject.Events.LIBRARY_TESTCASES_LOADED, () => {
eventCount++;
});
await project.loadTestCasesForLibrary(lib, []);
expect(lib.testCaseLoadState).to.equal('loaded');
expect(eventCount).to.equal(0);
});
});
suite('CqlProject.loadResults', () => {
test('resolves without error when results folder does not exist', async () => {
const wsRoot = workspace.workspaceFolders![0].uri;
const project = new CqlProject(wsRoot.fsPath, []);
// loadResults is private; call via cast. The results folder won't exist in
// the test workspace, so the inner readdir catch fires and we return early.
// Before the fix this returned without logging; after the fix the finally
// block always logs. Either way the promise must resolve, not reject.
await (project as any).loadResults();
});
});
suite('CqlTestCasesLoadingTreeItem', () => {
test('has spinner icon', () => {
const item = new CqlTestCasesLoadingTreeItem();
const icon = item.iconPath as vscode.ThemeIcon;
expect(icon.id).to.equal('loading~spin');
});
test('has correct label and context value', () => {
const item = new CqlTestCasesLoadingTreeItem();
expect(item.label).to.equal('Loading test cases\u2026');
expect(item.contextValue).to.equal('cql-testcases-loading');
});
});