sr-npm 2.0.19 → 2.1.0

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.1.0",
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,13 +24,18 @@ const pagination = {
22
24
  currentPage: 1,
23
25
  };
24
26
  async function careersMultiBoxesPageOnReady(_$w,urlParams) {
25
- await loadData(_$w);
26
- loadJobsRepeater(_$w);
27
- loadPrimarySearchRepeater(_$w);
28
- await loadFilters(_$w);
29
- loadSelectedValuesRepeater(_$w);
30
- bindSearchInput(_$w);
31
- loadPaginationButtons(_$w);
27
+ //to handle back and forth , url changes
28
+ onChange(async ()=>{
29
+ await handleBackAndForth(_$w);
30
+ });
31
+
32
+ await loadData(_$w);
33
+ loadJobsRepeater(_$w);
34
+ loadPrimarySearchRepeater(_$w);
35
+ await loadFilters(_$w);
36
+ loadSelectedValuesRepeater(_$w);
37
+ bindSearchInput(_$w);
38
+ loadPaginationButtons(_$w);
32
39
 
33
40
  if (await window.formFactor() === "Mobile") {
34
41
  handleFilterInMobile(_$w);
@@ -41,7 +48,15 @@ async function careersMultiBoxesPageOnReady(_$w,urlParams) {
41
48
 
42
49
  }
43
50
 
44
- async function clearAll(_$w) {
51
+ async function handleBackAndForth(_$w){
52
+ const newQueryParams=await location.query();
53
+ console.log("newQueryParams: ", newQueryParams);
54
+ await clearAll(_$w,true);
55
+ await handleUrlParams(_$w,newQueryParams);
56
+
57
+ }
58
+
59
+ async function clearAll(_$w,urlOnChange=false) {
45
60
  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
61
  for(const field of allfields) {
47
62
  _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = [];
@@ -52,6 +67,9 @@ async function clearAll(_$w) {
52
67
  secondarySearchIsFilled=false;
53
68
  currentJobs=alljobs;
54
69
  keywordAllJobs=undefined;
70
+ if(!urlOnChange) {
71
+ queryParams.remove(possibleUrlParams.concat(["keyword", "page"]));
72
+ }
55
73
  await updateJobsAndNumbersAndFilters(_$w,true);
56
74
  }
57
75
  }
@@ -95,26 +113,30 @@ function handleFilterInMobile(_$w) {
95
113
  async function handleUrlParams(_$w,urlParams) {
96
114
  try {
97
115
  let applyFiltering=false;
98
-
116
+ let currentApplyFilterFlag=false;
117
+ //apply this first to determine all jobs
99
118
  if(urlParams.keyword) {
100
119
  applyFiltering=await primarySearch(_$w, decodeURIComponent(urlParams.keyword), alljobs);
101
120
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value=decodeURIComponent(urlParams.keyword);
102
121
  currentJobs=_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
103
122
  keywordAllJobs=_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
104
123
  }
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)
124
+
125
+ for (const url of possibleUrlParams)
126
+ {
127
+ if(urlParams[url])
128
+ {
129
+ currentApplyFilterFlag=await handleParams(_$w,url,urlParams[url])
130
+ if(currentApplyFilterFlag) {
131
+ applyFiltering=true;
132
+ }
113
133
  }
114
-
134
+ currentApplyFilterFlag=false;
135
+ }
115
136
  if(applyFiltering || keywordAllJobs) {
116
137
  await updateJobsAndNumbersAndFilters(_$w);
117
138
  }
139
+
118
140
  if(urlParams.page) {
119
141
  if(Number.isNaN(Number(urlParams.page)) || Number(urlParams.page)<=1 || Number(urlParams.page)>Math.ceil(currentJobs.length/pagination.pageSize)) {
120
142
  console.warn("page number is invalid, removing page from url");
@@ -122,14 +144,14 @@ async function handleUrlParams(_$w,urlParams) {
122
144
  return;
123
145
  }
124
146
  pagination.currentPage=Number(urlParams.page);
125
- let paginationCurrentText=Number(urlParams.page)*pagination.pageSize
147
+ //let paginationCurrentText=urlParams.page;
126
148
  let startSlicIndex=pagination.pageSize*(pagination.currentPage-1);
127
149
  let endSlicIndex=(pagination.pageSize)*(pagination.currentPage);
128
150
  if(Number(urlParams.page)==Math.ceil(currentJobs.length/pagination.pageSize)) {
129
- paginationCurrentText=paginationCurrentText-(pagination.pageSize-(currentJobs.length%pagination.pageSize));
151
+ // paginationCurrentText=(paginationCurrentText-(pagination.pageSize-(currentJobs.length%pagination.pageSize))).toString();
130
152
  endSlicIndex=currentJobs.length;
131
153
  }
132
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = paginationCurrentText.toString();
154
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = urlParams.page
133
155
  const jobsFirstPage=currentJobs.slice(startSlicIndex,endSlicIndex);
134
156
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
135
157
  handlePaginationButtons(_$w);
@@ -139,31 +161,49 @@ async function handleUrlParams(_$w,urlParams) {
139
161
  }
140
162
  }
141
163
 
142
- async function handleParams(_$w,param,value) {
164
+ async function handleParams(_$w,param,values) {
143
165
  let applyFiltering=false;
166
+ let valuesAsArray = values.split(',')
167
+ valuesAsArray=valuesAsArray.filter(value=>value.trim()!=='');
168
+
169
+ let selectedIndices=[];
170
+ const field=getFieldByTitle(fieldTitlesInCMS[param],allfields);
171
+
172
+ let existing = selectedByField.get(field._id) || [];
173
+ for(const value of valuesAsArray) {
174
+
144
175
  const decodedValue = decodeURIComponent(value);
145
- const field=getFieldByTitle(fieldTitlesInCMS[param],allfields);
176
+
146
177
  const options=optionsByFieldId.get(field._id);
147
- const option=getCorrectOption(decodedValue,options);
178
+
179
+ const option=getCorrectOption(decodedValue,options,param);
180
+
148
181
  if(option) {
149
182
  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]);
183
+ selectedIndices.push(optionIndex);
184
+ existing.push(option.value);
152
185
  applyFiltering=true;
153
186
  dontUpdateThisCheckBox=field._id;
154
187
  }
155
188
  else {
156
189
  console.warn(`${param} value not found in dropdown options`);
157
190
  }
158
- return applyFiltering;
191
+ }
192
+
193
+ selectedByField.set(field._id, existing);
194
+ _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices=selectedIndices;
195
+
196
+ return applyFiltering;
197
+
159
198
  }
160
199
 
161
200
  function loadPaginationButtons(_$w) {
162
201
  try {
163
202
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_NEXT).onClick(async () => {
164
203
  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();
204
+
166
205
  pagination.currentPage++;
206
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = pagination.currentPage.toString();
167
207
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = nextPageJobs;
168
208
  handlePaginationButtons(_$w);
169
209
  });
@@ -171,7 +211,7 @@ async function handleParams(_$w,param,value) {
171
211
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_PREVIOUS).onClick(async () => {
172
212
  let previousPageJobs=currentJobs.slice(pagination.pageSize*(pagination.currentPage-2),pagination.pageSize*(pagination.currentPage-1));
173
213
  pagination.currentPage--;
174
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = (pagination.pageSize*pagination.currentPage).toString();
214
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = pagination.currentPage.toString();
175
215
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = previousPageJobs;
176
216
  handlePaginationButtons(_$w);
177
217
  });
@@ -186,21 +226,22 @@ async function handleParams(_$w,param,value) {
186
226
  $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.SELECTED_VALUES_REPEATER_ITEM_LABEL).text = itemData.label || '';
187
227
  // Deselect this value from both the selected map and the multibox
188
228
  $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.DESELECT_BUTTON_ID).onClick(async () => {
189
-
190
229
  const fieldId = itemData.fieldId;
191
230
  const valueId = itemData.valueId;
192
231
  dontUpdateThisCheckBox=fieldId;
193
232
  if (!fieldId || !valueId) return;
194
-
195
233
  const existing = selectedByField.get(fieldId) || [];
196
234
  const updated = existing.filter(v => v !== valueId);
235
+ const field=getFieldById(fieldId,allfields);
236
+ let fieldTitle=field.title.toLowerCase().replace(' ', '');
237
+ fieldTitle==="brands"? fieldTitle="brand":fieldTitle;
197
238
  if (updated.length) {
198
239
  selectedByField.set(fieldId, updated);
240
+ queryParams.add({ [fieldTitle] : updated.map(val=>encodeURIComponent(val)).join(',') });
199
241
  } else {
200
242
  selectedByField.delete(fieldId);
243
+ queryParams.remove([fieldTitle ]);
201
244
  }
202
-
203
- const field=getFieldById(fieldId,allfields);
204
245
  const currentVals = _$w(`#${FiltersIds[field.title]}CheckBox`).value || [];
205
246
  const nextVals = currentVals.filter(v => v !== valueId);
206
247
  _$w(`#${FiltersIds[field.title]}CheckBox`).value = nextVals;
@@ -247,8 +288,8 @@ async function loadJobsRepeater(_$w) {
247
288
 
248
289
  const jobsFirstPage=alljobs.slice(0,pagination.pageSize);
249
290
  _$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();
291
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = "1"
292
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = Math.ceil(currentJobs.length/pagination.pageSize).toString();
252
293
  updateTotalJobsCountText(_$w);
253
294
  handlePaginationButtons(_$w);
254
295
  } catch (error) {
@@ -289,28 +330,35 @@ async function loadJobsRepeater(_$w) {
289
330
  else{
290
331
  originalOptions=value
291
332
  }
292
-
293
333
  optionsByFieldId.set(key, originalOptions);
294
334
  for (const val of allvaluesobjects) {
295
335
  counter[val.title]=val.count
296
336
  }
297
-
298
337
  countsByFieldId.set(key, new Map(originalOptions.map(o => [o.value, counter[o.label]])));
299
338
  updateOptionsUI(_$w,field.title, field._id, ''); // no search query
300
339
  _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = []; // start empty
301
340
  _$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
341
  dontUpdateThisCheckBox=field._id;
306
342
  const selected = ev.target.value; // array of selected value IDs
307
- console.log("ev: ",ev)
308
- console.log("ev.target: ",ev.target)
343
+ let fieldTitle=field.title.toLowerCase().replace(' ', '');
344
+ fieldTitle==="brands"? fieldTitle="brand":fieldTitle;
345
+
309
346
  if (selected && selected.length) {
310
347
  selectedByField.set(field._id, selected);
348
+ if(fieldTitle==="brand" || fieldTitle==="storename") {
349
+ //in this case we need the label not valueid
350
+ const valueLabels=getValueFromValueId(selected,value);
351
+ queryParams.add({ [fieldTitle] : valueLabels.map(val=>encodeURIComponent(val)).join(',') });
352
+ }
353
+ else{
354
+ queryParams.add({ [fieldTitle] : selected.map(val=>encodeURIComponent(val)).join(',') });
355
+ }
356
+
311
357
  } else {
312
358
  selectedByField.delete(field._id);
359
+ queryParams.remove([fieldTitle ]);
313
360
  }
361
+
314
362
  await updateJobsAndNumbersAndFilters(_$w);
315
363
 
316
364
  });
@@ -328,8 +376,18 @@ async function loadJobsRepeater(_$w) {
328
376
  }
329
377
  }
330
378
 
379
+ function getValueFromValueId(valueIds,value) {
380
+ let valueLabels=[];
381
+ let currentVal
382
+ for(const valueId of valueIds) {
383
+ currentVal=value.find(val=>val.value===valueId);
384
+ if(currentVal) {
385
+ valueLabels.push(currentVal.label);
386
+ }
387
+ }
388
+ return valueLabels
389
+ }
331
390
 
332
-
333
391
  async function updateJobsAndNumbersAndFilters(_$w,clearAll=false) {
334
392
  await applyJobFilters(_$w); // re-query jobs
335
393
  await refreshFacetCounts(_$w,clearAll); // recompute and update counts in all lists
@@ -340,7 +398,6 @@ async function loadJobsRepeater(_$w) {
340
398
  function updateOptionsUI(_$w,fieldTitle, fieldId, searchQuery,clearAll=false) {
341
399
  let base = optionsByFieldId.get(fieldId) || [];
342
400
  const countsMap = countsByFieldId.get(fieldId) || new Map();
343
-
344
401
  if(dontUpdateThisCheckBox===fieldId && !clearAll)
345
402
  {
346
403
  dontUpdateThisCheckBox=null;
@@ -416,12 +473,15 @@ async function loadJobsRepeater(_$w) {
416
473
  finalFilteredJobs=tempFilteredJobs;
417
474
  tempFilteredJobs=[];
418
475
  }
476
+
419
477
  secondarySearchIsFilled? currentSecondarySearchJobs=finalFilteredJobs:currentJobs=finalFilteredJobs;
478
+
479
+
420
480
  let jobsFirstPage=[];
421
481
  secondarySearchIsFilled? jobsFirstPage=currentSecondarySearchJobs.slice(0,pagination.pageSize):jobsFirstPage=currentJobs.slice(0,pagination.pageSize);
422
482
  _$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();
483
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = "1";
484
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = secondarySearchIsFilled? Math.ceil(currentSecondarySearchJobs.length/pagination.pageSize).toString():Math.ceil(currentJobs.length/pagination.pageSize).toString();
425
485
  if(jobsFirstPage.length===0) {
426
486
  await _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_MULTI_STATE_BOX).changeState("noJobs");
427
487
  }
@@ -467,6 +527,7 @@ async function refreshFacetCounts(_$w,clearAll=false) {
467
527
 
468
528
  secondarySearchIsFilled? countJobsPerField(currentSecondarySearchJobs):countJobsPerField(currentJobs);
469
529
  for(const field of allfields) {
530
+
470
531
  const query = (_$w(`#${FiltersIds[field.title]}input`).value || '').toLowerCase().trim();
471
532
  clearAll? updateOptionsUI(_$w,field.title, field._id, '',true):updateOptionsUI(_$w,field.title, field._id, query);
472
533
  // no search query
@@ -519,9 +580,10 @@ async function secondarySearch(_$w,query) {
519
580
  currentSecondarySearchJobs=allsecondarySearchJobs;
520
581
  const jobsFirstPage=allsecondarySearchJobs.slice(0,pagination.pageSize);
521
582
  _$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();
583
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = "1";
584
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = Math.ceil(allsecondarySearchJobs.length/pagination.pageSize).toString();
524
585
  pagination.currentPage=1;
586
+
525
587
  if(jobsFirstPage.length===0) {
526
588
  await _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_MULTI_STATE_BOX).changeState("noJobs");
527
589
  }
@@ -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
  });