-
Notifications
You must be signed in to change notification settings - Fork 454
Expand file tree
/
Copy pathStatusBarObserver.test.ts
More file actions
142 lines (113 loc) · 5.82 KB
/
Copy pathStatusBarObserver.test.ts
File metadata and controls
142 lines (113 loc) · 5.82 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*---------------------------------------------------------------------------------------------
* Licensed to the .NET Foundation under one or more agreements.
* The .NET Foundation licenses this file to you under the MIT license.
*--------------------------------------------------------------------------------------------*/
import * as chai from 'chai';
import { DotnetInstall } from '../../Acquisition/DotnetInstall';
import {
DotnetAcquisitionCompleted,
DotnetAcquisitionFinalError,
DotnetAcquisitionStarted,
DotnetInstallCancelledByUserError,
EventBasedError,
} from '../../EventStream/EventStreamEvents';
import { StatusBarObserver } from '../../EventStream/StatusBarObserver';
const assert = chai.assert;
const defaultTimeoutTime = 5000;
class MockStatusBarItem
{
public text = '';
public command: string | undefined = undefined;
public color: string | undefined = undefined;
public tooltip: string | undefined = undefined;
public isVisible = false;
public show(): void
{
this.isVisible = true;
}
public hide(): void
{
this.isVisible = false;
}
}
const makeInstall = (id: string): DotnetInstall => ({
version: id,
isGlobal: false,
architecture: 'x64',
installId: id,
installMode: 'runtime',
});
suite('StatusBarObserver Unit Tests', function ()
{
const showLogCommand = 'dotnet.showLog';
let mockStatusBarItem: MockStatusBarItem;
let observer: StatusBarObserver;
setup(() =>
{
mockStatusBarItem = new MockStatusBarItem();
// Cast to any to avoid needing the full vscode.StatusBarItem interface
// eslint-disable-next-line @typescript-eslint/no-explicit-any
observer = new StatusBarObserver(mockStatusBarItem as any, showLogCommand);
});
test('Status bar shows when acquisition starts', () =>
{
const install = makeInstall('8.0~x64');
observer.post(new DotnetAcquisitionStarted(install, 'test-ext'));
assert.isTrue(mockStatusBarItem.isVisible, 'Status bar should be visible after acquisition starts');
assert.include(mockStatusBarItem.text, 'Downloading .NET', 'Status bar should display downloading text');
}).timeout(defaultTimeoutTime);
test('Status bar hides when single acquisition completes', () =>
{
const install = makeInstall('8.0~x64');
observer.post(new DotnetAcquisitionStarted(install, 'test-ext'));
observer.post(new DotnetAcquisitionCompleted(install, '/path/to/dotnet', '8.0'));
assert.isFalse(mockStatusBarItem.isVisible, 'Status bar should be hidden after acquisition completes');
}).timeout(defaultTimeoutTime);
test('Status bar stays visible when one of multiple concurrent downloads completes', () =>
{
const installA = makeInstall('8.0~x64');
const installB = makeInstall('9.0~x64');
observer.post(new DotnetAcquisitionStarted(installA, 'test-ext'));
observer.post(new DotnetAcquisitionStarted(installB, 'test-ext'));
// Complete the first download - status bar should remain visible because B is still in progress
observer.post(new DotnetAcquisitionCompleted(installA, '/path/to/dotnet', '8.0'));
assert.isTrue(mockStatusBarItem.isVisible, 'Status bar should remain visible while other downloads are in progress');
}).timeout(defaultTimeoutTime);
test('Status bar hides only after all concurrent downloads complete', () =>
{
const installA = makeInstall('8.0~x64');
const installB = makeInstall('9.0~x64');
observer.post(new DotnetAcquisitionStarted(installA, 'test-ext'));
observer.post(new DotnetAcquisitionStarted(installB, 'test-ext'));
observer.post(new DotnetAcquisitionCompleted(installA, '/path/to/dotnet', '8.0'));
assert.isTrue(mockStatusBarItem.isVisible, 'Status bar should remain visible after first of two downloads completes');
observer.post(new DotnetAcquisitionCompleted(installB, '/path/to/dotnet', '9.0'));
assert.isFalse(mockStatusBarItem.isVisible, 'Status bar should hide after all downloads complete');
}).timeout(defaultTimeoutTime);
test('Status bar hides when acquisition is aborted', () =>
{
const install = makeInstall('8.0~x64');
observer.post(new DotnetAcquisitionStarted(install, 'test-ext'));
const abortError = new EventBasedError('TestAbort', 'Installation cancelled');
observer.post(new DotnetInstallCancelledByUserError(abortError, install));
assert.isFalse(mockStatusBarItem.isVisible, 'Status bar should hide when acquisition is aborted');
}).timeout(defaultTimeoutTime);
test('Status bar hides when final error occurs for single download', () =>
{
const install = makeInstall('8.0~x64');
observer.post(new DotnetAcquisitionStarted(install, 'test-ext'));
const finalError = new DotnetAcquisitionFinalError(new EventBasedError('TestError', 'Download failed'), 'TestEvent', install);
observer.post(finalError);
assert.isFalse(mockStatusBarItem.isVisible, 'Status bar should hide when acquisition fails with final error');
}).timeout(defaultTimeoutTime);
test('Status bar stays visible when one of multiple concurrent downloads fails with final error', () =>
{
const installA = makeInstall('8.0~x64');
const installB = makeInstall('9.0~x64');
observer.post(new DotnetAcquisitionStarted(installA, 'test-ext'));
observer.post(new DotnetAcquisitionStarted(installB, 'test-ext'));
const finalError = new DotnetAcquisitionFinalError(new EventBasedError('TestError', 'Download failed'), 'TestEvent', installA);
observer.post(finalError);
assert.isTrue(mockStatusBarItem.isVisible, 'Status bar should remain visible when one download fails but another is still in progress');
}).timeout(defaultTimeoutTime);
});