File tree 6 files changed +120
-2
lines changed
packages/peregrine/lib/talons
6 files changed +120
-2
lines changed Original file line number Diff line number Diff line change @@ -171,4 +171,74 @@ describe('#sortFiltersArray', () => {
171
171
]
172
172
` ) ;
173
173
} ) ;
174
+ test ( 'returns sorted filters array with entry containing category_uid attribute code' , ( ) => {
175
+ const initialFiltersArray = [
176
+ {
177
+ attribute_code : 'code_c' ,
178
+ label : 'C - Label' ,
179
+ position : 0
180
+ } ,
181
+ {
182
+ attribute_code : 'code_b' ,
183
+ label : 'B - Label' ,
184
+ position : 0
185
+ } ,
186
+ {
187
+ attribute_code : 'code_f' ,
188
+ label : 'Label - F' ,
189
+ position : 20
190
+ } ,
191
+ {
192
+ attribute_code : 'category_uid' ,
193
+ label : 'label' ,
194
+ position : null
195
+ } ,
196
+ {
197
+ attribute_code : 'code_e' ,
198
+ label : 'Label - E' ,
199
+ position : 10
200
+ } ,
201
+ {
202
+ attribute_code : 'code_a' ,
203
+ label : 'A - Label' ,
204
+ position : 0
205
+ }
206
+ ] ;
207
+ const sortedFilters = sortFiltersArray ( initialFiltersArray ) ;
208
+
209
+ expect ( sortedFilters ) . toMatchInlineSnapshot ( `
210
+ Array [
211
+ Object {
212
+ "attribute_code": "category_uid",
213
+ "label": "label",
214
+ "position": null,
215
+ },
216
+ Object {
217
+ "attribute_code": "code_a",
218
+ "label": "A - Label",
219
+ "position": 0,
220
+ },
221
+ Object {
222
+ "attribute_code": "code_b",
223
+ "label": "B - Label",
224
+ "position": 0,
225
+ },
226
+ Object {
227
+ "attribute_code": "code_c",
228
+ "label": "C - Label",
229
+ "position": 0,
230
+ },
231
+ Object {
232
+ "attribute_code": "code_e",
233
+ "label": "Label - E",
234
+ "position": 10,
235
+ },
236
+ Object {
237
+ "attribute_code": "code_f",
238
+ "label": "Label - F",
239
+ "position": 20,
240
+ },
241
+ ]
242
+ ` ) ;
243
+ } ) ;
174
244
} ) ;
Original file line number Diff line number Diff line change @@ -46,6 +46,9 @@ jest.mock('@apollo/client', () => {
46
46
{
47
47
name : 'category_id'
48
48
} ,
49
+ {
50
+ name : 'category_uid'
51
+ } ,
49
52
{
50
53
name : 'foo'
51
54
} ,
@@ -94,6 +97,20 @@ const defaultProps = {
94
97
}
95
98
]
96
99
} ,
100
+ {
101
+ attribute_code : 'category_uid' ,
102
+ label : 'Category 2' ,
103
+ options : [
104
+ {
105
+ label : 'Bottoms' ,
106
+ value : '28'
107
+ } ,
108
+ {
109
+ label : 'Tops' ,
110
+ value : '19'
111
+ }
112
+ ]
113
+ } ,
97
114
{
98
115
attribute_code : 'foo' ,
99
116
label : 'Foo' ,
@@ -167,12 +184,15 @@ describe('#useFilterModal', () => {
167
184
createTestInstance ( < Component /> ) ;
168
185
const { filterNames } = log . mock . calls [ 0 ] [ 0 ] ;
169
186
expect ( filterNames . get ( 'category_id' ) ) . toBeTruthy ( ) ;
187
+ expect ( filterNames . get ( 'category_uid' ) ) . toBeTruthy ( ) ;
170
188
} ) ;
171
189
172
190
it ( 'only renders filters that are valid and enabled' , ( ) => {
173
191
createTestInstance ( < Component /> ) ;
174
192
const { filterNames } = log . mock . calls [ 0 ] [ 0 ] ;
175
193
expect ( filterNames . get ( 'foo' ) ) . toBeTruthy ( ) ;
194
+ expect ( filterNames . get ( 'category_id' ) ) . toBeFalsy ( ) ;
195
+ expect ( filterNames . get ( 'category_uid' ) ) . toBeFalsy ( ) ;
176
196
} ) ;
177
197
178
198
it ( 'renders boolean filters' , ( ) => {
Original file line number Diff line number Diff line change @@ -111,10 +111,16 @@ export const getFiltersFromSearch = initialValue => {
111
111
export const sortFiltersArray = initialArray => {
112
112
return initialArray . sort ( ( a , b ) => {
113
113
// Place Category filter first
114
- if ( a [ 'attribute_code' ] === 'category_id' ) {
114
+ if (
115
+ a [ 'attribute_code' ] === 'category_id' ||
116
+ a [ 'attribute_code' ] === 'category_uid'
117
+ ) {
115
118
return - 1 ;
116
119
}
117
- if ( b [ 'attribute_code' ] === 'category_id' ) {
120
+ if (
121
+ b [ 'attribute_code' ] === 'category_id' ||
122
+ b [ 'attribute_code' ] === 'category_uid'
123
+ ) {
118
124
return 1 ;
119
125
}
120
126
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ export const useFilterModal = props => {
55
55
// Disable category filtering when not on a search page.
56
56
if ( pathname !== '/search.html' ) {
57
57
disabled . add ( 'category_id' ) ;
58
+ disabled . add ( 'category_uid' ) ;
58
59
}
59
60
60
61
return disabled ;
Original file line number Diff line number Diff line change @@ -46,6 +46,9 @@ jest.mock('@apollo/client', () => {
46
46
{
47
47
name : 'category_id'
48
48
} ,
49
+ {
50
+ name : 'category_uid'
51
+ } ,
49
52
{
50
53
name : 'foo'
51
54
} ,
@@ -94,6 +97,20 @@ const defaultProps = {
94
97
}
95
98
]
96
99
} ,
100
+ {
101
+ attribute_code : 'category_uid' ,
102
+ label : 'Category 2' ,
103
+ options : [
104
+ {
105
+ label : 'Bottoms' ,
106
+ value : '28'
107
+ } ,
108
+ {
109
+ label : 'Tops' ,
110
+ value : '19'
111
+ }
112
+ ]
113
+ } ,
97
114
{
98
115
attribute_code : 'foo' ,
99
116
label : 'Foo' ,
@@ -167,12 +184,15 @@ describe('#useFilterSidebar', () => {
167
184
createTestInstance ( < Component /> ) ;
168
185
const { filterNames } = log . mock . calls [ 0 ] [ 0 ] ;
169
186
expect ( filterNames . get ( 'category_id' ) ) . toBeTruthy ( ) ;
187
+ expect ( filterNames . get ( 'category_uid' ) ) . toBeTruthy ( ) ;
170
188
} ) ;
171
189
172
190
it ( 'only renders filters that are valid and enabled' , ( ) => {
173
191
createTestInstance ( < Component /> ) ;
174
192
const { filterNames } = log . mock . calls [ 0 ] [ 0 ] ;
175
193
expect ( filterNames . get ( 'foo' ) ) . toBeTruthy ( ) ;
194
+ expect ( filterNames . get ( 'category_id' ) ) . toBeFalsy ( ) ;
195
+ expect ( filterNames . get ( 'category_uid' ) ) . toBeFalsy ( ) ;
176
196
} ) ;
177
197
178
198
it ( 'writes filter state to history when "isApplying"' , ( ) => {
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ export const useFilterSidebar = props => {
45
45
// Disable category filtering when not on a search page.
46
46
if ( pathname !== '/search.html' ) {
47
47
disabled . add ( 'category_id' ) ;
48
+ disabled . add ( 'category_uid' ) ;
48
49
}
49
50
50
51
return disabled ;
You can’t perform that action at this time.
0 commit comments