@@ -214,6 +214,72 @@ describe('chartMixin', () => {
214214 id : 'custom-ns/custom-name'
215215 } ) ;
216216 } ) ;
217+
218+ it ( 'should fall back to matchingInstalledApps when version namespace lookup fails' , async ( ) => {
219+ const installedApp = {
220+ id : 'other-ns/custom-name' ,
221+ spec : { chart : { metadata : { version : '0.9.0' } } }
222+ } ;
223+
224+ const mockStore = {
225+ dispatch : jest . fn ( ( action , payload ) => {
226+ if ( action === 'cluster/find' ) {
227+ return Promise . reject ( new Error ( 'not found' ) ) ;
228+ }
229+
230+ return Promise . resolve ( ) ;
231+ } ) ,
232+ getters : {
233+ currentCluster : ( ) => { } ,
234+ isRancher : ( ) => true ,
235+ 'catalog/repo' : ( ) => {
236+ return ( ) => 'repo' ;
237+ } ,
238+ 'catalog/chart' : ( ) => {
239+ return {
240+ id : 'chart-id' ,
241+ versions : [ { version : '1.0.0' } ] ,
242+ matchingInstalledApps : [ installedApp ]
243+ } ;
244+ } ,
245+ 'catalog/version' : ( ) => ( {
246+ version : '1.0.0' ,
247+ annotations : {
248+ [ CATALOG_ANNOTATIONS . NAMESPACE ] : 'custom-ns' ,
249+ [ CATALOG_ANNOTATIONS . RELEASE_NAME ] : 'custom-name' ,
250+ }
251+ } ) ,
252+ 'prefs/get' : ( ) => { } ,
253+ 'i18n/t' : ( ) => jest . fn ( )
254+ }
255+ } ;
256+
257+ const DummyComponent = {
258+ mixins : [ ChartMixin ] ,
259+ template : '<div></div>' ,
260+ } ;
261+
262+ const wrapper = mount (
263+ DummyComponent ,
264+ {
265+ global : {
266+ mocks : {
267+ $store : mockStore ,
268+ $route : {
269+ query : {
270+ chart : 'chart_name' ,
271+ versionName : '1.0.0'
272+ }
273+ }
274+ }
275+ }
276+ } ) ;
277+
278+ await wrapper . vm . fetchChart ( ) ;
279+
280+ expect ( wrapper . vm . existing ) . toStrictEqual ( installedApp ) ;
281+ expect ( wrapper . vm . mode ) . toStrictEqual ( 'edit' ) ;
282+ } ) ;
217283 } ) ;
218284
219285 describe ( 'action' , ( ) => {
@@ -366,6 +432,52 @@ describe('chartMixin', () => {
366432 } ) ;
367433 } ) ;
368434
435+ describe ( 'isChartTargeted' , ( ) => {
436+ const DummyComponent = {
437+ mixins : [ ChartMixin ] ,
438+ template : '<div></div>' ,
439+ } ;
440+
441+ const mockStore = {
442+ dispatch : jest . fn ( ( ) => Promise . resolve ( ) ) ,
443+ getters : { 'i18n/t' : ( key : string ) => key }
444+ } ;
445+
446+ it ( 'should return truthy when version annotations have both namespace and release-name' , ( ) => {
447+ const wrapper = mount ( DummyComponent , {
448+ data : ( ) => ( {
449+ version : {
450+ annotations : {
451+ [ CATALOG_ANNOTATIONS . NAMESPACE ] : 'custom-ns' ,
452+ [ CATALOG_ANNOTATIONS . RELEASE_NAME ] : 'custom-name' ,
453+ }
454+ }
455+ } ) ,
456+ global : { mocks : { $store : mockStore } }
457+ } ) ;
458+
459+ expect ( wrapper . vm . isChartTargeted ) . toBeTruthy ( ) ;
460+ } ) ;
461+
462+ it ( 'should return falsy when version annotations are missing' , ( ) => {
463+ const wrapper = mount ( DummyComponent , {
464+ data : ( ) => ( { version : { annotations : { } } } ) ,
465+ global : { mocks : { $store : mockStore } }
466+ } ) ;
467+
468+ expect ( wrapper . vm . isChartTargeted ) . toBeFalsy ( ) ;
469+ } ) ;
470+
471+ it ( 'should return falsy when version is null' , ( ) => {
472+ const wrapper = mount ( DummyComponent , {
473+ data : ( ) => ( { version : null } ) ,
474+ global : { mocks : { $store : mockStore } }
475+ } ) ;
476+
477+ expect ( wrapper . vm . isChartTargeted ) . toBeFalsy ( ) ;
478+ } ) ;
479+ } ) ;
480+
369481 describe ( 'mappedVersions' , ( ) => {
370482 it ( 'should return versions sorted by semver (descending)' , ( ) => {
371483 const versions = [
0 commit comments