sr-npm 2.0.17 → 2.0.19

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.
@@ -0,0 +1,140 @@
1
+ // Mock query chain at the top
2
+ const MockJobBuilder = require('./mockJobBuilder');
3
+ const { positionPageOnReady } = require('../pages/positionPage');
4
+ const { getPositionWithMultiRefField } = require('../backend/queries');
5
+ const { items: wixData } = require('@wix/data');
6
+
7
+ const mockQueryChain = {
8
+ eq: jest.fn().mockReturnThis(),
9
+ find: jest.fn(),
10
+ include: jest.fn().mockReturnThis(),
11
+ hasSome: jest.fn().mockReturnThis(),
12
+ ne: jest.fn().mockReturnThis(),
13
+ limit: jest.fn().mockReturnThis(),
14
+ then: jest.fn()
15
+ };
16
+
17
+ // Jest mocks (hoisted automatically)
18
+ jest.mock('wix-location-frontend', () => ({
19
+ query: {}
20
+ }), { virtual: true });
21
+ jest.mock('@wix/data', () => ({
22
+ items: {
23
+ query: jest.fn(() => mockQueryChain),
24
+ queryReferenced: jest.fn()
25
+ }
26
+ }));
27
+ jest.mock('@wix/site-location', () => ({
28
+ location: {
29
+ to: jest.fn()
30
+ }
31
+ }));
32
+
33
+ // Mock the backend queries module as well
34
+ jest.mock('../backend/queries', () => ({
35
+ getPositionWithMultiRefField: jest.fn()
36
+ }));
37
+
38
+ // Mock utils
39
+ jest.mock('../public/utils', () => ({
40
+ htmlToText: jest.fn((text) => text.replace(/<[^>]*>/g, '')),
41
+ appendQueryParams: jest.fn((url) => url)
42
+ }));
43
+
44
+ // Mock isElementExistOnPage
45
+ jest.mock('psdev-utils', () => ({
46
+ isElementExistOnPage: jest.fn(() => true)
47
+ }));
48
+
49
+
50
+
51
+
52
+
53
+
54
+ describe('related jobs show jobs with the same category value test', () => {
55
+ let mockW;
56
+ let mockRealtedJobsRepeater;
57
+
58
+ beforeEach(() => {
59
+ // Create a proper repeater mock that allows data to be set
60
+ mockRealtedJobsRepeater = {
61
+ data: null,
62
+ onItemReady: jest.fn()
63
+ };
64
+ });
65
+
66
+ it('should show related jobs with the same category value', async () => {
67
+ const CATEGORY_FIELD_ID = `category-field-${Date.now()}`;
68
+ const TECH_CATEGORY_VALUE_ID = `tech-category-${Math.floor(Math.random() * 10000)}`;
69
+
70
+ const currentJob = new MockJobBuilder()
71
+ .withTitle('Senior Developer')
72
+ .withDepartment('Technology')
73
+ .withMultiRefCustomValues([{ _id: TECH_CATEGORY_VALUE_ID }])
74
+ .forPositionPage()
75
+ .build();
76
+
77
+ // create 0-5 related jobs with same category value(0 for the case when there is no related jobs)
78
+ const relatedJobsCount = Math.floor(Math.random() * 6);
79
+ const relatedJobs = MockJobBuilder.createJobsWithSameField(TECH_CATEGORY_VALUE_ID, relatedJobsCount);
80
+
81
+ const currentJobCustomValues = [
82
+ { _id: TECH_CATEGORY_VALUE_ID, customField: CATEGORY_FIELD_ID, title: 'Technology' }
83
+ ];
84
+
85
+ const categoryCustomField = {
86
+ _id: CATEGORY_FIELD_ID,
87
+ title: 'Category'
88
+ };
89
+
90
+ let datasetReadyCallback;
91
+ const mockDataset = {
92
+ onReady: jest.fn((callback) => {
93
+ datasetReadyCallback = callback;
94
+ }),
95
+ getCurrentItem: jest.fn().mockResolvedValue(currentJob)
96
+ };
97
+
98
+ mockW = jest.fn((selector) => {
99
+ const mocks = {
100
+ '#datasetJobsItem': mockDataset,
101
+ '#relatedJobsRepNoDepartment': mockRealtedJobsRepeater,
102
+ '#companyDescriptionText': { text: '' },
103
+ '#responsibilitiesText': { text: '' },
104
+ '#qualificationsText': { text: '' },
105
+ '#relatedJobsTitleText': { text: '' },
106
+ '#additionalInfoText': { text: '' },
107
+ '#applyButton': { target: '', link: '' },
108
+ '#relatedJobsNoDepartmentItem': { onClick: jest.fn() },
109
+ '#relatedJobsDataset': { onReady: jest.fn(), getTotalCount: jest.fn() },
110
+ '#relatedJobsSection': { collapse: jest.fn() },
111
+ '#referFriendButton': { hide: jest.fn() }
112
+ };
113
+ return mocks[selector] || { text: '', hide: jest.fn(), onClick: jest.fn() };
114
+ });
115
+
116
+ getPositionWithMultiRefField.mockResolvedValue(currentJobCustomValues);
117
+
118
+ mockQueryChain.find.mockImplementation(() => {
119
+ const queryArg = wixData.query.mock.calls[wixData.query.mock.calls.length - 1][0];
120
+ if (queryArg === 'CustomFields') {
121
+ return Promise.resolve({ items: [categoryCustomField] });
122
+ }
123
+ return Promise.resolve({ items: relatedJobs });
124
+ });
125
+
126
+ await positionPageOnReady(mockW);
127
+ await datasetReadyCallback();
128
+
129
+ expect(mockRealtedJobsRepeater.data).not.toBeNull();
130
+ expect(mockRealtedJobsRepeater.data).toHaveLength(relatedJobsCount);
131
+
132
+ const allHaveSameCategory = mockRealtedJobsRepeater.data.every(job =>
133
+ job.multiRefJobsCustomValues &&
134
+ job.multiRefJobsCustomValues.some(val => val._id === TECH_CATEGORY_VALUE_ID)
135
+ );
136
+ expect(allHaveSameCategory).toBe(true);
137
+ });
138
+
139
+ });
140
+