sr-npm 2.0.19 → 2.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,6 +39,11 @@ const fieldTitlesInCMS={
39
39
  "brand": "Brands",
40
40
  category: "Category",
41
41
  visibility: "Visibility",
42
+ location: "Location",
43
+ employmenttype: "Employment Type",
44
+ contracttype: "Contract Type",
45
+ companysegment: "Company Segment",
46
+ storename: "Store Name",
42
47
  }
43
48
 
44
49
  const FiltersIds={
@@ -52,10 +57,21 @@ const FiltersIds={
52
57
  Visibility: 'Visibility',
53
58
  }
54
59
 
60
+ const possibleUrlParams=[
61
+ "brand",
62
+ "location",
63
+ "employmenttype",
64
+ "contracttype",
65
+ "visibility",
66
+ "category",
67
+ "companysegment",
68
+ "storename",
69
+ ]
55
70
 
56
71
  module.exports = {
57
72
  CAREERS_MULTI_BOXES_PAGE_CONSTS,
58
73
  FiltersIds,
59
74
  fieldTitlesInCMS,
60
75
  CATEGORY_CUSTOM_FIELD_ID_IN_CMS,
76
+ possibleUrlParams,
61
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "2.0.19",
3
+ "version": "2.0.20",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,9 +1,11 @@
1
1
  const { COLLECTIONS,CUSTOM_VALUES_COLLECTION_FIELDS,JOBS_COLLECTION_FIELDS } = require('../backend/collectionConsts');
2
- const { queryParams} = require('wix-location-frontend');
2
+
3
+ const { queryParams,onChange} = require('wix-location-frontend');
3
4
  const { location } = require("@wix/site-location");
4
- const {CAREERS_MULTI_BOXES_PAGE_CONSTS,FiltersIds,fieldTitlesInCMS} = require('../backend/careersMultiBoxesPageIds');
5
+ const {CAREERS_MULTI_BOXES_PAGE_CONSTS,FiltersIds,fieldTitlesInCMS,possibleUrlParams} = require('../backend/careersMultiBoxesPageIds');
5
6
  const { groupValuesByField, debounce, getAllRecords, getFieldById, getFieldByTitle,getCorrectOption,getOptionIndexFromCheckBox,loadPrimarySearchRepeater,bindPrimarySearch,primarySearch } = require('./pagesUtils');
6
7
 
8
+
7
9
  let dontUpdateThisCheckBox;
8
10
  const selectedByField = new Map(); // fieldId -> array of selected value IDs
9
11
  const optionsByFieldId = new Map(); // fieldId -> [{label, value}] array of objects with label which is the valueLabel and value which is the valueId
@@ -22,6 +24,10 @@ const pagination = {
22
24
  currentPage: 1,
23
25
  };
24
26
  async function careersMultiBoxesPageOnReady(_$w,urlParams) {
27
+ //to handle back and forth , url changes
28
+ onChange(async ()=>{
29
+ await handleBackAndForth(_$w);
30
+ });
25
31
  await loadData(_$w);
26
32
  loadJobsRepeater(_$w);
27
33
  loadPrimarySearchRepeater(_$w);
@@ -41,7 +47,15 @@ async function careersMultiBoxesPageOnReady(_$w,urlParams) {
41
47
 
42
48
  }
43
49
 
44
- async function clearAll(_$w) {
50
+ async function handleBackAndForth(_$w){
51
+ const newQueryParams=await location.query();
52
+ console.log("newQueryParams: ", newQueryParams);
53
+ await clearAll(_$w,true);
54
+ await handleUrlParams(_$w,newQueryParams);
55
+
56
+ }
57
+
58
+ async function clearAll(_$w,urlOnChange=false) {
45
59
  if(selectedByField.size>0 || _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.SECONDARY_SEARCH_INPUT).value || _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value) {
46
60
  for(const field of allfields) {
47
61
  _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = [];
@@ -52,6 +66,9 @@ async function clearAll(_$w) {
52
66
  secondarySearchIsFilled=false;
53
67
  currentJobs=alljobs;
54
68
  keywordAllJobs=undefined;
69
+ if(!urlOnChange) {
70
+ queryParams.remove(possibleUrlParams.concat(["keyword", "page"]));
71
+ }
55
72
  await updateJobsAndNumbersAndFilters(_$w,true);
56
73
  }
57
74
  }
@@ -95,26 +112,30 @@ function handleFilterInMobile(_$w) {
95
112
  async function handleUrlParams(_$w,urlParams) {
96
113
  try {
97
114
  let applyFiltering=false;
98
-
115
+ let currentApplyFilterFlag=false;
116
+ //apply this first to determine all jobs
99
117
  if(urlParams.keyword) {
100
118
  applyFiltering=await primarySearch(_$w, decodeURIComponent(urlParams.keyword), alljobs);
101
119
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value=decodeURIComponent(urlParams.keyword);
102
120
  currentJobs=_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
103
121
  keywordAllJobs=_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
104
122
  }
105
- if(urlParams.brand) {
106
- applyFiltering=await handleParams(_$w,"brand",urlParams.brand)
107
- }
108
- if(urlParams.visibility) {
109
- applyFiltering=await handleParams(_$w,"visibility",urlParams.visibility)
110
- }
111
- if(urlParams.category) {
112
- applyFiltering=await handleParams(_$w,"category",urlParams.category)
123
+
124
+ for (const url of possibleUrlParams)
125
+ {
126
+ if(urlParams[url])
127
+ {
128
+ currentApplyFilterFlag=await handleParams(_$w,url,urlParams[url])
129
+ if(currentApplyFilterFlag) {
130
+ applyFiltering=true;
131
+ }
113
132
  }
114
-
133
+ currentApplyFilterFlag=false;
134
+ }
115
135
  if(applyFiltering || keywordAllJobs) {
116
136
  await updateJobsAndNumbersAndFilters(_$w);
117
137
  }
138
+
118
139
  if(urlParams.page) {
119
140
  if(Number.isNaN(Number(urlParams.page)) || Number(urlParams.page)<=1 || Number(urlParams.page)>Math.ceil(currentJobs.length/pagination.pageSize)) {
120
141
  console.warn("page number is invalid, removing page from url");
@@ -122,14 +143,14 @@ async function handleUrlParams(_$w,urlParams) {
122
143
  return;
123
144
  }
124
145
  pagination.currentPage=Number(urlParams.page);
125
- let paginationCurrentText=Number(urlParams.page)*pagination.pageSize
146
+ //let paginationCurrentText=urlParams.page;
126
147
  let startSlicIndex=pagination.pageSize*(pagination.currentPage-1);
127
148
  let endSlicIndex=(pagination.pageSize)*(pagination.currentPage);
128
149
  if(Number(urlParams.page)==Math.ceil(currentJobs.length/pagination.pageSize)) {
129
- paginationCurrentText=paginationCurrentText-(pagination.pageSize-(currentJobs.length%pagination.pageSize));
150
+ // paginationCurrentText=(paginationCurrentText-(pagination.pageSize-(currentJobs.length%pagination.pageSize))).toString();
130
151
  endSlicIndex=currentJobs.length;
131
152
  }
132
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = paginationCurrentText.toString();
153
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = urlParams.page
133
154
  const jobsFirstPage=currentJobs.slice(startSlicIndex,endSlicIndex);
134
155
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
135
156
  handlePaginationButtons(_$w);
@@ -139,31 +160,49 @@ async function handleUrlParams(_$w,urlParams) {
139
160
  }
140
161
  }
141
162
 
142
- async function handleParams(_$w,param,value) {
163
+ async function handleParams(_$w,param,values) {
143
164
  let applyFiltering=false;
165
+ let valuesAsArray = values.split(',')
166
+ valuesAsArray=valuesAsArray.filter(value=>value.trim()!=='');
167
+
168
+ let selectedIndices=[];
169
+ const field=getFieldByTitle(fieldTitlesInCMS[param],allfields);
170
+
171
+ let existing = selectedByField.get(field._id) || [];
172
+ for(const value of valuesAsArray) {
173
+
144
174
  const decodedValue = decodeURIComponent(value);
145
- const field=getFieldByTitle(fieldTitlesInCMS[param],allfields);
175
+
146
176
  const options=optionsByFieldId.get(field._id);
147
- const option=getCorrectOption(decodedValue,options);
177
+
178
+ const option=getCorrectOption(decodedValue,options,param);
179
+
148
180
  if(option) {
149
181
  const optionIndex=getOptionIndexFromCheckBox(_$w(`#${FiltersIds[field.title]}CheckBox`).options,option.value);
150
- _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = [optionIndex];
151
- selectedByField.set(field._id, [option.value]);
182
+ selectedIndices.push(optionIndex);
183
+ existing.push(option.value);
152
184
  applyFiltering=true;
153
185
  dontUpdateThisCheckBox=field._id;
154
186
  }
155
187
  else {
156
188
  console.warn(`${param} value not found in dropdown options`);
157
189
  }
158
- return applyFiltering;
190
+ }
191
+
192
+ selectedByField.set(field._id, existing);
193
+ _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices=selectedIndices;
194
+
195
+ return applyFiltering;
196
+
159
197
  }
160
198
 
161
199
  function loadPaginationButtons(_$w) {
162
200
  try {
163
201
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_NEXT).onClick(async () => {
164
202
  let nextPageJobs=currentJobs.slice(pagination.pageSize*pagination.currentPage,pagination.pageSize*(pagination.currentPage+1));
165
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = (nextPageJobs.length+pagination.pageSize*pagination.currentPage).toString();
203
+
166
204
  pagination.currentPage++;
205
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = pagination.currentPage.toString();
167
206
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = nextPageJobs;
168
207
  handlePaginationButtons(_$w);
169
208
  });
@@ -171,7 +210,7 @@ async function handleParams(_$w,param,value) {
171
210
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_PREVIOUS).onClick(async () => {
172
211
  let previousPageJobs=currentJobs.slice(pagination.pageSize*(pagination.currentPage-2),pagination.pageSize*(pagination.currentPage-1));
173
212
  pagination.currentPage--;
174
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = (pagination.pageSize*pagination.currentPage).toString();
213
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = pagination.currentPage.toString();
175
214
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = previousPageJobs;
176
215
  handlePaginationButtons(_$w);
177
216
  });
@@ -186,21 +225,22 @@ async function handleParams(_$w,param,value) {
186
225
  $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.SELECTED_VALUES_REPEATER_ITEM_LABEL).text = itemData.label || '';
187
226
  // Deselect this value from both the selected map and the multibox
188
227
  $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.DESELECT_BUTTON_ID).onClick(async () => {
189
-
190
228
  const fieldId = itemData.fieldId;
191
229
  const valueId = itemData.valueId;
192
230
  dontUpdateThisCheckBox=fieldId;
193
231
  if (!fieldId || !valueId) return;
194
-
195
232
  const existing = selectedByField.get(fieldId) || [];
196
233
  const updated = existing.filter(v => v !== valueId);
234
+ const field=getFieldById(fieldId,allfields);
235
+ let fieldTitle=field.title.toLowerCase().replace(' ', '');
236
+ fieldTitle==="brands"? fieldTitle="brand":fieldTitle;
197
237
  if (updated.length) {
198
238
  selectedByField.set(fieldId, updated);
239
+ queryParams.add({ [fieldTitle] : updated.map(val=>encodeURIComponent(val)).join(',') });
199
240
  } else {
200
241
  selectedByField.delete(fieldId);
242
+ queryParams.remove([fieldTitle ]);
201
243
  }
202
-
203
- const field=getFieldById(fieldId,allfields);
204
244
  const currentVals = _$w(`#${FiltersIds[field.title]}CheckBox`).value || [];
205
245
  const nextVals = currentVals.filter(v => v !== valueId);
206
246
  _$w(`#${FiltersIds[field.title]}CheckBox`).value = nextVals;
@@ -247,8 +287,8 @@ async function loadJobsRepeater(_$w) {
247
287
 
248
288
  const jobsFirstPage=alljobs.slice(0,pagination.pageSize);
249
289
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
250
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = jobsFirstPage.length.toString();
251
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = currentJobs.length.toString();
290
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = "1"
291
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = Math.ceil(currentJobs.length/pagination.pageSize).toString();
252
292
  updateTotalJobsCountText(_$w);
253
293
  handlePaginationButtons(_$w);
254
294
  } catch (error) {
@@ -289,28 +329,35 @@ async function loadJobsRepeater(_$w) {
289
329
  else{
290
330
  originalOptions=value
291
331
  }
292
-
293
332
  optionsByFieldId.set(key, originalOptions);
294
333
  for (const val of allvaluesobjects) {
295
334
  counter[val.title]=val.count
296
335
  }
297
-
298
336
  countsByFieldId.set(key, new Map(originalOptions.map(o => [o.value, counter[o.label]])));
299
337
  updateOptionsUI(_$w,field.title, field._id, ''); // no search query
300
338
  _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = []; // start empty
301
339
  _$w(`#${FiltersIds[field.title]}CheckBox`).onChange(async (ev) => {
302
- console.log("i am here !!!!!")
303
- console.log("field.title: ",field.title)
304
- console.log("value: ",value)
305
340
  dontUpdateThisCheckBox=field._id;
306
341
  const selected = ev.target.value; // array of selected value IDs
307
- console.log("ev: ",ev)
308
- console.log("ev.target: ",ev.target)
342
+ let fieldTitle=field.title.toLowerCase().replace(' ', '');
343
+ fieldTitle==="brands"? fieldTitle="brand":fieldTitle;
344
+
309
345
  if (selected && selected.length) {
310
346
  selectedByField.set(field._id, selected);
347
+ if(fieldTitle==="brand" || fieldTitle==="storename") {
348
+ //in this case we need the label not valueid
349
+ const valueLabels=getValueFromValueId(selected,value);
350
+ queryParams.add({ [fieldTitle] : valueLabels.map(val=>encodeURIComponent(val)).join(',') });
351
+ }
352
+ else{
353
+ queryParams.add({ [fieldTitle] : selected.map(val=>encodeURIComponent(val)).join(',') });
354
+ }
355
+
311
356
  } else {
312
357
  selectedByField.delete(field._id);
358
+ queryParams.remove([fieldTitle ]);
313
359
  }
360
+
314
361
  await updateJobsAndNumbersAndFilters(_$w);
315
362
 
316
363
  });
@@ -328,8 +375,18 @@ async function loadJobsRepeater(_$w) {
328
375
  }
329
376
  }
330
377
 
378
+ function getValueFromValueId(valueIds,value) {
379
+ let valueLabels=[];
380
+ let currentVal
381
+ for(const valueId of valueIds) {
382
+ currentVal=value.find(val=>val.value===valueId);
383
+ if(currentVal) {
384
+ valueLabels.push(currentVal.label);
385
+ }
386
+ }
387
+ return valueLabels
388
+ }
331
389
 
332
-
333
390
  async function updateJobsAndNumbersAndFilters(_$w,clearAll=false) {
334
391
  await applyJobFilters(_$w); // re-query jobs
335
392
  await refreshFacetCounts(_$w,clearAll); // recompute and update counts in all lists
@@ -340,7 +397,6 @@ async function loadJobsRepeater(_$w) {
340
397
  function updateOptionsUI(_$w,fieldTitle, fieldId, searchQuery,clearAll=false) {
341
398
  let base = optionsByFieldId.get(fieldId) || [];
342
399
  const countsMap = countsByFieldId.get(fieldId) || new Map();
343
-
344
400
  if(dontUpdateThisCheckBox===fieldId && !clearAll)
345
401
  {
346
402
  dontUpdateThisCheckBox=null;
@@ -416,12 +472,15 @@ async function loadJobsRepeater(_$w) {
416
472
  finalFilteredJobs=tempFilteredJobs;
417
473
  tempFilteredJobs=[];
418
474
  }
475
+
419
476
  secondarySearchIsFilled? currentSecondarySearchJobs=finalFilteredJobs:currentJobs=finalFilteredJobs;
477
+
478
+
420
479
  let jobsFirstPage=[];
421
480
  secondarySearchIsFilled? jobsFirstPage=currentSecondarySearchJobs.slice(0,pagination.pageSize):jobsFirstPage=currentJobs.slice(0,pagination.pageSize);
422
481
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
423
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = jobsFirstPage.length.toString();
424
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = secondarySearchIsFilled? currentSecondarySearchJobs.length.toString():currentJobs.length.toString();
482
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = "1";
483
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = secondarySearchIsFilled? Math.ceil(currentSecondarySearchJobs.length/pagination.pageSize).toString():Math.ceil(currentJobs.length/pagination.pageSize).toString();
425
484
  if(jobsFirstPage.length===0) {
426
485
  await _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_MULTI_STATE_BOX).changeState("noJobs");
427
486
  }
@@ -467,6 +526,7 @@ async function refreshFacetCounts(_$w,clearAll=false) {
467
526
 
468
527
  secondarySearchIsFilled? countJobsPerField(currentSecondarySearchJobs):countJobsPerField(currentJobs);
469
528
  for(const field of allfields) {
529
+
470
530
  const query = (_$w(`#${FiltersIds[field.title]}input`).value || '').toLowerCase().trim();
471
531
  clearAll? updateOptionsUI(_$w,field.title, field._id, '',true):updateOptionsUI(_$w,field.title, field._id, query);
472
532
  // no search query
@@ -519,9 +579,10 @@ async function secondarySearch(_$w,query) {
519
579
  currentSecondarySearchJobs=allsecondarySearchJobs;
520
580
  const jobsFirstPage=allsecondarySearchJobs.slice(0,pagination.pageSize);
521
581
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
522
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = jobsFirstPage.length.toString();
523
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = allsecondarySearchJobs.length.toString();
582
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = "1";
583
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = Math.ceil(allsecondarySearchJobs.length/pagination.pageSize).toString();
524
584
  pagination.currentPage=1;
585
+
525
586
  if(jobsFirstPage.length===0) {
526
587
  await _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_MULTI_STATE_BOX).changeState("noJobs");
527
588
  }
@@ -2,6 +2,7 @@ const { items: wixData } = require('@wix/data');
2
2
  const { JOBS_COLLECTION_FIELDS,COLLECTIONS } = require('../backend/collectionConsts');
3
3
  const { CAREERS_MULTI_BOXES_PAGE_CONSTS,CATEGORY_CUSTOM_FIELD_ID_IN_CMS } = require('../backend/careersMultiBoxesPageIds');
4
4
  const { location } = require("@wix/site-location");
5
+ const { normalizeString } = require('../backend/utils');
5
6
 
6
7
  function groupValuesByField(values, refKey) {
7
8
  const map = new Map();
@@ -62,14 +63,19 @@ function groupValuesByField(values, refKey) {
62
63
  return allFields.find(field=>field.title===title);
63
64
  }
64
65
 
65
- function getCorrectOption(value,options) {
66
- const standardizedValue = value.toLowerCase().trim().replace(/[^a-z0-9]/gi, '');
67
- return options.find(option=>option.label.toLowerCase().trim().replace(/[^a-z0-9]/gi, '')===standardizedValue);
66
+ function getCorrectOption(value,options,param) {
67
+ const standardizedValue = normalizeString(value.toLowerCase())
68
+ if(param==="employmenttype") //employmenttype have a problematic value
69
+ {
70
+ return options.find(option=>normalizeString(option.value.toLowerCase())===standardizedValue);
71
+ }
72
+ return options.find(option=>normalizeString(option.label.toLowerCase())===standardizedValue);
68
73
  }
69
74
 
70
75
  function getOptionIndexFromCheckBox(options,value) {
76
+ const normalizedValue=normalizeString(value.toLowerCase());
71
77
  for(let index=0;index<options.length;index++) {
72
- if(options[index].value===value) {
78
+ if(normalizeString(options[index].value.toLowerCase())===normalizedValue) {
73
79
  return index;
74
80
  }
75
81
  }
@@ -85,7 +91,10 @@ function loadPrimarySearchRepeater(_$w) {
85
91
  const data = _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
86
92
  const clickedItemData = data.find(
87
93
  (item) => item._id === event.context.itemId,
94
+
88
95
  );
96
+ console.log("clickedItemData: ",clickedItemData);
97
+ console.log("clickedItemData['link-jobs-title']: ",clickedItemData["link-jobs-title"]);
89
98
  location.to(clickedItemData["link-jobs-title"]);
90
99
  });
91
100
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).onItemReady(async ($item, itemData) => {
@@ -109,7 +118,7 @@ function loadPrimarySearchRepeater(_$w) {
109
118
  const primarySearchDebounced = debounce(async () => {
110
119
  const query = (_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value || '').toLowerCase().trim();
111
120
  await primarySearch(_$w, query, alljobs);
112
- }, 150);
121
+ }, 300);
113
122
 
114
123
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onInput(async () => {
115
124
  await primarySearchDebounced();
@@ -1,3 +1,22 @@
1
+ jest.mock('wix-location-frontend');
2
+ jest.mock('@wix/site-location', () => ({
3
+ location: {
4
+ to: jest.fn()
5
+ }
6
+ }));
7
+ jest.mock('@wix/data', () => ({
8
+ items: {
9
+ query: jest.fn(() => ({
10
+ eq: jest.fn().mockReturnThis(),
11
+ find: jest.fn().mockResolvedValue({ items: [] }),
12
+ include: jest.fn().mockReturnThis(),
13
+ hasSome: jest.fn().mockReturnThis(),
14
+ ne: jest.fn().mockReturnThis(),
15
+ limit: jest.fn().mockReturnThis()
16
+ })),
17
+ queryReferenced: jest.fn()
18
+ }
19
+ }));
1
20
  const rewire = require('rewire');
2
21
  const MockJobBuilder = require('./mockJobBuilder');
3
22
  const { CAREERS_MULTI_BOXES_PAGE_CONSTS, CATEGORY_CUSTOM_FIELD_ID_IN_CMS } = require('../backend/careersMultiBoxesPageIds');
@@ -9,7 +28,13 @@ const pagesUtils = rewire('../pages/pagesUtils');
9
28
  const secondarySearch = careersMultiBoxesPage.__get__('secondarySearch');
10
29
  const primarySearch = pagesUtils.__get__('primarySearch');
11
30
  const loadCategoriesListPrimarySearch = pagesUtils.__get__('loadCategoriesListPrimarySearch');
12
-
31
+ const mockQueryParams = {
32
+ add: jest.fn(),
33
+ remove: jest.fn()
34
+ };
35
+ const mockOnChange = jest.fn();
36
+ careersMultiBoxesPage.__set__('queryParams', mockQueryParams);
37
+ careersMultiBoxesPage.__set__('onChange', mockOnChange);
13
38
 
14
39
  describe('secondarySearch function tests', () => {
15
40
  let mockW;
@@ -79,13 +104,11 @@ describe('secondarySearch function tests', () => {
79
104
  mockJobs.push(new MockJobBuilder().withTitle('Frontend Engineer').build());
80
105
 
81
106
  careersMultiBoxesPage.__set__('currentJobs', mockJobs);
82
-
83
107
  const result = await secondarySearch(mockW, 'product');
84
-
85
108
  expect(result.length).toBe(11);
86
109
  expect(mockTotalJobsCountText.text).toContain('11');
87
- expect(mockPaginationCurrentText.text).toBe('10');
88
- expect(mockPaginationTotalCountText.text).toBe('11');
110
+ expect(mockPaginationCurrentText.text).toBe('1');
111
+ expect(mockPaginationTotalCountText.text).toBe('2');
89
112
  expect(mockPageButtonNext.enable).toHaveBeenCalled();
90
113
  expect(mockPageButtonPrevious.disable).toHaveBeenCalled();
91
114
  });