Path: blob/main/src/vs/sessions/contrib/accountMenu/test/browser/accountTitleBarState.test.ts
13405 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 { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';7import { ChatEntitlement } from '../../../../../workbench/services/chat/common/chatEntitlementService.js';8import { getAccountProfileImageUrl, getAccountTitleBarBadgeKey, getAccountTitleBarState, IAccountTitleBarStateContext } from '../../../../browser/accountTitleBarState.js';910suite('Sessions - Account Title Bar State', () => {1112ensureNoDisposablesAreLeakedInTestSuite();1314function createState(overrides: Partial<IAccountTitleBarStateContext> = {}): IAccountTitleBarStateContext {15return {16isAccountLoading: false,17accountName: '[email protected]',18accountProviderLabel: 'GitHub',19entitlement: ChatEntitlement.Pro,20sentiment: {},21quotas: {},22...overrides,23};24}2526test('shows low token badge for Copilot Free users', () => {27const state = getAccountTitleBarState(createState({28entitlement: ChatEntitlement.Free,29quotas: { chat: { percentRemaining: 10, unlimited: false } },30}));3132assert.deepStrictEqual({33source: state.source,34label: state.label,35badge: state.badge,36dotBadge: state.dotBadge,37kind: state.kind,38}, {39source: 'copilot',40label: 'Tokens Remaining',41badge: '10%',42dotBadge: 'error',43kind: 'warning',44});4546assert.strictEqual(getAccountTitleBarBadgeKey(state), 'copilot:error:10%');47});4849test('shows warning dot badge for low but non-critical tokens', () => {50const state = getAccountTitleBarState(createState({51entitlement: ChatEntitlement.Free,52quotas: { chat: { percentRemaining: 20, unlimited: false } },53}));5455assert.deepStrictEqual({56source: state.source,57label: state.label,58badge: state.badge,59dotBadge: state.dotBadge,60kind: state.kind,61}, {62source: 'copilot',63label: 'Tokens Remaining',64badge: '20%',65dotBadge: 'warning',66kind: 'accent',67});68});6970test('shows quota reached warning when free quota is exhausted', () => {71const state = getAccountTitleBarState(createState({72entitlement: ChatEntitlement.Free,73quotas: { completions: { percentRemaining: 0, unlimited: false } },74}));7576assert.deepStrictEqual({77source: state.source,78label: state.label,79dotBadge: state.dotBadge,80kind: state.kind,81}, {82source: 'copilot',83label: 'Quota Reached',84dotBadge: 'error',85kind: 'warning',86});8788assert.strictEqual(getAccountTitleBarBadgeKey(state), 'copilot:error:');89});9091test('falls back to signed-in account label when no higher-priority state exists', () => {92const state = getAccountTitleBarState(createState());9394assert.deepStrictEqual({95source: state.source,96label: state.label,97kind: state.kind,98revealLabelOnHover: state.revealLabelOnHover,99}, {100source: 'account',101label: '[email protected]',102kind: 'default',103revealLabelOnHover: true,104});105});106107test('reveals loading account label only on hover', () => {108const state = getAccountTitleBarState(createState({109isAccountLoading: true,110accountName: undefined,111accountProviderLabel: undefined,112entitlement: ChatEntitlement.Unknown,113}));114115assert.deepStrictEqual({116source: state.source,117label: state.label,118kind: state.kind,119revealLabelOnHover: state.revealLabelOnHover,120}, {121source: 'account',122label: 'Loading Account...',123kind: 'default',124revealLabelOnHover: true,125});126});127128test('shows sign in state when no account is available', () => {129const state = getAccountTitleBarState(createState({130accountName: undefined,131accountProviderLabel: undefined,132entitlement: ChatEntitlement.Unknown,133}));134135assert.deepStrictEqual({136source: state.source,137label: state.label,138kind: state.kind,139}, {140source: 'copilot',141label: 'Agents Signed Out',142kind: 'prominent',143});144});145146test('returns a GitHub profile image URL for GitHub accounts', () => {147assert.strictEqual(148getAccountProfileImageUrl('github', 'mona lisa'),149'https://github.com/mona%20lisa.png?size=64'150);151});152153test('falls back to the codicon when no GitHub profile image URL is available', () => {154assert.strictEqual(getAccountProfileImageUrl(undefined, 'octocat'), undefined);155assert.strictEqual(getAccountProfileImageUrl('github-enterprise', 'octocat'), undefined);156assert.strictEqual(getAccountProfileImageUrl('github', undefined), undefined);157});158});159160161