Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/test/browser/notificationsPosition.test.ts
13397 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 { TestConfigurationService } from '../../../platform/configuration/test/common/testConfigurationService.js';
8
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../base/test/common/utils.js';
9
import { DEFAULT_CUSTOM_TITLEBAR_HEIGHT } from '../../../platform/window/common/window.js';
10
import { NotificationsPosition, NotificationsSettings } from '../../common/notifications.js';
11
import { Codicon } from '../../../base/common/codicons.js';
12
import { hideIcon, hideUpIcon, getNotificationExpandIcon, getNotificationCollapseIcon } from '../../browser/parts/notifications/notificationsActions.js';
13
14
suite('Notifications Position', () => {
15
16
ensureNoDisposablesAreLeakedInTestSuite();
17
18
suite('Configuration', () => {
19
20
test('defaults to bottom-right when no configuration is set', () => {
21
const configurationService = new TestConfigurationService();
22
const position = configurationService.getValue<NotificationsPosition>(NotificationsSettings.NOTIFICATIONS_POSITION) ?? NotificationsPosition.BOTTOM_RIGHT;
23
assert.strictEqual(position, NotificationsPosition.BOTTOM_RIGHT);
24
});
25
26
test('returns bottom-left when configured', async () => {
27
const configurationService = new TestConfigurationService();
28
await configurationService.setUserConfiguration(NotificationsSettings.NOTIFICATIONS_POSITION, NotificationsPosition.BOTTOM_LEFT);
29
const position = configurationService.getValue<NotificationsPosition>(NotificationsSettings.NOTIFICATIONS_POSITION);
30
assert.strictEqual(position, NotificationsPosition.BOTTOM_LEFT);
31
});
32
33
test('returns top-right when configured', async () => {
34
const configurationService = new TestConfigurationService();
35
await configurationService.setUserConfiguration(NotificationsSettings.NOTIFICATIONS_POSITION, NotificationsPosition.TOP_RIGHT);
36
const position = configurationService.getValue<NotificationsPosition>(NotificationsSettings.NOTIFICATIONS_POSITION);
37
assert.strictEqual(position, NotificationsPosition.TOP_RIGHT);
38
});
39
40
test('returns bottom-right when configured', async () => {
41
const configurationService = new TestConfigurationService();
42
await configurationService.setUserConfiguration(NotificationsSettings.NOTIFICATIONS_POSITION, NotificationsPosition.BOTTOM_RIGHT);
43
const position = configurationService.getValue<NotificationsPosition>(NotificationsSettings.NOTIFICATIONS_POSITION);
44
assert.strictEqual(position, NotificationsPosition.BOTTOM_RIGHT);
45
});
46
});
47
48
suite('Status Bar Alignment', () => {
49
50
function getDesiredAlignment(position: NotificationsPosition): 'left' | 'right' | 'hidden' {
51
switch (position) {
52
case NotificationsPosition.BOTTOM_LEFT:
53
return 'left';
54
case NotificationsPosition.TOP_RIGHT:
55
return 'hidden'; // bell is in titlebar instead
56
case NotificationsPosition.BOTTOM_RIGHT:
57
default:
58
return 'right';
59
}
60
}
61
62
test('bottom-right position aligns bell to right', () => {
63
assert.strictEqual(getDesiredAlignment(NotificationsPosition.BOTTOM_RIGHT), 'right');
64
});
65
66
test('bottom-left position aligns bell to left', () => {
67
assert.strictEqual(getDesiredAlignment(NotificationsPosition.BOTTOM_LEFT), 'left');
68
});
69
70
test('top-right position hides status bar bell', () => {
71
assert.strictEqual(getDesiredAlignment(NotificationsPosition.TOP_RIGHT), 'hidden');
72
});
73
});
74
75
suite('Top Offset for Top-Right', () => {
76
77
function computeTopOffset(position: NotificationsPosition, titleBarVisible: boolean): number | undefined {
78
if (position !== NotificationsPosition.TOP_RIGHT) {
79
return undefined;
80
}
81
let topOffset = 7;
82
if (titleBarVisible) {
83
topOffset += DEFAULT_CUSTOM_TITLEBAR_HEIGHT;
84
}
85
return topOffset;
86
}
87
88
test('bottom-right has no top offset', () => {
89
assert.strictEqual(computeTopOffset(NotificationsPosition.BOTTOM_RIGHT, true), undefined);
90
});
91
92
test('bottom-left has no top offset', () => {
93
assert.strictEqual(computeTopOffset(NotificationsPosition.BOTTOM_LEFT, true), undefined);
94
});
95
96
test('top-right without titlebar has 7px offset', () => {
97
assert.strictEqual(computeTopOffset(NotificationsPosition.TOP_RIGHT, false), 7);
98
});
99
100
test('top-right with titlebar has 42px offset', () => {
101
assert.strictEqual(computeTopOffset(NotificationsPosition.TOP_RIGHT, true), 42);
102
});
103
});
104
105
suite('NotificationsPosition Enum Values', () => {
106
107
test('enum values match expected strings', () => {
108
assert.strictEqual(NotificationsPosition.BOTTOM_RIGHT, 'bottom-right');
109
assert.strictEqual(NotificationsPosition.BOTTOM_LEFT, 'bottom-left');
110
assert.strictEqual(NotificationsPosition.TOP_RIGHT, 'top-right');
111
});
112
113
test('setting key is correct', () => {
114
assert.strictEqual(NotificationsSettings.NOTIFICATIONS_POSITION, 'workbench.notifications.position');
115
});
116
117
test('button setting key is correct', () => {
118
assert.strictEqual(NotificationsSettings.NOTIFICATIONS_BUTTON, 'workbench.notifications.showInTitleBar');
119
});
120
});
121
122
suite('Hide Notifications Icon', () => {
123
124
function getHideIcon(position: NotificationsPosition) {
125
return position === NotificationsPosition.TOP_RIGHT ? hideUpIcon : hideIcon;
126
}
127
128
test('bottom-right uses chevron down icon', () => {
129
assert.strictEqual(getHideIcon(NotificationsPosition.BOTTOM_RIGHT).id, hideIcon.id);
130
});
131
132
test('bottom-left uses chevron down icon', () => {
133
assert.strictEqual(getHideIcon(NotificationsPosition.BOTTOM_LEFT).id, hideIcon.id);
134
});
135
136
test('top-right uses chevron up icon', () => {
137
assert.strictEqual(getHideIcon(NotificationsPosition.TOP_RIGHT).id, hideUpIcon.id);
138
});
139
140
test('hide icon defaults use correct codicons', () => {
141
assert.strictEqual(Codicon.chevronDown.id, 'chevron-down');
142
assert.strictEqual(Codicon.chevronUp.id, 'chevron-up');
143
});
144
});
145
146
suite('Expand/Collapse Notification Icons', () => {
147
148
test('bottom-right expand uses notifications-expand icon', () => {
149
assert.strictEqual(getNotificationExpandIcon(NotificationsPosition.BOTTOM_RIGHT).id, 'notifications-expand');
150
});
151
152
test('bottom-left expand uses notifications-expand icon', () => {
153
assert.strictEqual(getNotificationExpandIcon(NotificationsPosition.BOTTOM_LEFT).id, 'notifications-expand');
154
});
155
156
test('top-right expand uses notifications-expand-down icon', () => {
157
assert.strictEqual(getNotificationExpandIcon(NotificationsPosition.TOP_RIGHT).id, 'notifications-expand-down');
158
});
159
160
test('bottom-right collapse uses notifications-collapse icon', () => {
161
assert.strictEqual(getNotificationCollapseIcon(NotificationsPosition.BOTTOM_RIGHT).id, 'notifications-collapse');
162
});
163
164
test('bottom-left collapse uses notifications-collapse icon', () => {
165
assert.strictEqual(getNotificationCollapseIcon(NotificationsPosition.BOTTOM_LEFT).id, 'notifications-collapse');
166
});
167
168
test('top-right collapse uses notifications-collapse-up icon', () => {
169
assert.strictEqual(getNotificationCollapseIcon(NotificationsPosition.TOP_RIGHT).id, 'notifications-collapse-up');
170
});
171
});
172
});
173
174