sr-npm 1.7.771 → 1.7.772

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.771",
3
+ "version": "1.7.772",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -341,30 +341,30 @@ async function loadJobsRepeater(_$w) {
341
341
  if(keyword) {
342
342
  finalFilteredJobs=currentJobs
343
343
  }
344
- let addedJobsIds=[]
344
+ let addedJobsIds=new Set();
345
345
  // AND across categories, OR within each category
346
346
  for (const [key, values] of selectedByField.entries()) {
347
347
  for(const job of finalFilteredJobs) {
348
348
  if(key==="Location"){
349
349
  //if it is location then we check if selecred values (which is an array) have job city text
350
350
  if(values.includes(job[JOBS_COLLECTION_FIELDS.CITY_TEXT])) {
351
- if(!addedJobsIds.includes(job._id)) {
351
+ if(!addedJobsIds.has(job._id)) {
352
352
  tempFilteredJobs.push(job);
353
- addedJobsIds.push(job._id);
353
+ addedJobsIds.add(job._id);
354
354
  }
355
355
  }
356
356
  }
357
357
  else{
358
358
  //if it is not location then we check if selecred values (which is an array) have one of the job values (whcih is also an array)
359
359
  if(job[JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES].some(value=>values.includes(value._id))) {
360
- if(!addedJobsIds.includes(job._id)) {
360
+ if(!addedJobsIds.has(job._id)) {
361
361
  tempFilteredJobs.push(job);
362
- addedJobsIds.push(job._id);
362
+ addedJobsIds.add(job._id);
363
363
  }
364
364
  }
365
365
  }
366
366
  }
367
- addedJobsIds=[]
367
+ addedJobsIds.clear();
368
368
  finalFilteredJobs=tempFilteredJobs;
369
369
  tempFilteredJobs=[];
370
370
  }
@@ -1,9 +1,40 @@
1
1
  const rewire = require('rewire');
2
2
  const MockJobBuilder = require('./mockJobBuilder');
3
- const { CAREERS_MULTI_BOXES_PAGE_CONSTS } = require('../backend/careersMultiBoxesPageIds');
3
+ const { CAREERS_MULTI_BOXES_PAGE_CONSTS, CATEGORY_CUSTOM_FIELD_ID_IN_CMS } = require('../backend/careersMultiBoxesPageIds');
4
+
5
+ // Mock Wix modules
6
+ const mockQueryParams = {
7
+ add: jest.fn(),
8
+ remove: jest.fn()
9
+ };
10
+
11
+ const mockLocation = {
12
+ url: 'https://test.com',
13
+ path: '/test',
14
+ query: {}
15
+ };
16
+
17
+ // Temporarily mock require for Wix modules
18
+ const Module = require('module');
19
+ const originalRequire = Module.prototype.require;
20
+ Module.prototype.require = function(id) {
21
+ if (id === 'wix-location-frontend') {
22
+ return { queryParams: mockQueryParams };
23
+ }
24
+ if (id === '@wix/site-location') {
25
+ return { location: mockLocation };
26
+ }
27
+ return originalRequire.apply(this, arguments);
28
+ };
4
29
 
5
30
  const careersMultiBoxesPage = rewire('../pages/careersMultiBoxesPage');
31
+
32
+ // Restore original require
33
+ Module.prototype.require = originalRequire;
34
+
6
35
  const secondarySearch = careersMultiBoxesPage.__get__('secondarySearch');
36
+ const primarySearch = careersMultiBoxesPage.__get__('primarySearch');
37
+ const loadCategoriesListPrimarySearch = careersMultiBoxesPage.__get__('loadCategoriesListPrimarySearch');
7
38
 
8
39
 
9
40
 
@@ -15,6 +46,7 @@ describe('secondarySearch function tests', () => {
15
46
  let mockPageButtonNext;
16
47
  let mockPageButtonPrevious;
17
48
  let mockTotalJobsCountText;
49
+ let mockJobsMultiStateBox;
18
50
 
19
51
  beforeEach(() => {
20
52
  mockJobsRepeater = { data: null };
@@ -29,6 +61,7 @@ describe('secondarySearch function tests', () => {
29
61
  disable: jest.fn()
30
62
  };
31
63
  mockTotalJobsCountText = { text: '' };
64
+ mockJobsMultiStateBox = { changeState: jest.fn() };
32
65
 
33
66
  mockW = jest.fn((selector) => {
34
67
  const mocks = {
@@ -37,7 +70,8 @@ describe('secondarySearch function tests', () => {
37
70
  [CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText]: mockPaginationTotalCountText,
38
71
  [CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_NEXT]: mockPageButtonNext,
39
72
  [CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_PREVIOUS]: mockPageButtonPrevious,
40
- [CAREERS_MULTI_BOXES_PAGE_CONSTS.TotalJobsCountText]: mockTotalJobsCountText
73
+ [CAREERS_MULTI_BOXES_PAGE_CONSTS.TotalJobsCountText]: mockTotalJobsCountText,
74
+ [CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_MULTI_STATE_BOX]: mockJobsMultiStateBox
41
75
  };
42
76
  return mocks[selector] || {
43
77
  data: null,
@@ -47,7 +81,8 @@ describe('secondarySearch function tests', () => {
47
81
  onChange: jest.fn(),
48
82
  onInput: jest.fn(),
49
83
  enable: jest.fn(),
50
- disable: jest.fn()
84
+ disable: jest.fn(),
85
+ changeState: jest.fn()
51
86
  };
52
87
  });
53
88
  });
@@ -57,7 +92,7 @@ describe('secondarySearch function tests', () => {
57
92
  careersMultiBoxesPage.__set__('currentJobs', []);
58
93
  });
59
94
 
60
- it('should return count > 0 when searching for existing job title', () => {
95
+ it('should return count > 0 when searching for existing job title', async () => {
61
96
 
62
97
 
63
98
  let mockJobs = MockJobBuilder.createMultiple(11, (builder, index) => {
@@ -69,27 +104,26 @@ describe('secondarySearch function tests', () => {
69
104
 
70
105
  careersMultiBoxesPage.__set__('currentJobs', mockJobs);
71
106
 
72
- const result = secondarySearch(mockW, 'product');
107
+ const result = await secondarySearch(mockW, 'product');
73
108
 
74
109
  expect(result.length).toBe(11);
75
- expect(mockTotalJobsCountText.text).toContain('11 Jobs');
110
+ expect(mockTotalJobsCountText.text).toContain('11');
76
111
  expect(mockPaginationCurrentText.text).toBe('10');
77
112
  expect(mockPaginationTotalCountText.text).toBe('11');
78
113
  expect(mockPageButtonNext.enable).toHaveBeenCalled();
79
114
  expect(mockPageButtonPrevious.disable).toHaveBeenCalled();
80
115
  });
81
116
 
82
- it('should return 0 when searching for non-existing job title', () => {
117
+ it('should return 0 when searching for non-existing job title', async () => {
83
118
  let mockJobs = MockJobBuilder.createMultiple(11, (builder, index) => {
84
119
  builder.withTitle(`random job ${index}`);
85
120
  });
86
121
  careersMultiBoxesPage.__set__('currentJobs', mockJobs);
87
122
 
88
- const result = secondarySearch(mockW, 'unicorn hunter');
123
+ const result = await secondarySearch(mockW, 'unicorn hunter');
89
124
 
90
125
  expect(result.length).toBe(0);
91
126
  expect(mockTotalJobsCountText.text).toContain('0 Jobs');
92
- expect(mockPaginationCurrentText.text).toBe('0');
93
127
  expect(mockPaginationTotalCountText.text).toBe('0');
94
128
  expect(mockPageButtonNext.disable).toHaveBeenCalled();
95
129
  expect(mockPageButtonPrevious.disable).toHaveBeenCalled();
@@ -98,3 +132,75 @@ describe('secondarySearch function tests', () => {
98
132
 
99
133
  });
100
134
 
135
+
136
+ describe('primarySearch function tests', () => {
137
+ let mockW;
138
+ let mockprimarySearcJobResult;
139
+ let mockprimarySearchMultiBox;
140
+ let mockCategoryResultsRepeater;
141
+
142
+ beforeEach(() => {
143
+ mockprimarySearcJobResult = { data: null };
144
+ mockprimarySearchMultiBox = { changeState: jest.fn() };
145
+ mockCategoryResultsRepeater = { data: null };
146
+
147
+ mockW = jest.fn((selector) => {
148
+ const mocks = {
149
+ [CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER]: mockprimarySearcJobResult,
150
+ [CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX]: mockprimarySearchMultiBox,
151
+ [CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER]: mockCategoryResultsRepeater
152
+ };
153
+ return mocks[selector]
154
+ });
155
+ });
156
+
157
+ afterEach(() => {
158
+ jest.clearAllMocks();
159
+ careersMultiBoxesPage.__set__('currentJobs', []);
160
+ });
161
+
162
+ it('should show job results for existing job title', async () => {
163
+ let mockJobs = MockJobBuilder.createMultiple(11, (builder, index) => {
164
+ builder.withTitle(`Product Manager ${index}`);
165
+ });
166
+ careersMultiBoxesPage.__set__('alljobs', mockJobs);
167
+
168
+ await primarySearch(mockW, 'product');
169
+
170
+ expect(mockprimarySearchMultiBox.changeState).toHaveBeenCalledWith('jobResults');
171
+ expect(mockprimarySearcJobResult.data).toHaveLength(11);
172
+ expect(mockprimarySearcJobResult.data).toEqual(mockJobs);
173
+ });
174
+
175
+ it('should show no results for non-existing job title', async () => {
176
+ let mockJobs = MockJobBuilder.createMultiple(11, (builder, index) => {
177
+ builder.withTitle(`Product Manager ${index}`);
178
+ });
179
+ careersMultiBoxesPage.__set__('alljobs', mockJobs);
180
+
181
+ await primarySearch(mockW, 'unicorn hunter');
182
+
183
+ expect(mockprimarySearchMultiBox.changeState).toHaveBeenCalledWith('noResults');
184
+ expect(mockprimarySearcJobResult.data).toBeNull();
185
+ });
186
+
187
+ it('should fill category repeater when clicking on empty primary search input', async () => {
188
+ const mockCategoryValues = [
189
+ { _id: 'cat1', title: 'Engineering', customField: CATEGORY_CUSTOM_FIELD_ID_IN_CMS, totalJobs: 5 },
190
+ { _id: 'cat2', title: 'Marketing', customField: CATEGORY_CUSTOM_FIELD_ID_IN_CMS, totalJobs: 3 },
191
+ { _id: 'cat3', title: 'Sales', customField: CATEGORY_CUSTOM_FIELD_ID_IN_CMS, totalJobs: 7 }
192
+ ];
193
+
194
+ careersMultiBoxesPage.__set__('allvaluesobjects', mockCategoryValues);
195
+
196
+ await loadCategoriesListPrimarySearch(mockW);
197
+
198
+ expect(mockprimarySearchMultiBox.changeState).toHaveBeenCalledWith('categoryResults');
199
+ expect(mockCategoryResultsRepeater.data).toHaveLength(3);
200
+ expect(mockCategoryResultsRepeater.data[0].title).toContain('Engineering (5)');
201
+ expect(mockCategoryResultsRepeater.data[1].title).toContain('Marketing (3)');
202
+ expect(mockCategoryResultsRepeater.data[2].title).toContain('Sales (7)');
203
+ });
204
+
205
+ });
206
+