sr-npm 1.7.724 → 1.7.726
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 +3 -2
- package/pages/careersMultiBoxesPage.js +38 -10
- package/tests/mockJobBuilder.js +182 -0
- package/tests/multiSearchBoxCareers.spec.js +94 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sr-npm",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.726",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@eslint/js": "^9.39.0",
|
|
32
32
|
"eslint": "^9.38.0",
|
|
33
33
|
"globals": "^16.4.0",
|
|
34
|
-
"prettier": "^3.6.2"
|
|
34
|
+
"prettier": "^3.6.2",
|
|
35
|
+
"rewire": "^9.0.1"
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { COLLECTIONS,CUSTOM_VALUES_COLLECTION_FIELDS,JOBS_COLLECTION_FIELDS } = require('../backend/collectionConsts');
|
|
2
|
+
const { queryParams } = require('wix-location-frontend');
|
|
2
3
|
const {CAREERS_MULTI_BOXES_PAGE_CONSTS,FiltersIds,fieldTitlesInCMS} = require('../backend/careersMultiBoxesPageIds');
|
|
3
|
-
const { query,queryParams,onChange} = require("wix-location-frontend");
|
|
4
4
|
const { groupValuesByField, debounce, getAllRecords, getFieldById, getFieldByTitle,getCorrectOption,getOptionIndexFromCheckBox } = require('./pagesUtils');
|
|
5
5
|
|
|
6
6
|
let dontUpdateThisCheckBox;
|
|
@@ -51,6 +51,26 @@ async function handleUrlParams(_$w,urlParams) {
|
|
|
51
51
|
if(applyFiltering) {
|
|
52
52
|
await updateJobsAndNumbersAndFilters(_$w);
|
|
53
53
|
}
|
|
54
|
+
if(urlParams.page) {
|
|
55
|
+
console.log("urlParams.page: ", urlParams.page);
|
|
56
|
+
if(Number.isNaN(Number(urlParams.page)) || Number(urlParams.page)<=1 || Number(urlParams.page)>Math.ceil(currentJobs.length/pagination.pageSize)) {
|
|
57
|
+
console.log("page number is invalid, removing page from url");
|
|
58
|
+
queryParams.remove(["page"]);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
console.log("(Number(urlParams.page)*pagination.pageSize).toString(); ", (Number(urlParams.page)*pagination.pageSize).toString());
|
|
63
|
+
let paginationCurrentText=Number(urlParams.page)*pagination.pageSize
|
|
64
|
+
if(Number(urlParams.page)==Math.ceil(currentJobs.length/pagination.pageSize)) {
|
|
65
|
+
console.log("last page, subtracting the remaining jobs from the pagination current text");
|
|
66
|
+
paginationCurrentText=paginationCurrentText-(currentJobs.length%pagination.pageSize);
|
|
67
|
+
}
|
|
68
|
+
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = paginationCurrentText.toString();
|
|
69
|
+
pagination.currentPage=Number(urlParams.page);
|
|
70
|
+
const jobsFirstPage=currentJobs.slice(pagination.pageSize*(pagination.currentPage),pagination.pageSize*pagination.currentPage);
|
|
71
|
+
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
|
|
72
|
+
handlePaginationButtons(_$w);
|
|
73
|
+
}
|
|
54
74
|
}
|
|
55
75
|
|
|
56
76
|
async function handleParams(_$w,param,value) {
|
|
@@ -314,14 +334,26 @@ async function loadJobsRepeater(_$w) {
|
|
|
314
334
|
|
|
315
335
|
function handlePaginationButtons(_$w,secondarySearch=false)
|
|
316
336
|
{
|
|
337
|
+
handlePageUrlParam();
|
|
317
338
|
pagination.currentPage===1? _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_PREVIOUS).disable():_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_PREVIOUS).enable();
|
|
318
339
|
if(secondarySearch) {
|
|
319
|
-
pagination.currentPage
|
|
340
|
+
pagination.currentPage>=Math.ceil(secondarySearchJobs.length/pagination.pageSize)? _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_NEXT).disable():_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_NEXT).enable();
|
|
320
341
|
}
|
|
321
342
|
else {
|
|
322
|
-
pagination.currentPage
|
|
343
|
+
pagination.currentPage>=Math.ceil(currentJobs.length/pagination.pageSize)? _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_NEXT).disable():_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_NEXT).enable();
|
|
323
344
|
}
|
|
324
345
|
}
|
|
346
|
+
|
|
347
|
+
function handlePageUrlParam() {
|
|
348
|
+
if(pagination.currentPage==1)
|
|
349
|
+
{
|
|
350
|
+
queryParams.remove(["page"]);
|
|
351
|
+
}
|
|
352
|
+
else{
|
|
353
|
+
queryParams.add({ page: pagination.currentPage });
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
}
|
|
325
357
|
async function refreshFacetCounts(_$w,clearAll=false) {
|
|
326
358
|
const fieldIds = Array.from(optionsByFieldId.keys());
|
|
327
359
|
const currentJobsIds=currentJobs.map(job=>job._id);
|
|
@@ -365,26 +397,21 @@ function primarySearch(_$w,query) {
|
|
|
365
397
|
console.log("primary search query: ", query);
|
|
366
398
|
}
|
|
367
399
|
function secondarySearch(_$w,query) {
|
|
368
|
-
console.log("secondary search query: ", query);
|
|
369
400
|
if(query.length===0) {
|
|
370
401
|
secondarySearchJobs=currentJobs;
|
|
371
402
|
}
|
|
372
403
|
else {
|
|
373
404
|
secondarySearchJobs=currentJobs.filter(job=>job.title.toLowerCase().includes(query));
|
|
374
405
|
}
|
|
375
|
-
console.log("current jobs length: ", currentJobs.length);
|
|
376
|
-
console.log("current jobs: ", currentJobs);
|
|
377
406
|
|
|
378
407
|
const jobsFirstPage=secondarySearchJobs.slice(0,pagination.pageSize);
|
|
379
|
-
console.log("jobs first page: ", jobsFirstPage);
|
|
380
408
|
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
|
|
381
409
|
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = jobsFirstPage.length.toString();
|
|
382
410
|
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = secondarySearchJobs.length.toString();
|
|
383
411
|
pagination.currentPage=1;
|
|
384
412
|
handlePaginationButtons(_$w,true);
|
|
385
413
|
updateTotalJobsCountText(_$w,true);
|
|
386
|
-
|
|
387
|
-
return _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data
|
|
414
|
+
return secondarySearchJobs;
|
|
388
415
|
}
|
|
389
416
|
function bindSearchInput(_$w) {
|
|
390
417
|
const primarySearchDebounced = debounce(() => {
|
|
@@ -400,5 +427,6 @@ function secondarySearch(_$w,query) {
|
|
|
400
427
|
}
|
|
401
428
|
|
|
402
429
|
module.exports = {
|
|
403
|
-
careersMultiBoxesPageOnReady
|
|
430
|
+
careersMultiBoxesPageOnReady,
|
|
431
|
+
secondarySearch
|
|
404
432
|
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
class MockJobBuilder {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.reset();
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
reset() {
|
|
7
|
+
this.jobData = {
|
|
8
|
+
id: this.generateId(),
|
|
9
|
+
title: "Software Engineer",
|
|
10
|
+
uuid: this.generateUuid(),
|
|
11
|
+
refNumber: this.generateRefNumber(),
|
|
12
|
+
company: {
|
|
13
|
+
identifier: "TheWarehouseGroup1",
|
|
14
|
+
name: "The Warehouse Group"
|
|
15
|
+
},
|
|
16
|
+
location: {
|
|
17
|
+
city: "Auckland",
|
|
18
|
+
region: "Auckland Region",
|
|
19
|
+
country: "nz",
|
|
20
|
+
address: "123 Queen Street",
|
|
21
|
+
postalCode: "1010",
|
|
22
|
+
remote: false,
|
|
23
|
+
latitude: "-36.8484597",
|
|
24
|
+
longitude: "174.7633315",
|
|
25
|
+
fullLocation: "Auckland, Auckland Region, New Zealand"
|
|
26
|
+
},
|
|
27
|
+
employmentType: "Full-time",
|
|
28
|
+
customField: [
|
|
29
|
+
{
|
|
30
|
+
fieldId: "5cd160b26b2f07000673dc00",
|
|
31
|
+
fieldLabel: "Brands",
|
|
32
|
+
valueId: "2b6526b2-ed37-426c-8592-1c580f462334",
|
|
33
|
+
valueLabel: "The Warehouse"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
};
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
generateId() {
|
|
41
|
+
return `74400009${Math.floor(1000000 + Math.random() * 9000000)}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
generateUuid() {
|
|
45
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
46
|
+
const r = Math.random() * 16 | 0;
|
|
47
|
+
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
48
|
+
return v.toString(16);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
generateRefNumber() {
|
|
53
|
+
return `REF${Math.floor(10000 + Math.random() * 90000)}G`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
withId(id) {
|
|
57
|
+
this.jobData.id = id;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
withTitle(title) {
|
|
62
|
+
this.jobData.title = title;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
withUuid(uuid) {
|
|
67
|
+
this.jobData.uuid = uuid;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
withRefNumber(refNumber) {
|
|
72
|
+
this.jobData.refNumber = refNumber;
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
withCompany(identifier, name) {
|
|
77
|
+
this.jobData.company = {
|
|
78
|
+
identifier: identifier || this.jobData.company.identifier,
|
|
79
|
+
name: name || this.jobData.company.name
|
|
80
|
+
};
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
withLocation(locationData) {
|
|
85
|
+
this.jobData.location = {
|
|
86
|
+
...this.jobData.location,
|
|
87
|
+
...locationData
|
|
88
|
+
};
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
withCity(city, region = null, fullLocation = null) {
|
|
93
|
+
this.jobData.location.city = city;
|
|
94
|
+
if (region) this.jobData.location.region = region;
|
|
95
|
+
if (fullLocation) {
|
|
96
|
+
this.jobData.location.fullLocation = fullLocation;
|
|
97
|
+
} else {
|
|
98
|
+
this.jobData.location.fullLocation = `${city}, ${this.jobData.location.region}, New Zealand`;
|
|
99
|
+
}
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
withEmploymentType(employmentType) {
|
|
104
|
+
this.jobData.employmentType = employmentType;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
withCustomField(fieldId, fieldLabel, valueId, valueLabel) {
|
|
109
|
+
this.jobData.customField.push({
|
|
110
|
+
fieldId,
|
|
111
|
+
fieldLabel,
|
|
112
|
+
valueId,
|
|
113
|
+
valueLabel
|
|
114
|
+
});
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
withCustomFields(fields) {
|
|
119
|
+
this.jobData.customField = fields;
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
asRemote() {
|
|
124
|
+
this.jobData.location.remote = true;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
asOnsite() {
|
|
129
|
+
this.jobData.location.remote = false;
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
build() {
|
|
134
|
+
const result = { ...this.jobData };
|
|
135
|
+
this.reset();
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static createDefault() {
|
|
140
|
+
return new MockJobBuilder().build();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
static createSeniorEngineer() {
|
|
144
|
+
return new MockJobBuilder()
|
|
145
|
+
.withTitle("Senior Software Engineer")
|
|
146
|
+
.withCity("Dunedin", "Otago Region")
|
|
147
|
+
.withEmploymentType("Full-time")
|
|
148
|
+
.build();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static createBackendDeveloper() {
|
|
152
|
+
return new MockJobBuilder()
|
|
153
|
+
.withTitle("Backend Developer")
|
|
154
|
+
.withCity("Auckland", "Auckland Region")
|
|
155
|
+
.withEmploymentType("Part-time")
|
|
156
|
+
.build();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static createProductManager() {
|
|
160
|
+
return new MockJobBuilder()
|
|
161
|
+
.withTitle("Product Manager")
|
|
162
|
+
.withCity("Wellington", "Wellington Region")
|
|
163
|
+
.withEmploymentType("Full-time")
|
|
164
|
+
.asRemote()
|
|
165
|
+
.build();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
static createMultiple(count, customizer = null) {
|
|
169
|
+
const jobs = [];
|
|
170
|
+
for (let i = 0; i < count; i++) {
|
|
171
|
+
const builder = new MockJobBuilder();
|
|
172
|
+
if (customizer) {
|
|
173
|
+
customizer(builder, i);
|
|
174
|
+
}
|
|
175
|
+
jobs.push(builder.build());
|
|
176
|
+
}
|
|
177
|
+
return jobs;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
module.exports = MockJobBuilder;
|
|
182
|
+
|
|
@@ -1,24 +1,100 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
const rewire = require('rewire');
|
|
2
|
+
const MockJobBuilder = require('./mockJobBuilder');
|
|
3
|
+
const { CAREERS_MULTI_BOXES_PAGE_CONSTS } = require('../backend/careersMultiBoxesPageIds');
|
|
4
|
+
|
|
5
|
+
const careersMultiBoxesPage = rewire('../pages/careersMultiBoxesPage');
|
|
6
|
+
const secondarySearch = careersMultiBoxesPage.__get__('secondarySearch');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
describe('secondarySearch function tests', () => {
|
|
11
|
+
let mockW;
|
|
12
|
+
let mockJobsRepeater;
|
|
13
|
+
let mockPaginationCurrentText;
|
|
14
|
+
let mockPaginationTotalCountText;
|
|
15
|
+
let mockPageButtonNext;
|
|
16
|
+
let mockPageButtonPrevious;
|
|
17
|
+
let mockTotalJobsCountText;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
mockJobsRepeater = { data: null };
|
|
21
|
+
mockPaginationCurrentText = { text: '' };
|
|
22
|
+
mockPaginationTotalCountText = { text: '' };
|
|
23
|
+
mockPageButtonNext = {
|
|
24
|
+
enable: jest.fn(),
|
|
25
|
+
disable: jest.fn()
|
|
26
|
+
};
|
|
27
|
+
mockPageButtonPrevious = {
|
|
28
|
+
enable: jest.fn(),
|
|
29
|
+
disable: jest.fn()
|
|
30
|
+
};
|
|
31
|
+
mockTotalJobsCountText = { text: '' };
|
|
32
|
+
|
|
33
|
+
mockW = jest.fn((selector) => {
|
|
34
|
+
const mocks = {
|
|
35
|
+
[CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER]: mockJobsRepeater,
|
|
36
|
+
[CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText]: mockPaginationCurrentText,
|
|
37
|
+
[CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText]: mockPaginationTotalCountText,
|
|
38
|
+
[CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_NEXT]: mockPageButtonNext,
|
|
39
|
+
[CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_PREVIOUS]: mockPageButtonPrevious,
|
|
40
|
+
[CAREERS_MULTI_BOXES_PAGE_CONSTS.TotalJobsCountText]: mockTotalJobsCountText
|
|
41
|
+
};
|
|
42
|
+
return mocks[selector] || {
|
|
43
|
+
data: null,
|
|
44
|
+
text: '',
|
|
45
|
+
value: '',
|
|
46
|
+
onClick: jest.fn(),
|
|
47
|
+
onChange: jest.fn(),
|
|
48
|
+
onInput: jest.fn(),
|
|
49
|
+
enable: jest.fn(),
|
|
50
|
+
disable: jest.fn()
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
afterEach(() => {
|
|
56
|
+
jest.clearAllMocks();
|
|
57
|
+
careersMultiBoxesPage.__set__('currentJobs', []);
|
|
19
58
|
});
|
|
20
59
|
|
|
60
|
+
it('should return count > 0 when searching for existing job title', () => {
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
let mockJobs = MockJobBuilder.createMultiple(11, (builder, index) => {
|
|
64
|
+
builder.withTitle(`Product Manager ${index}`);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
mockJobs.push(new MockJobBuilder().withTitle('Backend Engineer').build());
|
|
68
|
+
mockJobs.push(new MockJobBuilder().withTitle('Frontend Engineer').build());
|
|
21
69
|
|
|
70
|
+
careersMultiBoxesPage.__set__('currentJobs', mockJobs);
|
|
22
71
|
|
|
72
|
+
const result = secondarySearch(mockW, 'product');
|
|
23
73
|
|
|
74
|
+
expect(result.length).toBe(11);
|
|
75
|
+
expect(mockTotalJobsCountText.text).toContain('11 Jobs');
|
|
76
|
+
expect(mockPaginationCurrentText.text).toBe('10');
|
|
77
|
+
expect(mockPaginationTotalCountText.text).toBe('11');
|
|
78
|
+
expect(mockPageButtonNext.enable).toHaveBeenCalled();
|
|
79
|
+
expect(mockPageButtonPrevious.disable).toHaveBeenCalled();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should return 0 when searching for non-existing job title', () => {
|
|
83
|
+
let mockJobs = MockJobBuilder.createMultiple(11, (builder, index) => {
|
|
84
|
+
builder.withTitle(`random job ${index}`);
|
|
85
|
+
});
|
|
86
|
+
careersMultiBoxesPage.__set__('currentJobs', mockJobs);
|
|
87
|
+
|
|
88
|
+
const result = secondarySearch(mockW, 'unicorn hunter');
|
|
89
|
+
|
|
90
|
+
expect(result.length).toBe(0);
|
|
91
|
+
expect(mockTotalJobsCountText.text).toContain('0 Jobs');
|
|
92
|
+
expect(mockPaginationCurrentText.text).toBe('0');
|
|
93
|
+
expect(mockPaginationTotalCountText.text).toBe('0');
|
|
94
|
+
expect(mockPageButtonNext.disable).toHaveBeenCalled();
|
|
95
|
+
expect(mockPageButtonPrevious.disable).toHaveBeenCalled();
|
|
96
|
+
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
});
|
|
24
100
|
|