@@ -3,6 +3,10 @@ import Resource from '@shell/plugins/dashboard-store/resource-class.js';
33import { resourceClassJunkObject } from '@shell/plugins/dashboard-store/__tests__/utils/store-mocks' ;
44import { EVENT } from '@shell/config/types' ;
55
6+ jest . mock ( '@shell/config/version' , ( ) => ( { getVersionData : ( ) => ( { Version : 'v2.13.0' } ) } ) ) ;
7+ jest . mock ( '@shell/config/uiplugins' , ( ) => ( { parseRancherVersion : ( v : string ) => v } ) ) ;
8+ jest . mock ( '@shell/core/plugin-helpers' , ( ) => ( { getApplicableExtensionEnhancements : ( ) => [ ] } ) ) ;
9+
610describe ( 'class: Resource' , ( ) => {
711 describe ( 'given custom resource keys' , ( ) => {
812 const customResource = resourceClassJunkObject ;
@@ -497,4 +501,88 @@ describe('class: Resource', () => {
497501 expect ( actions [ 1 ] . variant ) . toBe ( 'primary' ) ;
498502 } ) ;
499503 } ) ;
504+
505+ describe ( 'getter: _availableActions' , ( ) => {
506+ function createResource ( links : Record < string , string > , overrides : Record < string , any > = { } ) {
507+ const resource = new Resource ( {
508+ type : 'test-type' ,
509+ links,
510+ ...overrides ,
511+ } , {
512+ getters : {
513+ schemaFor : ( ) => ( {
514+ linkFor : jest . fn ( ) ,
515+ resourceMethods : [ ] ,
516+ collectionMethods : [ ] ,
517+ } ) ,
518+ } ,
519+ dispatch : jest . fn ( ) ,
520+ rootState : { $extension : { getPlugins : ( ) => ( { } ) } } ,
521+ rootGetters : {
522+ 'i18n/t' : ( key : string ) => key ,
523+ 'type-map/hasCustomEdit' : ( ) => false ,
524+ 'type-map/optionsFor' : ( ) => ( {
525+ isEditable : false , isRemovable : true , isCreatable : false
526+ } ) ,
527+ 'prefs/get' : ( ) => false ,
528+ currentCluster : undefined ,
529+ currentProduct : undefined ,
530+ ...overrides . rootGetters ,
531+ } ,
532+ } ) ;
533+
534+ jest . spyOn ( resource , 'currentRouter' ) . mockReturnValue ( { currentRoute : { value : { } } } as any ) ;
535+
536+ return resource ;
537+ }
538+
539+ function findAction ( actions : any [ ] , actionName : string ) {
540+ return actions . find ( ( a : any ) => a . action === actionName ) ;
541+ }
542+
543+ it ( 'should hide "View YAML" when "Show Configuration" is enabled and resource cannot edit YAML' , ( ) => {
544+ const resource = createResource ( { view : '/api/v1/test' } ) ;
545+
546+ const actions = resource . _availableActions ;
547+ const viewYaml = findAction ( actions , 'goToViewYaml' ) ;
548+ const showConfig = findAction ( actions , 'showConfiguration' ) ;
549+
550+ expect ( showConfig . enabled ) . toBe ( true ) ;
551+ expect ( viewYaml . enabled ) . toBe ( false ) ;
552+ } ) ;
553+
554+ it ( 'should show "Edit YAML" even when "Show Configuration" is enabled' , ( ) => {
555+ const resource = createResource (
556+ { view : '/api/v1/test' , update : '/api/v1/test' } ,
557+ {
558+ rootGetters : {
559+ 'type-map/optionsFor' : ( ) => ( {
560+ isEditable : true , isRemovable : true , isCreatable : false
561+ } )
562+ }
563+ } ,
564+ ) ;
565+
566+ const actions = resource . _availableActions ;
567+ const editYaml = findAction ( actions , 'goToEditYaml' ) ;
568+ const showConfig = findAction ( actions , 'showConfiguration' ) ;
569+
570+ expect ( showConfig . enabled ) . toBe ( true ) ;
571+ expect ( editYaml . enabled ) . toBe ( true ) ;
572+ } ) ;
573+
574+ it ( 'should show "View YAML" when "Show Configuration" is not enabled' , ( ) => {
575+ const resource = createResource (
576+ { view : '/api/v1/test' } ,
577+ { disableResourceDetailDrawer : true } ,
578+ ) ;
579+
580+ const actions = resource . _availableActions ;
581+ const viewYaml = findAction ( actions , 'goToViewYaml' ) ;
582+ const showConfig = findAction ( actions , 'showConfiguration' ) ;
583+
584+ expect ( showConfig . enabled ) . toBe ( false ) ;
585+ expect ( viewYaml . enabled ) . toBe ( true ) ;
586+ } ) ;
587+ } ) ;
500588} ) ;
0 commit comments