Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/sessions/contrib/accountMenu/test/browser/accountTitleBarState.test.ts
13405 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
8
import { ChatEntitlement } from '../../../../../workbench/services/chat/common/chatEntitlementService.js';
9
import { getAccountProfileImageUrl, getAccountTitleBarBadgeKey, getAccountTitleBarState, IAccountTitleBarStateContext } from '../../../../browser/accountTitleBarState.js';
10
11
suite('Sessions - Account Title Bar State', () => {
12
13
ensureNoDisposablesAreLeakedInTestSuite();
14
15
function createState(overrides: Partial<IAccountTitleBarStateContext> = {}): IAccountTitleBarStateContext {
16
return {
17
isAccountLoading: false,
18
accountName: '[email protected]',
19
accountProviderLabel: 'GitHub',
20
entitlement: ChatEntitlement.Pro,
21
sentiment: {},
22
quotas: {},
23
...overrides,
24
};
25
}
26
27
test('shows low token badge for Copilot Free users', () => {
28
const state = getAccountTitleBarState(createState({
29
entitlement: ChatEntitlement.Free,
30
quotas: { chat: { percentRemaining: 10, unlimited: false } },
31
}));
32
33
assert.deepStrictEqual({
34
source: state.source,
35
label: state.label,
36
badge: state.badge,
37
dotBadge: state.dotBadge,
38
kind: state.kind,
39
}, {
40
source: 'copilot',
41
label: 'Tokens Remaining',
42
badge: '10%',
43
dotBadge: 'error',
44
kind: 'warning',
45
});
46
47
assert.strictEqual(getAccountTitleBarBadgeKey(state), 'copilot:error:10%');
48
});
49
50
test('shows warning dot badge for low but non-critical tokens', () => {
51
const state = getAccountTitleBarState(createState({
52
entitlement: ChatEntitlement.Free,
53
quotas: { chat: { percentRemaining: 20, unlimited: false } },
54
}));
55
56
assert.deepStrictEqual({
57
source: state.source,
58
label: state.label,
59
badge: state.badge,
60
dotBadge: state.dotBadge,
61
kind: state.kind,
62
}, {
63
source: 'copilot',
64
label: 'Tokens Remaining',
65
badge: '20%',
66
dotBadge: 'warning',
67
kind: 'accent',
68
});
69
});
70
71
test('shows quota reached warning when free quota is exhausted', () => {
72
const state = getAccountTitleBarState(createState({
73
entitlement: ChatEntitlement.Free,
74
quotas: { completions: { percentRemaining: 0, unlimited: false } },
75
}));
76
77
assert.deepStrictEqual({
78
source: state.source,
79
label: state.label,
80
dotBadge: state.dotBadge,
81
kind: state.kind,
82
}, {
83
source: 'copilot',
84
label: 'Quota Reached',
85
dotBadge: 'error',
86
kind: 'warning',
87
});
88
89
assert.strictEqual(getAccountTitleBarBadgeKey(state), 'copilot:error:');
90
});
91
92
test('falls back to signed-in account label when no higher-priority state exists', () => {
93
const state = getAccountTitleBarState(createState());
94
95
assert.deepStrictEqual({
96
source: state.source,
97
label: state.label,
98
kind: state.kind,
99
revealLabelOnHover: state.revealLabelOnHover,
100
}, {
101
source: 'account',
102
label: '[email protected]',
103
kind: 'default',
104
revealLabelOnHover: true,
105
});
106
});
107
108
test('reveals loading account label only on hover', () => {
109
const state = getAccountTitleBarState(createState({
110
isAccountLoading: true,
111
accountName: undefined,
112
accountProviderLabel: undefined,
113
entitlement: ChatEntitlement.Unknown,
114
}));
115
116
assert.deepStrictEqual({
117
source: state.source,
118
label: state.label,
119
kind: state.kind,
120
revealLabelOnHover: state.revealLabelOnHover,
121
}, {
122
source: 'account',
123
label: 'Loading Account...',
124
kind: 'default',
125
revealLabelOnHover: true,
126
});
127
});
128
129
test('shows sign in state when no account is available', () => {
130
const state = getAccountTitleBarState(createState({
131
accountName: undefined,
132
accountProviderLabel: undefined,
133
entitlement: ChatEntitlement.Unknown,
134
}));
135
136
assert.deepStrictEqual({
137
source: state.source,
138
label: state.label,
139
kind: state.kind,
140
}, {
141
source: 'copilot',
142
label: 'Agents Signed Out',
143
kind: 'prominent',
144
});
145
});
146
147
test('returns a GitHub profile image URL for GitHub accounts', () => {
148
assert.strictEqual(
149
getAccountProfileImageUrl('github', 'mona lisa'),
150
'https://github.com/mona%20lisa.png?size=64'
151
);
152
});
153
154
test('falls back to the codicon when no GitHub profile image URL is available', () => {
155
assert.strictEqual(getAccountProfileImageUrl(undefined, 'octocat'), undefined);
156
assert.strictEqual(getAccountProfileImageUrl('github-enterprise', 'octocat'), undefined);
157
assert.strictEqual(getAccountProfileImageUrl('github', undefined), undefined);
158
});
159
});
160
161