@@ -205,6 +205,102 @@ describe('catalog', () => {
205205 // Version info should be changed (it's now empty given reset)
206206 expect ( store . state [ catalogStoreName ] . versionInfos ) . toStrictEqual ( { } ) ;
207207 } ) ;
208+
209+ it ( 'repoKeys provided' , async ( ) => {
210+ const store = createStore ( constructStore ( ) ) ;
211+
212+ // Validate initial state of store
213+ expect ( store . getters [ `${ catalogStoreName } /rawCharts` ] ) . toStrictEqual ( initialRawCharts ) ;
214+ expect ( store . getters [ `${ catalogStoreName } /charts` ] ) . toStrictEqual ( [ ] ) ;
215+
216+ // Make the request targeting specific repo (we provide repo._key)
217+ await store . dispatch ( `${ catalogStoreName } /load` , {
218+ force : true ,
219+ repoKeys : [ repo . _key ]
220+ } ) ;
221+
222+ const rawCharts = store . getters [ `${ catalogStoreName } /rawCharts` ] ;
223+ const charts = store . getters [ `${ catalogStoreName } /charts` ] ;
224+
225+ // We expect the old chart belonging to this repo to be wiped out
226+ // and replaced entirely by the newly fetched chart.
227+ expect ( rawCharts [ initialRawChart . id ] ) . not . toBeDefined ( ) ;
228+ expect ( rawCharts [ expectedChartKey ] ) . toBeDefined ( ) ;
229+ expect ( rawCharts [ expectedChartKey ] . id ) . toBe ( expectedChartKey ) ;
230+ expect ( rawCharts [ expectedChartKey ] . versions [ 0 ] . version ) . toBe ( repoChart . version ) ;
231+
232+ expect ( charts ) . toHaveLength ( 1 ) ;
233+ expect ( charts [ 0 ] ) . toBeDefined ( ) ;
234+ expect ( charts [ 0 ] . id ) . toBe ( expectedChartKey ) ;
235+ } ) ;
236+
237+ it ( 'repoKeys provided, ignoring unrelated charts and versions' , async ( ) => {
238+ // We will manually inject an unrelated chart to prove it isn't wiped out
239+ const store = createStore ( constructStore ( ) ) ;
240+ const unrelatedChart = {
241+ id : `namespace/unrelatedRepo/unrelatedChart` ,
242+ repoKey : 'unrelatedRepo' ,
243+ type : 'namespaced' ,
244+ name : 'unrelatedChart' ,
245+ version : 1 ,
246+ metadata : { name : 'unrelatedChart' }
247+ } ;
248+
249+ const targetedVersionKey = `namespace/testRepo/myChart/1.0.0` ;
250+ const unrelatedVersionKey = `namespace/unrelatedRepo/unrelatedChart/1.0.0` ;
251+
252+ store . state [ catalogStoreName ] . charts = {
253+ ...initialRawCharts ,
254+ [ unrelatedChart . id ] : unrelatedChart
255+ } ;
256+
257+ store . state [ catalogStoreName ] . versionInfos = {
258+ [ targetedVersionKey ] : { data : 'old-data' } ,
259+ [ unrelatedVersionKey ] : { data : 'keep-me' }
260+ } ;
261+
262+ // Make the request targeting specific repo
263+ await store . dispatch ( `${ catalogStoreName } /load` , {
264+ force : true ,
265+ repoKeys : [ repo . _key ]
266+ } ) ;
267+
268+ const rawCharts = store . getters [ `${ catalogStoreName } /rawCharts` ] ;
269+ const versionInfos = store . state [ catalogStoreName ] . versionInfos ;
270+
271+ // The unrelated chart should NOT be wiped
272+ expect ( rawCharts [ unrelatedChart . id ] ) . toBeDefined ( ) ;
273+ expect ( rawCharts [ unrelatedChart . id ] . repoKey ) . toBe ( 'unrelatedRepo' ) ;
274+
275+ // The old initialRawChart (with repoKey: repo._key) SHOULD be wiped and replaced
276+ expect ( rawCharts [ initialRawChart . id ] ) . not . toBeDefined ( ) ;
277+ expect ( rawCharts [ expectedChartKey ] ) . toBeDefined ( ) ;
278+
279+ // The targeted version info SHOULD be wiped
280+ expect ( versionInfos [ targetedVersionKey ] ) . not . toBeDefined ( ) ;
281+ // The unrelated version info should NOT be wiped
282+ expect ( versionInfos [ unrelatedVersionKey ] ) . toBeDefined ( ) ;
283+ expect ( versionInfos [ unrelatedVersionKey ] . data ) . toBe ( 'keep-me' ) ;
284+ } ) ;
285+ } ) ;
286+
287+ describe ( 'refresh' , ( ) => {
288+ it ( 'calls refresh(false) on all repos and then dispatches a reset load' , async ( ) => {
289+ const mockRepo1 = { refresh : jest . fn ( ) . mockResolvedValue ( true ) } ;
290+ const mockRepo2 = { refresh : jest . fn ( ) . mockResolvedValue ( true ) } ;
291+
292+ const getters = { repos : [ mockRepo1 , mockRepo2 ] } ;
293+ const dispatch = jest . fn ( ) . mockResolvedValue ( true ) ;
294+ const commit = jest . fn ( ) ;
295+
296+ await actions . refresh ( {
297+ getters, commit, dispatch
298+ } ) ;
299+
300+ expect ( mockRepo1 . refresh ) . toHaveBeenCalledWith ( false ) ;
301+ expect ( mockRepo2 . refresh ) . toHaveBeenCalledWith ( false ) ;
302+ expect ( dispatch ) . toHaveBeenCalledWith ( 'load' , { force : true , reset : true } ) ;
303+ } ) ;
208304 } ) ;
209305
210306 describe ( 'filterAndArrangeCharts' , ( ) => {
0 commit comments