@@ -11,6 +11,8 @@ import {
1111 TOPIC_CONTRIBUTEIONS_CHANGED ,
1212 type Contribution ,
1313 type CommandContribution ,
14+ getContributionVisible ,
15+ getContributionDisabled ,
1416} from '../../src/core/contributionregistry' ;
1517
1618describe ( 'ContributionRegistry' , ( ) => {
@@ -36,7 +38,7 @@ describe('ContributionRegistry', () => {
3638 expect ( list [ 1 ] . label ) . toBe ( 'Second' ) ;
3739 } ) ;
3840
39- it ( 'converts disabled function to Signal.Computed for CommandContribution ' , ( ) => {
41+ it ( 'converts disabled function to Signal.Computed' , ( ) => {
4042 const target = 'test-disabled-' + Math . random ( ) ;
4143 const contribution : CommandContribution = {
4244 label : 'With disabled' ,
@@ -49,7 +51,7 @@ describe('ContributionRegistry', () => {
4951 expect ( ( contribution . disabled as { get ( ) : boolean } ) . get ( ) ) . toBe ( true ) ;
5052 } ) ;
5153
52- it ( 'leaves existing Signal.Computed disabled unchanged for CommandContribution ' , ( ) => {
54+ it ( 'leaves existing Signal.Computed disabled unchanged' , ( ) => {
5355 const target = 'test-computed-' + Math . random ( ) ;
5456 const computed = new Signal . Computed ( ( ) => false ) ;
5557 const contribution : CommandContribution = {
@@ -62,6 +64,80 @@ describe('ContributionRegistry', () => {
6264 expect ( ( contribution . disabled as { get ( ) : boolean } ) . get ( ) ) . toBe ( false ) ;
6365 } ) ;
6466
67+ it ( 'getContributionVisible returns true when visible is omitted' , ( ) => {
68+ const contribution : CommandContribution = {
69+ label : 'Always visible' ,
70+ command : 'test.cmd' ,
71+ } ;
72+ expect ( getContributionVisible ( contribution ) ) . toBe ( true ) ;
73+ } ) ;
74+
75+ it ( 'getContributionVisible reflects Signal.Computed visible' , ( ) => {
76+ const contribution : CommandContribution = {
77+ label : 'Conditional' ,
78+ command : 'test.cmd' ,
79+ visible : new Signal . Computed ( ( ) => false ) ,
80+ } ;
81+ expect ( getContributionVisible ( contribution ) ) . toBe ( false ) ;
82+ } ) ;
83+
84+ it ( 'getContributionDisabled returns false when disabled is omitted' , ( ) => {
85+ const contribution : CommandContribution = {
86+ label : 'Enabled' ,
87+ command : 'test.cmd' ,
88+ } ;
89+ expect ( getContributionDisabled ( contribution ) ) . toBe ( false ) ;
90+ } ) ;
91+
92+ it ( 'getContributionDisabled reflects Signal.Computed disabled' , ( ) => {
93+ const contribution : CommandContribution = {
94+ label : 'Disabled' ,
95+ command : 'test.cmd' ,
96+ disabled : new Signal . Computed ( ( ) => true ) ,
97+ } ;
98+ expect ( getContributionDisabled ( contribution ) ) . toBe ( true ) ;
99+ } ) ;
100+
101+ it ( 'converts visible/disabled functions for any contribution' , ( ) => {
102+ const target = 'test-non-command-' + Math . random ( ) ;
103+ const contribution : Contribution = {
104+ label : 'Generic' ,
105+ visible : ( ) => false ,
106+ disabled : ( ) => true ,
107+ } ;
108+ contributionRegistry . registerContribution ( target , contribution ) ;
109+ expect ( contribution . visible ) . not . toBeInstanceOf ( Function ) ;
110+ expect ( contribution . disabled ) . not . toBeInstanceOf ( Function ) ;
111+ expect ( ( contribution . visible as { get ( ) : boolean } ) . get ( ) ) . toBe ( false ) ;
112+ expect ( ( contribution . disabled as { get ( ) : boolean } ) . get ( ) ) . toBe ( true ) ;
113+ } ) ;
114+
115+ it ( 'converts visible function to Signal.Computed' , ( ) => {
116+ const target = 'test-visible-' + Math . random ( ) ;
117+ const contribution : CommandContribution = {
118+ label : 'With visible' ,
119+ command : 'test.cmd' ,
120+ visible : ( ) => false ,
121+ } ;
122+ contributionRegistry . registerContribution ( target , contribution ) ;
123+ expect ( contribution . visible ) . toBeDefined ( ) ;
124+ expect ( contribution . visible ) . not . toBeInstanceOf ( Function ) ;
125+ expect ( ( contribution . visible as { get ( ) : boolean } ) . get ( ) ) . toBe ( false ) ;
126+ } ) ;
127+
128+ it ( 'leaves existing Signal.Computed visible unchanged' , ( ) => {
129+ const target = 'test-visible-computed-' + Math . random ( ) ;
130+ const computed = new Signal . Computed ( ( ) => true ) ;
131+ const contribution : CommandContribution = {
132+ label : 'Already computed visible' ,
133+ command : 'test.cmd' ,
134+ visible : computed ,
135+ } ;
136+ contributionRegistry . registerContribution ( target , contribution ) ;
137+ expect ( contribution . visible ) . toBe ( computed ) ;
138+ expect ( ( contribution . visible as { get ( ) : boolean } ) . get ( ) ) . toBe ( true ) ;
139+ } ) ;
140+
65141 describe ( 'contribution target remapping' , ( ) => {
66142 it ( 'getContributions(slotB) returns contribution registered to slotA when remapped to slotB' , ( ) => {
67143 const slotA = 'test-remap-a-' + Math . random ( ) ;
0 commit comments