Path: blob/main/src/vs/workbench/test/browser/notificationsPosition.test.ts
13397 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import { TestConfigurationService } from '../../../platform/configuration/test/common/testConfigurationService.js';7import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../base/test/common/utils.js';8import { DEFAULT_CUSTOM_TITLEBAR_HEIGHT } from '../../../platform/window/common/window.js';9import { NotificationsPosition, NotificationsSettings } from '../../common/notifications.js';10import { Codicon } from '../../../base/common/codicons.js';11import { hideIcon, hideUpIcon, getNotificationExpandIcon, getNotificationCollapseIcon } from '../../browser/parts/notifications/notificationsActions.js';1213suite('Notifications Position', () => {1415ensureNoDisposablesAreLeakedInTestSuite();1617suite('Configuration', () => {1819test('defaults to bottom-right when no configuration is set', () => {20const configurationService = new TestConfigurationService();21const position = configurationService.getValue<NotificationsPosition>(NotificationsSettings.NOTIFICATIONS_POSITION) ?? NotificationsPosition.BOTTOM_RIGHT;22assert.strictEqual(position, NotificationsPosition.BOTTOM_RIGHT);23});2425test('returns bottom-left when configured', async () => {26const configurationService = new TestConfigurationService();27await configurationService.setUserConfiguration(NotificationsSettings.NOTIFICATIONS_POSITION, NotificationsPosition.BOTTOM_LEFT);28const position = configurationService.getValue<NotificationsPosition>(NotificationsSettings.NOTIFICATIONS_POSITION);29assert.strictEqual(position, NotificationsPosition.BOTTOM_LEFT);30});3132test('returns top-right when configured', async () => {33const configurationService = new TestConfigurationService();34await configurationService.setUserConfiguration(NotificationsSettings.NOTIFICATIONS_POSITION, NotificationsPosition.TOP_RIGHT);35const position = configurationService.getValue<NotificationsPosition>(NotificationsSettings.NOTIFICATIONS_POSITION);36assert.strictEqual(position, NotificationsPosition.TOP_RIGHT);37});3839test('returns bottom-right when configured', async () => {40const configurationService = new TestConfigurationService();41await configurationService.setUserConfiguration(NotificationsSettings.NOTIFICATIONS_POSITION, NotificationsPosition.BOTTOM_RIGHT);42const position = configurationService.getValue<NotificationsPosition>(NotificationsSettings.NOTIFICATIONS_POSITION);43assert.strictEqual(position, NotificationsPosition.BOTTOM_RIGHT);44});45});4647suite('Status Bar Alignment', () => {4849function getDesiredAlignment(position: NotificationsPosition): 'left' | 'right' | 'hidden' {50switch (position) {51case NotificationsPosition.BOTTOM_LEFT:52return 'left';53case NotificationsPosition.TOP_RIGHT:54return 'hidden'; // bell is in titlebar instead55case NotificationsPosition.BOTTOM_RIGHT:56default:57return 'right';58}59}6061test('bottom-right position aligns bell to right', () => {62assert.strictEqual(getDesiredAlignment(NotificationsPosition.BOTTOM_RIGHT), 'right');63});6465test('bottom-left position aligns bell to left', () => {66assert.strictEqual(getDesiredAlignment(NotificationsPosition.BOTTOM_LEFT), 'left');67});6869test('top-right position hides status bar bell', () => {70assert.strictEqual(getDesiredAlignment(NotificationsPosition.TOP_RIGHT), 'hidden');71});72});7374suite('Top Offset for Top-Right', () => {7576function computeTopOffset(position: NotificationsPosition, titleBarVisible: boolean): number | undefined {77if (position !== NotificationsPosition.TOP_RIGHT) {78return undefined;79}80let topOffset = 7;81if (titleBarVisible) {82topOffset += DEFAULT_CUSTOM_TITLEBAR_HEIGHT;83}84return topOffset;85}8687test('bottom-right has no top offset', () => {88assert.strictEqual(computeTopOffset(NotificationsPosition.BOTTOM_RIGHT, true), undefined);89});9091test('bottom-left has no top offset', () => {92assert.strictEqual(computeTopOffset(NotificationsPosition.BOTTOM_LEFT, true), undefined);93});9495test('top-right without titlebar has 7px offset', () => {96assert.strictEqual(computeTopOffset(NotificationsPosition.TOP_RIGHT, false), 7);97});9899test('top-right with titlebar has 42px offset', () => {100assert.strictEqual(computeTopOffset(NotificationsPosition.TOP_RIGHT, true), 42);101});102});103104suite('NotificationsPosition Enum Values', () => {105106test('enum values match expected strings', () => {107assert.strictEqual(NotificationsPosition.BOTTOM_RIGHT, 'bottom-right');108assert.strictEqual(NotificationsPosition.BOTTOM_LEFT, 'bottom-left');109assert.strictEqual(NotificationsPosition.TOP_RIGHT, 'top-right');110});111112test('setting key is correct', () => {113assert.strictEqual(NotificationsSettings.NOTIFICATIONS_POSITION, 'workbench.notifications.position');114});115116test('button setting key is correct', () => {117assert.strictEqual(NotificationsSettings.NOTIFICATIONS_BUTTON, 'workbench.notifications.showInTitleBar');118});119});120121suite('Hide Notifications Icon', () => {122123function getHideIcon(position: NotificationsPosition) {124return position === NotificationsPosition.TOP_RIGHT ? hideUpIcon : hideIcon;125}126127test('bottom-right uses chevron down icon', () => {128assert.strictEqual(getHideIcon(NotificationsPosition.BOTTOM_RIGHT).id, hideIcon.id);129});130131test('bottom-left uses chevron down icon', () => {132assert.strictEqual(getHideIcon(NotificationsPosition.BOTTOM_LEFT).id, hideIcon.id);133});134135test('top-right uses chevron up icon', () => {136assert.strictEqual(getHideIcon(NotificationsPosition.TOP_RIGHT).id, hideUpIcon.id);137});138139test('hide icon defaults use correct codicons', () => {140assert.strictEqual(Codicon.chevronDown.id, 'chevron-down');141assert.strictEqual(Codicon.chevronUp.id, 'chevron-up');142});143});144145suite('Expand/Collapse Notification Icons', () => {146147test('bottom-right expand uses notifications-expand icon', () => {148assert.strictEqual(getNotificationExpandIcon(NotificationsPosition.BOTTOM_RIGHT).id, 'notifications-expand');149});150151test('bottom-left expand uses notifications-expand icon', () => {152assert.strictEqual(getNotificationExpandIcon(NotificationsPosition.BOTTOM_LEFT).id, 'notifications-expand');153});154155test('top-right expand uses notifications-expand-down icon', () => {156assert.strictEqual(getNotificationExpandIcon(NotificationsPosition.TOP_RIGHT).id, 'notifications-expand-down');157});158159test('bottom-right collapse uses notifications-collapse icon', () => {160assert.strictEqual(getNotificationCollapseIcon(NotificationsPosition.BOTTOM_RIGHT).id, 'notifications-collapse');161});162163test('bottom-left collapse uses notifications-collapse icon', () => {164assert.strictEqual(getNotificationCollapseIcon(NotificationsPosition.BOTTOM_LEFT).id, 'notifications-collapse');165});166167test('top-right collapse uses notifications-collapse-up icon', () => {168assert.strictEqual(getNotificationCollapseIcon(NotificationsPosition.TOP_RIGHT).id, 'notifications-collapse-up');169});170});171});172173174