@@ -49,3 +49,140 @@ test('check categories', async () => {
49
49
const category2 = screen . getByText ( 'category2' ) ;
50
50
expect ( category2 ) . toBeInTheDocument ( ) ;
51
51
} ) ;
52
+
53
+ test ( 'if per_page is passed into window.location.search then it should be used to filter extensions' , async ( ) => {
54
+ // Mock query to be last 1
55
+ vi . spyOn ( window , 'location' , 'get' ) . mockReturnValue ( {
56
+ search : '?per_page=1' ,
57
+ } as unknown as Location ) ;
58
+
59
+ const extensionsByCategories : ExtensionByCategoryInfo [ ] = [
60
+ {
61
+ category : 'category1' ,
62
+ extensions : [
63
+ {
64
+ displayName : 'dummy1' ,
65
+ versions : [
66
+ {
67
+ version : '1.0.0' ,
68
+ // Todays date minus 1 day, to make sure it is NOT the most recent one (we want to show dummy2)
69
+ lastUpdated : new Date ( new Date ( ) . setDate ( new Date ( ) . getDate ( ) - 1 ) ) ,
70
+ files : [ ] ,
71
+ } ,
72
+ ] ,
73
+ } as unknown as CatalogExtensionInfo ,
74
+ ] ,
75
+ } ,
76
+ {
77
+ category : 'category2' ,
78
+ extensions : [
79
+ {
80
+ displayName : 'dummy2' ,
81
+ versions : [
82
+ {
83
+ version : '1.0.0' ,
84
+ lastUpdated : new Date ( ) ,
85
+ files : [ ] ,
86
+ } ,
87
+ ] ,
88
+ } as unknown as CatalogExtensionInfo ,
89
+ ] ,
90
+ } ,
91
+ ] ;
92
+
93
+ render ( ExtensionsList , { extensionsByCategories } ) ;
94
+
95
+ // Make sure that displayname dummy2 is shown, as it is the "most" up to date one.
96
+ const dummy2 = screen . getByText ( 'dummy2' ) ;
97
+ expect ( dummy2 ) . toBeInTheDocument ( ) ;
98
+
99
+ // Dummy1 should NOT be shown
100
+ const dummy1 = screen . queryByText ( 'dummy1' ) ;
101
+ expect ( dummy1 ) . not . toBeInTheDocument ( ) ;
102
+
103
+ // Categories category1 and category2 should be NOT shown
104
+ const category1 = screen . queryByText ( 'category1' ) ;
105
+ expect ( category1 ) . not . toBeInTheDocument ( ) ;
106
+
107
+ const category2 = screen . queryByText ( 'category2' ) ;
108
+ expect ( category2 ) . not . toBeInTheDocument ( ) ;
109
+ } ) ;
110
+
111
+ test ( 'if per_page is passed in with 4, it should show last 4 extensions even if there is 5 in the list' , async ( ) => {
112
+ // Mock query to be last 4
113
+ vi . spyOn ( window , 'location' , 'get' ) . mockReturnValue ( {
114
+ search : '?per_page=4' ,
115
+ } as unknown as Location ) ;
116
+
117
+ const extensionsByCategories : ExtensionByCategoryInfo [ ] = [
118
+ {
119
+ category : 'category1' ,
120
+ extensions : [
121
+ {
122
+ displayName : 'dummy1' ,
123
+ versions : [
124
+ {
125
+ version : '1.0.0' ,
126
+ lastUpdated : new Date ( new Date ( ) . setDate ( new Date ( ) . getDate ( ) - 1 ) ) ,
127
+ files : [ ] ,
128
+ } ,
129
+ ] ,
130
+ } as unknown as CatalogExtensionInfo ,
131
+ {
132
+ displayName : 'dummy2' ,
133
+ versions : [
134
+ {
135
+ version : '1.0.0' ,
136
+ lastUpdated : new Date ( new Date ( ) . setDate ( new Date ( ) . getDate ( ) - 2 ) ) ,
137
+ files : [ ] ,
138
+ } ,
139
+ ] ,
140
+ } as unknown as CatalogExtensionInfo ,
141
+ {
142
+ displayName : 'dummy3' ,
143
+ versions : [
144
+ {
145
+ version : '1.0.0' ,
146
+ lastUpdated : new Date ( new Date ( ) . setDate ( new Date ( ) . getDate ( ) - 3 ) ) ,
147
+ files : [ ] ,
148
+ } ,
149
+ ] ,
150
+ } as unknown as CatalogExtensionInfo ,
151
+ {
152
+ displayName : 'dummy4' ,
153
+ versions : [
154
+ {
155
+ version : '1.0.0' ,
156
+ lastUpdated : new Date ( new Date ( ) . setDate ( new Date ( ) . getDate ( ) - 4 ) ) ,
157
+ files : [ ] ,
158
+ } ,
159
+ ] ,
160
+ } as unknown as CatalogExtensionInfo ,
161
+ {
162
+ displayName : 'dummy5' ,
163
+ versions : [
164
+ {
165
+ version : '1.0.0' ,
166
+ lastUpdated : new Date ( new Date ( ) . setDate ( new Date ( ) . getDate ( ) - 5 ) ) ,
167
+ files : [ ] ,
168
+ } ,
169
+ ] ,
170
+ } as unknown as CatalogExtensionInfo ,
171
+ ] ,
172
+ } ,
173
+ ] ;
174
+
175
+ render ( ExtensionsList , { extensionsByCategories } ) ;
176
+
177
+ // Make sure that displayname dummy4 is shown, as it is the "most" up to date one.
178
+ const dummy4 = screen . getByText ( 'dummy4' ) ;
179
+ expect ( dummy4 ) . toBeInTheDocument ( ) ;
180
+
181
+ // Dummy5 should NOT be shown, as it's the "oldest" one.
182
+ const dummy5 = screen . queryByText ( 'dummy5' ) ;
183
+ expect ( dummy5 ) . not . toBeInTheDocument ( ) ;
184
+
185
+ // Categories category1 should be NOT shown
186
+ const category1 = screen . queryByText ( 'category1' ) ;
187
+ expect ( category1 ) . not . toBeInTheDocument ( ) ;
188
+ } ) ;
0 commit comments