@@ -88,4 +88,71 @@ describe('registries.vue', () => {
88
88
expect ( rows [ 0 ] . metadata . name ) . toBe ( 'reg1' ) ;
89
89
} ) ;
90
90
91
+ it ( 'summarizes registry scan data correctly' , ( ) => {
92
+ const wrapper = factory ( ) ;
93
+ const registriesCRD = [
94
+ {
95
+ metadata : { name : 'reg1' , namespace : 'ns1' , creationTimestamp : '2023-01-01T00:00:00Z' } ,
96
+ spec : { uri : 'http://test.uri' } ,
97
+ scanRec : { currStatus : 'complete' , previousStatus : 'pending' , lastTransitionTime : '2023-01-02T00:00:00Z' }
98
+ }
99
+ ] ;
100
+
101
+ const { registryStatusList, statusSummary } = wrapper . vm . getSummaryData ( registriesCRD ) ;
102
+
103
+ expect ( registryStatusList [ 0 ] . registryName ) . toBe ( 'reg1' ) ;
104
+ expect ( statusSummary . complete ) . toBe ( 1 ) ;
105
+ } ) ;
106
+ it ( 'updates filter status when filterByStatus is called' , ( ) => {
107
+ const wrapper = factory ( ) ;
108
+ wrapper . vm . filterByStatus ( 'pending' ) ;
109
+ expect ( wrapper . vm . filters . statusSearch ) . toBe ( 'pending' ) ;
110
+ } ) ;
111
+ it ( 'filters rows correctly by registry, namespace, uri, repository, and status' , ( ) => {
112
+ const wrapper = factory ( ) ;
113
+ ( wrapper . vm . rows as any [ ] ) = [ {
114
+ metadata : { name : 'reg1' , namespace : 'ns1' } ,
115
+ spec : { uri : 'http://my-uri' , repositories : [ 'repo1' ] } ,
116
+ scanRec : { currStatus : 'complete' }
117
+ } ] ;
118
+
119
+ wrapper . vm . filters = {
120
+ registrySearch : 'reg1' ,
121
+ namespaceSearch : 'ns1' ,
122
+ uriSearch : 'uri' ,
123
+ repositorySearch : 'repo1' ,
124
+ statusSearch : 'complete'
125
+ } ;
126
+
127
+ const filtered = wrapper . vm . filteredRows ;
128
+ expect ( filtered ) . toHaveLength ( 1 ) ;
129
+ expect ( filtered [ 0 ] . metadata . name ) . toBe ( 'reg1' ) ;
130
+ } ) ;
131
+ it ( 'formats latest update time correctly' , ( ) => {
132
+ const wrapper = factory ( ) ;
133
+ wrapper . vm . latestUpdateTime = new Date ( '2023-01-01T12:34:56Z' ) ;
134
+ expect ( wrapper . vm . latestUpdateDateText ) . toContain ( '2023' ) ; // year included
135
+ expect ( wrapper . vm . latestUpdateTimeText ) . toMatch ( / \d / ) ; // time string
136
+ } ) ;
137
+ it ( 'fetchSecondaryResources returns scan jobs' , async ( ) => {
138
+ storeMock . dispatch . mockResolvedValueOnce ( [ { id : 'scanJob1' } ] ) ;
139
+ const wrapper = factory ( ) ;
140
+ const result = await wrapper . vm . fetchSecondaryResources ( { canPaginate : false } ) ;
141
+ expect ( result ) . toEqual ( [ { id : 'scanJob1' } ] ) ;
142
+ } ) ;
143
+
144
+ it ( 'fetchPageSecondaryResources fetches scan jobs with pagination' , async ( ) => {
145
+ const scanJob = { id : 'scanJob1' } ;
146
+ storeMock . dispatch . mockResolvedValueOnce ( [ scanJob ] ) ;
147
+
148
+ const wrapper = factory ( ) ;
149
+ const result = await wrapper . vm . fetchPageSecondaryResources ( {
150
+ canPaginate : true ,
151
+ force : true ,
152
+ page : [ { metadata : { namespace : 'ns1' , name : 'job1' } } ]
153
+ } ) ;
154
+
155
+ expect ( storeMock . dispatch ) . toHaveBeenCalledWith ( 'cluster/findPage' , expect . any ( Object ) ) ;
156
+ expect ( result ) . toEqual ( [ scanJob ] ) ;
157
+ } ) ;
91
158
} ) ;
0 commit comments