sr-npm 1.7.816 → 1.7.818
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 +1 -1
- package/pages/brandPage.js +12 -0
- package/pages/index.js +1 -0
- package/pages/positionPage.js +1 -4
- package/tests/mockJobBuilder.js +93 -0
- package/tests/positionPageTest.spec.js +139 -0
package/package.json
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
const { location } = require("@wix/site-location");
|
|
3
|
+
async function brandPageOnReady(_$w,brand) {
|
|
4
|
+
const decodedBrand = decodeURIComponent(brand);
|
|
5
|
+
_$w('#seeJobsButton').onClick(async () => {
|
|
6
|
+
await location.to(`/search?brand=${decodedBrand}`);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
brandPageOnReady,
|
|
12
|
+
};
|
package/pages/index.js
CHANGED
package/pages/positionPage.js
CHANGED
|
@@ -51,9 +51,7 @@ async function getCategoryValueId(customFields) {
|
|
|
51
51
|
}
|
|
52
52
|
if(_$w('#relatedJobsRepNoDepartment')) // when there is no department, we filter based on category
|
|
53
53
|
{
|
|
54
|
-
console.log("item inside getRelatedJobs: ", item);
|
|
55
54
|
const relatedJobs=await getRelatedJobs(categoryValueId,item._id);
|
|
56
|
-
console.log("relatedJobs@@$@$@$$%%%%%%%%%%#$@: ", relatedJobs);
|
|
57
55
|
_$w('#relatedJobsRepNoDepartment').onItemReady(($item, itemData) => {
|
|
58
56
|
$item('#relatedJobTitle').text = itemData.title;
|
|
59
57
|
$item('#relatedJobLocation').text = itemData.location.fullLocation;
|
|
@@ -61,7 +59,7 @@ async function getCategoryValueId(customFields) {
|
|
|
61
59
|
await location.to(itemData["link-jobs-title"]);
|
|
62
60
|
});
|
|
63
61
|
});
|
|
64
|
-
_$w('#relatedJobsRepNoDepartment').data = relatedJobs
|
|
62
|
+
_$w('#relatedJobsRepNoDepartment').data = relatedJobs
|
|
65
63
|
|
|
66
64
|
}
|
|
67
65
|
});
|
|
@@ -93,7 +91,6 @@ async function getCategoryValueId(customFields) {
|
|
|
93
91
|
|
|
94
92
|
async function getRelatedJobs(categoryValueId,itemId) {
|
|
95
93
|
const relatedJobs=await wixData.query(COLLECTIONS.JOBS).include(JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES).hasSome(JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,[categoryValueId]).ne("_id",itemId).find();
|
|
96
|
-
console.log("relatedJobs@@$@$@$#$@: ", relatedJobs);
|
|
97
94
|
return relatedJobs.items;
|
|
98
95
|
}
|
|
99
96
|
|
package/tests/mockJobBuilder.js
CHANGED
|
@@ -120,6 +120,67 @@ class MockJobBuilder {
|
|
|
120
120
|
return this;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
withMultiRefCustomValues(categoryIds) {
|
|
124
|
+
this.jobData.multiRefJobsCustomValues = categoryIds;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
withCategory(categoryId) {
|
|
129
|
+
if (!this.jobData.multiRefJobsCustomValues) {
|
|
130
|
+
this.jobData.multiRefJobsCustomValues = [];
|
|
131
|
+
}
|
|
132
|
+
this.jobData.multiRefJobsCustomValues.push(categoryId);
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
withDepartment(department) {
|
|
137
|
+
this.jobData.department = department;
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
withJobDescription(companyDesc, jobDesc, qualifications, additionalInfo = null) {
|
|
142
|
+
this.jobData.jobDescription = {
|
|
143
|
+
companyDescription: { text: companyDesc },
|
|
144
|
+
jobDescription: { text: jobDesc },
|
|
145
|
+
qualifications: { text: qualifications }
|
|
146
|
+
};
|
|
147
|
+
if (additionalInfo) {
|
|
148
|
+
this.jobData.jobDescription.additionalInformation = { text: additionalInfo };
|
|
149
|
+
}
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
withApplyLink(link) {
|
|
154
|
+
this.jobData.applyLink = link;
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
withLinkJobsTitle(link) {
|
|
159
|
+
this.jobData['link-jobs-title'] = link;
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
forPositionPage() {
|
|
164
|
+
if (!this.jobData._id) {
|
|
165
|
+
this.jobData._id = this.generateId();
|
|
166
|
+
}
|
|
167
|
+
if (!this.jobData.department) {
|
|
168
|
+
this.jobData.department = 'Technology';
|
|
169
|
+
}
|
|
170
|
+
if (!this.jobData.jobDescription) {
|
|
171
|
+
this.withJobDescription(
|
|
172
|
+
'<p>Great company to work for</p>',
|
|
173
|
+
'<p>You will build awesome stuff</p>',
|
|
174
|
+
'<p>Must know how to code</p>',
|
|
175
|
+
'<p>Additional info here</p>'
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
if (!this.jobData.applyLink) {
|
|
179
|
+
this.jobData.applyLink = `https://apply.com/${this.jobData.id}`;
|
|
180
|
+
}
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
|
|
123
184
|
asRemote() {
|
|
124
185
|
this.jobData.location.remote = true;
|
|
125
186
|
return this;
|
|
@@ -176,6 +237,38 @@ class MockJobBuilder {
|
|
|
176
237
|
}
|
|
177
238
|
return jobs;
|
|
178
239
|
}
|
|
240
|
+
|
|
241
|
+
static createJobsWithSameCategory(categoryId, count = 3) {
|
|
242
|
+
const jobs = [];
|
|
243
|
+
const titles = [
|
|
244
|
+
'Frontend Developer', 'Backend Developer', 'Full Stack Engineer',
|
|
245
|
+
'DevOps Engineer', 'QA Engineer', 'Data Scientist',
|
|
246
|
+
'Product Manager', 'UX Designer', 'System Architect'
|
|
247
|
+
];
|
|
248
|
+
const cities = [
|
|
249
|
+
{ city: 'Auckland', region: 'Auckland Region' },
|
|
250
|
+
{ city: 'Wellington', region: 'Wellington Region' },
|
|
251
|
+
{ city: 'Christchurch', region: 'Canterbury Region' },
|
|
252
|
+
{ city: 'Hamilton', region: 'Waikato Region' },
|
|
253
|
+
{ city: 'Dunedin', region: 'Otago Region' }
|
|
254
|
+
];
|
|
255
|
+
|
|
256
|
+
for (let i = 0; i < count; i++) {
|
|
257
|
+
const randomTitle = titles[Math.floor(Math.random() * titles.length)];
|
|
258
|
+
const randomCity = cities[Math.floor(Math.random() * cities.length)];
|
|
259
|
+
|
|
260
|
+
jobs.push(
|
|
261
|
+
new MockJobBuilder()
|
|
262
|
+
.withTitle(`${randomTitle} ${i + 1}`)
|
|
263
|
+
.withCity(randomCity.city, randomCity.region)
|
|
264
|
+
.withCategory(categoryId)
|
|
265
|
+
.withLinkJobsTitle(`/jobs/${randomTitle.toLowerCase().replace(/\s+/g, '-')}-${i + 1}`)
|
|
266
|
+
.forPositionPage()
|
|
267
|
+
.build()
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
return jobs;
|
|
271
|
+
}
|
|
179
272
|
}
|
|
180
273
|
|
|
181
274
|
module.exports = MockJobBuilder;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
const MockJobBuilder = require('./mockJobBuilder');
|
|
2
|
+
|
|
3
|
+
// Create mocks before importing
|
|
4
|
+
const mockQueryChain = {
|
|
5
|
+
eq: jest.fn().mockReturnThis(),
|
|
6
|
+
find: jest.fn(),
|
|
7
|
+
include: jest.fn().mockReturnThis(),
|
|
8
|
+
hasSome: jest.fn().mockReturnThis(),
|
|
9
|
+
ne: jest.fn().mockReturnThis(),
|
|
10
|
+
limit: jest.fn().mockReturnThis(),
|
|
11
|
+
then: jest.fn()
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const mockWixData = {
|
|
15
|
+
query: jest.fn(() => mockQueryChain),
|
|
16
|
+
queryReferenced: jest.fn()
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
jest.mock('wix-location-frontend', () => ({
|
|
20
|
+
query: {}
|
|
21
|
+
}), { virtual: true });
|
|
22
|
+
jest.mock('@wix/data', () => ({
|
|
23
|
+
items: mockWixData
|
|
24
|
+
}));
|
|
25
|
+
jest.mock('@wix/site-location', () => ({
|
|
26
|
+
location: {
|
|
27
|
+
to: jest.fn()
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
// Mock the backend queries module as well
|
|
32
|
+
jest.mock('../backend/queries', () => ({
|
|
33
|
+
getPositionWithMultiRefField: jest.fn()
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
// Mock utils
|
|
37
|
+
jest.mock('../public/utils', () => ({
|
|
38
|
+
htmlToText: jest.fn((text) => text.replace(/<[^>]*>/g, '')),
|
|
39
|
+
appendQueryParams: jest.fn((url) => url)
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
const { positionPageOnReady } = require('../pages/positionPage');
|
|
43
|
+
const { getPositionWithMultiRefField } = require('../backend/queries');
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
describe('related jobs show jobs with the same category value test', () => {
|
|
47
|
+
let mockW;
|
|
48
|
+
let mockRealtedJobsRepeater;
|
|
49
|
+
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
// Create a proper repeater mock that allows data to be set
|
|
52
|
+
mockRealtedJobsRepeater = {
|
|
53
|
+
data: null,
|
|
54
|
+
onItemReady: jest.fn()
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should show related jobs with the same category value', async () => {
|
|
59
|
+
const CATEGORY_FIELD_ID = `category-field-${Date.now()}`;
|
|
60
|
+
const TECH_CATEGORY_VALUE_ID = `tech-category-${Math.floor(Math.random() * 10000)}`;
|
|
61
|
+
|
|
62
|
+
// Create current job using MockJobBuilder with random data
|
|
63
|
+
const currentJob = new MockJobBuilder()
|
|
64
|
+
.withTitle('Senior Developer')
|
|
65
|
+
.withDepartment('Technology')
|
|
66
|
+
.withCategory(TECH_CATEGORY_VALUE_ID)
|
|
67
|
+
.forPositionPage()
|
|
68
|
+
.build();
|
|
69
|
+
|
|
70
|
+
// Create 0-5 related jobs with same category using random data (including case with 0 related jobs)
|
|
71
|
+
const relatedJobsCount = Math.floor(Math.random() * 6); // 0-5 jobs
|
|
72
|
+
const relatedJobs = MockJobBuilder.createJobsWithSameCategory(
|
|
73
|
+
TECH_CATEGORY_VALUE_ID,
|
|
74
|
+
relatedJobsCount
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// Current job's custom values (Tech category)
|
|
78
|
+
const currentJobCustomValues = [
|
|
79
|
+
{ _id: TECH_CATEGORY_VALUE_ID, customField: CATEGORY_FIELD_ID, title: 'Technology' }
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const categoryCustomField = {
|
|
83
|
+
_id: CATEGORY_FIELD_ID,
|
|
84
|
+
title: 'Category'
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// Setup mocks - capture the onReady callback so we can await it
|
|
88
|
+
let datasetReadyCallback;
|
|
89
|
+
const mockDataset = {
|
|
90
|
+
onReady: jest.fn((callback) => {
|
|
91
|
+
datasetReadyCallback = callback;
|
|
92
|
+
}),
|
|
93
|
+
getCurrentItem: jest.fn().mockResolvedValue(currentJob)
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
mockW = jest.fn((selector) => {
|
|
97
|
+
const mocks = {
|
|
98
|
+
'#datasetJobsItem': mockDataset,
|
|
99
|
+
'#relatedJobsRepNoDepartment': mockRealtedJobsRepeater,
|
|
100
|
+
'#companyDescriptionText': { text: '' },
|
|
101
|
+
'#responsibilitiesText': { text: '' },
|
|
102
|
+
'#qualificationsText': { text: '' },
|
|
103
|
+
'#relatedJobsTitleText': { text: '' },
|
|
104
|
+
'#additionalInfoText': { text: '' },
|
|
105
|
+
'#applyButton': { target: '', link: '' }
|
|
106
|
+
};
|
|
107
|
+
return mocks[selector] || { text: '', hide: jest.fn() };
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
getPositionWithMultiRefField.mockResolvedValue(currentJobCustomValues);
|
|
111
|
+
|
|
112
|
+
mockQueryChain.find.mockImplementation(() => {
|
|
113
|
+
const queryArg = mockWixData.query.mock.calls[mockWixData.query.mock.calls.length - 1][0];
|
|
114
|
+
if (queryArg === 'CustomFields') {
|
|
115
|
+
return Promise.resolve({ items: [categoryCustomField] });
|
|
116
|
+
}
|
|
117
|
+
return Promise.resolve({ items: relatedJobs });
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Run the page function (sets up the onReady callback)
|
|
121
|
+
await positionPageOnReady(mockW);
|
|
122
|
+
|
|
123
|
+
// Now execute the dataset onReady callback and wait for it
|
|
124
|
+
await datasetReadyCallback();
|
|
125
|
+
|
|
126
|
+
// Verify the repeater got populated with related jobs
|
|
127
|
+
expect(mockRealtedJobsRepeater.data).not.toBeNull();
|
|
128
|
+
expect(mockRealtedJobsRepeater.data).toHaveLength(relatedJobsCount);
|
|
129
|
+
|
|
130
|
+
// Verify all related jobs have the same category as current job
|
|
131
|
+
const allHaveSameCategory = mockRealtedJobsRepeater.data.every(job =>
|
|
132
|
+
job.multiRefJobsCustomValues &&
|
|
133
|
+
job.multiRefJobsCustomValues.includes(TECH_CATEGORY_VALUE_ID)
|
|
134
|
+
);
|
|
135
|
+
expect(allHaveSameCategory).toBe(true);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
});
|
|
139
|
+
|