Skip to content

Commit df17af3

Browse files
committed
fix unit tests
1 parent c83979c commit df17af3

File tree

6 files changed

+84
-72
lines changed

6 files changed

+84
-72
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
],
99
"scripts": {
1010
"build": "turbo run build",
11-
"start": "turbo run start --continue --filter=./examples/**/*",
12-
"start:e2e": "turbo run start --continue --filter=./packages/e2e-react-web-app",
11+
"start": "turbo run start --continue --filter=./examples/**/* --filter=./packages/**/*",
12+
"start:e2e": "turbo run start --continue --filter=./packages/**/*",
1313
"test": "turbo run test",
1414
"test:e2e": "turbo run test:e2e",
1515
"format": "prettier --write \"**/*.{ts,tsx,md}\"",

packages/config/test/unit/jest.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ export default {
1212
restoreMocks: true,
1313
testEnvironment: 'jsdom',
1414
moduleDirectories: ['**/src', 'node_modules'],
15-
setupFilesAfterEnv: ['@lemoncode/config/test/jest/setup.ts'],
15+
setupFilesAfterEnv: ['@lemoncode/config/test/unit/setup.ts'],
1616
moduleNameMapper: {
17-
'\\.css$': '@lemoncode/config/test/jest/file.mock.js',
17+
'\\.css$': '@lemoncode/config/test/unit/file.mock.js',
1818
},
19+
modulePathIgnorePatterns: ['<rootDir>/e2e'],
1920
};

packages/react-image-focal-point/src/image-focal-point.component.spec.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { render, screen } from '@testing-library/react';
2-
import userEvent from '@testing-library/user-event';
32
import { ImageFocalPoint, ImageFocalPointProps } from './image-focal-point.component';
43

54
describe('focal-point/focal-point.component specs', () => {

packages/react-image-focal-point/src/image-focal-point.helpers.spec.ts

Lines changed: 68 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ const imageContainer = {
77

88
describe('focal-point/onMove specs', () => {
99
describe('base case', () => {
10-
const boundingRectangle = { top: 0, left: 0 } as DOMRect;
10+
const container = {
11+
getBoundingClientRect: jest.fn().mockReturnValue({
12+
top: 0,
13+
left: 0,
14+
}),
15+
} as unknown as HTMLDivElement;
1116

1217
it('should does not call to setX, setY nor onChange when it feeds canMove equals false', () => {
1318
// Arrange
1419
const props = {
1520
setX: jest.fn(),
1621
setY: jest.fn(),
17-
boundingRectangle,
22+
container,
1823
canMove: false,
1924
onChange: jest.fn(),
2025
};
@@ -34,13 +39,13 @@ describe('focal-point/onMove specs', () => {
3439
const props = {
3540
setX: jest.fn(),
3641
setY: jest.fn(),
37-
boundingRectangle,
42+
container,
3843
canMove: true,
3944
onChange: jest.fn(),
4045
};
4146
const event = {
42-
pageX: 101,
43-
pageY: 100,
47+
clientX: 101,
48+
clientY: 100,
4449
currentTarget: imageContainer,
4550
} as unknown as MouseEvent;
4651

@@ -58,13 +63,13 @@ describe('focal-point/onMove specs', () => {
5863
const props = {
5964
setX: jest.fn(),
6065
setY: jest.fn(),
61-
boundingRectangle,
66+
container,
6267
canMove: true,
6368
onChange: jest.fn(),
6469
};
6570
const event = {
66-
pageX: 99,
67-
pageY: 100,
71+
clientX: 99,
72+
clientY: 100,
6873
currentTarget: imageContainer,
6974
} as unknown as MouseEvent;
7075

@@ -82,13 +87,13 @@ describe('focal-point/onMove specs', () => {
8287
const props = {
8388
setX: jest.fn(),
8489
setY: jest.fn(),
85-
boundingRectangle,
90+
container,
8691
canMove: true,
8792
onChange: jest.fn(),
8893
};
8994
const event = {
90-
pageX: 100,
91-
pageY: 101,
95+
clientX: 100,
96+
clientY: 101,
9297
currentTarget: imageContainer,
9398
} as unknown as MouseEvent;
9499

@@ -106,13 +111,13 @@ describe('focal-point/onMove specs', () => {
106111
const props = {
107112
setX: jest.fn(),
108113
setY: jest.fn(),
109-
boundingRectangle,
114+
container,
110115
canMove: true,
111116
onChange: jest.fn(),
112117
};
113118
const event = {
114-
pageX: 100,
115-
pageY: 99,
119+
clientX: 100,
120+
clientY: 99,
116121
currentTarget: imageContainer,
117122
} as unknown as MouseEvent;
118123

@@ -130,13 +135,13 @@ describe('focal-point/onMove specs', () => {
130135
const props = {
131136
setX: jest.fn(),
132137
setY: jest.fn(),
133-
boundingRectangle,
138+
container,
134139
canMove: true,
135140
onChange: jest.fn(),
136141
};
137142
const event = {
138-
pageX: 98,
139-
pageY: 102,
143+
clientX: 98,
144+
clientY: 102,
140145
currentTarget: imageContainer,
141146
} as unknown as MouseEvent;
142147

@@ -154,13 +159,13 @@ describe('focal-point/onMove specs', () => {
154159
const props = {
155160
setX: jest.fn(),
156161
setY: jest.fn(),
157-
boundingRectangle,
162+
container,
158163
canMove: true,
159164
onChange: jest.fn(),
160165
};
161166
const event = {
162-
pageX: -20,
163-
pageY: 100,
167+
clientX: -20,
168+
clientY: 100,
164169
currentTarget: imageContainer,
165170
} as unknown as MouseEvent;
166171

@@ -178,13 +183,13 @@ describe('focal-point/onMove specs', () => {
178183
const props = {
179184
setX: jest.fn(),
180185
setY: jest.fn(),
181-
boundingRectangle,
186+
container,
182187
canMove: true,
183188
onChange: jest.fn(),
184189
};
185190
const event = {
186-
pageX: 100,
187-
pageY: -20,
191+
clientX: 100,
192+
clientY: -20,
188193
currentTarget: imageContainer,
189194
} as unknown as MouseEvent;
190195

@@ -202,13 +207,13 @@ describe('focal-point/onMove specs', () => {
202207
const props = {
203208
setX: jest.fn(),
204209
setY: jest.fn(),
205-
boundingRectangle,
210+
container,
206211
canMove: true,
207212
onChange: jest.fn(),
208213
};
209214
const event = {
210-
pageX: 210,
211-
pageY: 100,
215+
clientX: 210,
216+
clientY: 100,
212217
currentTarget: imageContainer,
213218
} as unknown as MouseEvent;
214219

@@ -226,13 +231,13 @@ describe('focal-point/onMove specs', () => {
226231
const props = {
227232
setX: jest.fn(),
228233
setY: jest.fn(),
229-
boundingRectangle,
234+
container,
230235
canMove: true,
231236
onChange: jest.fn(),
232237
};
233238
const event = {
234-
pageX: 100,
235-
pageY: 220,
239+
clientX: 100,
240+
clientY: 220,
236241
currentTarget: imageContainer,
237242
} as unknown as MouseEvent;
238243

@@ -247,14 +252,19 @@ describe('focal-point/onMove specs', () => {
247252
});
248253

249254
describe('image container inside some page an its location is not 0/0', () => {
250-
const boundingRectangle = { top: 400, left: 400 } as DOMRect;
255+
const container = {
256+
getBoundingClientRect: jest.fn().mockReturnValue({
257+
top: 400,
258+
left: 400,
259+
}),
260+
} as unknown as HTMLDivElement;
251261

252262
it('should does not call to setX, setY nor onChange when it feeds canMove equals false', () => {
253263
// Arrange
254264
const props = {
255265
setX: jest.fn(),
256266
setY: jest.fn(),
257-
boundingRectangle,
267+
container,
258268
canMove: false,
259269
onChange: jest.fn(),
260270
};
@@ -274,13 +284,13 @@ describe('focal-point/onMove specs', () => {
274284
const props = {
275285
setX: jest.fn(),
276286
setY: jest.fn(),
277-
boundingRectangle,
287+
container,
278288
canMove: true,
279289
onChange: jest.fn(),
280290
};
281291
const event = {
282-
pageX: 501,
283-
pageY: 500,
292+
clientX: 501,
293+
clientY: 500,
284294
currentTarget: imageContainer,
285295
} as unknown as MouseEvent;
286296

@@ -298,13 +308,13 @@ describe('focal-point/onMove specs', () => {
298308
const props = {
299309
setX: jest.fn(),
300310
setY: jest.fn(),
301-
boundingRectangle,
311+
container,
302312
canMove: true,
303313
onChange: jest.fn(),
304314
};
305315
const event = {
306-
pageX: 499,
307-
pageY: 500,
316+
clientX: 499,
317+
clientY: 500,
308318
currentTarget: imageContainer,
309319
} as unknown as MouseEvent;
310320

@@ -322,13 +332,13 @@ describe('focal-point/onMove specs', () => {
322332
const props = {
323333
setX: jest.fn(),
324334
setY: jest.fn(),
325-
boundingRectangle,
335+
container,
326336
canMove: true,
327337
onChange: jest.fn(),
328338
};
329339
const event = {
330-
pageX: 500,
331-
pageY: 501,
340+
clientX: 500,
341+
clientY: 501,
332342
currentTarget: imageContainer,
333343
} as unknown as MouseEvent;
334344

@@ -346,13 +356,13 @@ describe('focal-point/onMove specs', () => {
346356
const props = {
347357
setX: jest.fn(),
348358
setY: jest.fn(),
349-
boundingRectangle,
359+
container,
350360
canMove: true,
351361
onChange: jest.fn(),
352362
};
353363
const event = {
354-
pageX: 500,
355-
pageY: 499,
364+
clientX: 500,
365+
clientY: 499,
356366
currentTarget: imageContainer,
357367
} as unknown as MouseEvent;
358368

@@ -370,13 +380,13 @@ describe('focal-point/onMove specs', () => {
370380
const props = {
371381
setX: jest.fn(),
372382
setY: jest.fn(),
373-
boundingRectangle,
383+
container,
374384
canMove: true,
375385
onChange: jest.fn(),
376386
};
377387
const event = {
378-
pageX: 498,
379-
pageY: 502,
388+
clientX: 498,
389+
clientY: 502,
380390
currentTarget: imageContainer,
381391
} as unknown as MouseEvent;
382392

@@ -394,13 +404,13 @@ describe('focal-point/onMove specs', () => {
394404
const props = {
395405
setX: jest.fn(),
396406
setY: jest.fn(),
397-
boundingRectangle,
407+
container,
398408
canMove: true,
399409
onChange: jest.fn(),
400410
};
401411
const event = {
402-
pageX: 320,
403-
pageY: 500,
412+
clientX: 320,
413+
clientY: 500,
404414
currentTarget: imageContainer,
405415
} as unknown as MouseEvent;
406416

@@ -418,13 +428,13 @@ describe('focal-point/onMove specs', () => {
418428
const props = {
419429
setX: jest.fn(),
420430
setY: jest.fn(),
421-
boundingRectangle,
431+
container,
422432
canMove: true,
423433
onChange: jest.fn(),
424434
};
425435
const event = {
426-
pageX: 500,
427-
pageY: 320,
436+
clientX: 500,
437+
clientY: 320,
428438
currentTarget: imageContainer,
429439
} as unknown as MouseEvent;
430440

@@ -442,13 +452,13 @@ describe('focal-point/onMove specs', () => {
442452
const props = {
443453
setX: jest.fn(),
444454
setY: jest.fn(),
445-
boundingRectangle,
455+
container,
446456
canMove: true,
447457
onChange: jest.fn(),
448458
};
449459
const event = {
450-
pageX: 610,
451-
pageY: 500,
460+
clientX: 610,
461+
clientY: 500,
452462
currentTarget: imageContainer,
453463
} as unknown as MouseEvent;
454464

@@ -466,13 +476,13 @@ describe('focal-point/onMove specs', () => {
466476
const props = {
467477
setX: jest.fn(),
468478
setY: jest.fn(),
469-
boundingRectangle,
479+
container,
470480
canMove: true,
471481
onChange: jest.fn(),
472482
};
473483
const event = {
474-
pageX: 500,
475-
pageY: 620,
484+
clientX: 500,
485+
clientY: 620,
476486
currentTarget: imageContainer,
477487
} as unknown as MouseEvent;
478488

0 commit comments

Comments
 (0)