Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/test/browser/notificationsList.test.ts
4778 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 { NotificationAccessibilityProvider } from '../../browser/parts/notifications/notificationsList.js';
8
import { NotificationViewItem, INotificationsFilter, INotificationViewItem } from '../../common/notifications.js';
9
import { Severity, NotificationsFilter } from '../../../platform/notification/common/notification.js';
10
import { IKeybindingService } from '../../../platform/keybinding/common/keybinding.js';
11
import { IConfigurationService } from '../../../platform/configuration/common/configuration.js';
12
import { TestConfigurationService } from '../../../platform/configuration/test/common/testConfigurationService.js';
13
import { MockKeybindingService } from '../../../platform/keybinding/test/common/mockKeybindingService.js';
14
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../base/test/common/utils.js';
15
16
suite('NotificationsList AccessibilityProvider', () => {
17
18
const noFilter: INotificationsFilter = { global: NotificationsFilter.OFF, sources: new Map() };
19
let configurationService: IConfigurationService;
20
let keybindingService: IKeybindingService;
21
let accessibilityProvider: NotificationAccessibilityProvider;
22
const createdNotifications: INotificationViewItem[] = [];
23
24
setup(() => {
25
configurationService = new TestConfigurationService();
26
keybindingService = new MockKeybindingService();
27
accessibilityProvider = new NotificationAccessibilityProvider({}, keybindingService, configurationService);
28
});
29
30
teardown(() => {
31
// Close all created notifications to prevent disposable leaks
32
for (const notification of createdNotifications) {
33
notification.close();
34
}
35
createdNotifications.length = 0;
36
});
37
38
ensureNoDisposablesAreLeakedInTestSuite();
39
40
test('getAriaLabel includes severity prefix for Error notifications', () => {
41
const notification = NotificationViewItem.create({ severity: Severity.Error, message: 'Something went wrong' }, noFilter)!;
42
createdNotifications.push(notification);
43
const ariaLabel = accessibilityProvider.getAriaLabel(notification);
44
45
assert.ok(ariaLabel.startsWith('Error: '), `Expected aria label to start with "Error: ", but got: ${ariaLabel}`);
46
assert.ok(ariaLabel.includes('Something went wrong'), 'Expected aria label to include original message');
47
assert.ok(ariaLabel.includes('notification'), 'Expected aria label to include "notification"');
48
});
49
50
test('getAriaLabel includes severity prefix for Warning notifications', () => {
51
const notification = NotificationViewItem.create({ severity: Severity.Warning, message: 'This is a warning' }, noFilter)!;
52
createdNotifications.push(notification);
53
const ariaLabel = accessibilityProvider.getAriaLabel(notification);
54
55
assert.ok(ariaLabel.startsWith('Warning: '), `Expected aria label to start with "Warning: ", but got: ${ariaLabel}`);
56
assert.ok(ariaLabel.includes('This is a warning'), 'Expected aria label to include original message');
57
assert.ok(ariaLabel.includes('notification'), 'Expected aria label to include "notification"');
58
});
59
60
test('getAriaLabel includes severity prefix for Info notifications', () => {
61
const notification = NotificationViewItem.create({ severity: Severity.Info, message: 'Information message' }, noFilter)!;
62
createdNotifications.push(notification);
63
const ariaLabel = accessibilityProvider.getAriaLabel(notification);
64
65
assert.ok(ariaLabel.startsWith('Info: '), `Expected aria label to start with "Info: ", but got: ${ariaLabel}`);
66
assert.ok(ariaLabel.includes('Information message'), 'Expected aria label to include original message');
67
assert.ok(ariaLabel.includes('notification'), 'Expected aria label to include "notification"');
68
});
69
70
test('getAriaLabel includes source when present', () => {
71
const notification = NotificationViewItem.create({
72
severity: Severity.Error,
73
message: 'Error with source',
74
source: 'TestExtension'
75
}, noFilter)!;
76
createdNotifications.push(notification);
77
const ariaLabel = accessibilityProvider.getAriaLabel(notification);
78
79
assert.ok(ariaLabel.startsWith('Error: '), 'Expected aria label to start with severity prefix');
80
assert.ok(ariaLabel.includes('Error with source'), 'Expected aria label to include original message');
81
assert.ok(ariaLabel.includes('source: TestExtension'), 'Expected aria label to include source information');
82
assert.ok(ariaLabel.includes('notification'), 'Expected aria label to include "notification"');
83
});
84
85
test('severity prefix consistency', () => {
86
// Test that the severity prefixes are consistent with the ARIA alerts
87
const errorNotification = NotificationViewItem.create({ severity: Severity.Error, message: 'Error message' }, noFilter)!;
88
const warningNotification = NotificationViewItem.create({ severity: Severity.Warning, message: 'Warning message' }, noFilter)!;
89
const infoNotification = NotificationViewItem.create({ severity: Severity.Info, message: 'Info message' }, noFilter)!;
90
91
createdNotifications.push(errorNotification, warningNotification, infoNotification);
92
93
const errorLabel = accessibilityProvider.getAriaLabel(errorNotification);
94
const warningLabel = accessibilityProvider.getAriaLabel(warningNotification);
95
const infoLabel = accessibilityProvider.getAriaLabel(infoNotification);
96
97
// Check that each severity type gets the correct prefix
98
assert.ok(errorLabel.includes('Error: Error message'), 'Error notifications should have Error prefix');
99
assert.ok(warningLabel.includes('Warning: Warning message'), 'Warning notifications should have Warning prefix');
100
assert.ok(infoLabel.includes('Info: Info message'), 'Info notifications should have Info prefix');
101
});
102
});
103
104