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 { default as assert } from 'assert' ;
7+
8+ // Test the text truncation logic that should be applied to tree view button text
9+ describe ( 'CompareChangesTreeDataProvider text truncation' , ( ) => {
10+ const MAX_BUTTON_TEXT_LENGTH = 40 ; // Same constant used in implementation
11+
12+ function truncateButtonText ( buttonText : string ) : string {
13+ return buttonText . length > MAX_BUTTON_TEXT_LENGTH
14+ ? buttonText . substring ( 0 , MAX_BUTTON_TEXT_LENGTH - 3 ) + '...'
15+ : buttonText ;
16+ }
17+
18+ describe ( 'button text truncation' , ( ) => {
19+ it ( 'should truncate long button text with ellipsis' , ( ) => {
20+ const longButtonText = '$(sparkle) Very Long Copilot Reviewer Name That Would Cause Overflow Issues Code Review' ;
21+ const result = truncateButtonText ( longButtonText ) ;
22+
23+ assert . strictEqual ( result . length , MAX_BUTTON_TEXT_LENGTH ) ;
24+ assert . ok ( result . endsWith ( '...' ) ) ;
25+ assert . ok ( result . includes ( '$(sparkle)' ) ) ;
26+ assert . ok ( ! result . includes ( 'Overflow Issues Code Review' ) ) ;
27+ } ) ;
28+
29+ it ( 'should not truncate short button text' , ( ) => {
30+ const shortButtonText = '$(sparkle) Copilot Code Review' ;
31+ const result = truncateButtonText ( shortButtonText ) ;
32+
33+ assert . strictEqual ( result , shortButtonText ) ;
34+ assert . ok ( ! result . includes ( '...' ) ) ;
35+ } ) ;
36+
37+ it ( 'should handle exactly max length text' , ( ) => {
38+ const exactLengthText = 'A' . repeat ( MAX_BUTTON_TEXT_LENGTH ) ;
39+ const result = truncateButtonText ( exactLengthText ) ;
40+
41+ assert . strictEqual ( result , exactLengthText ) ;
42+ assert . ok ( ! result . includes ( '...' ) ) ;
43+ } ) ;
44+
45+ it ( 'should handle text that is one character over the limit' , ( ) => {
46+ const overLimitByOne = 'A' . repeat ( MAX_BUTTON_TEXT_LENGTH + 1 ) ;
47+ const result = truncateButtonText ( overLimitByOne ) ;
48+
49+ assert . strictEqual ( result . length , MAX_BUTTON_TEXT_LENGTH ) ;
50+ assert . ok ( result . endsWith ( '...' ) ) ;
51+ assert . strictEqual ( result , 'A' . repeat ( MAX_BUTTON_TEXT_LENGTH - 3 ) + '...' ) ;
52+ } ) ;
53+
54+ it ( 'should preserve sparkle icon in truncated text' , ( ) => {
55+ const longTextWithIcon = '$(sparkle) ' + 'Very ' . repeat ( 20 ) + 'Long Code Review' ;
56+ const result = truncateButtonText ( longTextWithIcon ) ;
57+
58+ assert . ok ( result . startsWith ( '$(sparkle)' ) ) ;
59+ assert . ok ( result . endsWith ( '...' ) ) ;
60+ assert . strictEqual ( result . length , MAX_BUTTON_TEXT_LENGTH ) ;
61+ } ) ;
62+ } ) ;
63+ } ) ;
0 commit comments