Skip to content

Commit 0697ade

Browse files
Add tests
1 parent d65c81f commit 0697ade

File tree

5 files changed

+503
-24
lines changed

5 files changed

+503
-24
lines changed

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,46 +28,46 @@
2828
"start-test-server": "http-server -p 9002",
2929
"test": "pnpm lint:js && pnpm test:ci",
3030
"test:ci": "pnpm test:unit:ci && pnpm test:cy:ci",
31-
"test:cy:ci": "pnpm build && start-server-and-test start-test-server http://localhost:9002 cy:run",
32-
"test:cy:watch": "pnpm build && start-server-and-test start-test-server http://localhost:9002 cy:open",
31+
"test:cy:ci": "pnpm build && start-server-and-test start-test-server http://127.0.0.1:9002 cy:run",
32+
"test:cy:watch": "pnpm build && start-server-and-test start-test-server http://127.0.0.1:9002 cy:open",
3333
"test:unit:ci": "jest --coverage",
3434
"test:unit:watch": "jest --watch",
3535
"watch": "pnpm clean && rollup -c --environment DEVELOPMENT --watch"
3636
},
3737
"devDependencies": {
38-
"@babel/core": "^7.27.4",
39-
"@babel/preset-env": "^7.27.2",
38+
"@babel/core": "^7.28.5",
39+
"@babel/preset-env": "^7.28.5",
4040
"@testing-library/jest-dom": "^5.17.0",
41-
"autoprefixer": "^10.4.21",
41+
"autoprefixer": "^10.4.22",
4242
"babel-jest": "^29.7.0",
4343
"babel-plugin-rewire": "^1.2.0",
4444
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
45-
"chai": "^5.2.0",
45+
"chai": "^5.3.3",
4646
"cssnano": "^6.1.2",
4747
"cypress": "13.17.0",
4848
"eslint": "^8.57.1",
49-
"eslint-plugin-jest": "^28.3.0",
49+
"eslint-plugin-jest": "^28.14.0",
5050
"http-server": "^14.1.1",
5151
"jest": "^29.7.0",
5252
"jest-environment-jsdom": "^29.7.0",
5353
"jest-expect-message": "^1.1.3",
5454
"jsdom": "^22.1.0",
5555
"mutationobserver-shim": "^0.3.7",
56-
"postcss": "^8.5.5",
56+
"postcss": "^8.5.6",
5757
"release-it": "^15.11.0",
5858
"release-it-lerna-changelog": "^5.0.0",
59-
"rimraf": "^5.0.7",
59+
"rimraf": "^5.0.10",
6060
"rollup": "^2.79.2",
6161
"rollup-plugin-babel": "^4.4.0",
6262
"rollup-plugin-browsersync": "^1.3.3",
6363
"rollup-plugin-eslint": "^7.0.0",
6464
"rollup-plugin-filesize": "^10.0.0",
6565
"rollup-plugin-license": "^3.6.0",
66-
"rollup-plugin-sass": "^1.15.2",
66+
"rollup-plugin-sass": "^1.15.3",
6767
"rollup-plugin-terser": "^7.0.2",
68-
"rollup-plugin-visualizer": "^5.12.0",
69-
"sinon": "^15.1.2",
70-
"start-server-and-test": "^2.0.12"
68+
"rollup-plugin-visualizer": "^5.14.0",
69+
"sinon": "^15.2.0",
70+
"start-server-and-test": "^2.1.3"
7171
},
7272
"publishConfig": {
7373
"registry": "https://registry.npmjs.org"

pnpm-lock.yaml

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/unit/shift.spec.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import shift from '../../src/js/shift';
2+
3+
describe('Shift', () => {
4+
describe('position()', () => {
5+
it('returns undefined when shift option is not set', () => {
6+
const context = {
7+
options: {}
8+
};
9+
const result = shift.position.call(context, { top: 10, left: 20 });
10+
expect(result).toBeUndefined();
11+
});
12+
13+
it('shifts position with string value (single value applies to both)', () => {
14+
const context = {
15+
options: { shift: '10' }
16+
};
17+
const result = shift.position.call(context, { top: 10, left: 20 });
18+
expect(result).toEqual({ top: 20, left: 30 });
19+
});
20+
21+
it('shifts position with string value (two values)', () => {
22+
const context = {
23+
options: { shift: '10 5' }
24+
};
25+
const result = shift.position.call(context, { top: 10, left: 20 });
26+
expect(result).toEqual({ top: 20, left: 25 });
27+
});
28+
29+
it('shifts position with object value', () => {
30+
const context = {
31+
options: { shift: { top: 15, left: 25 } }
32+
};
33+
const result = shift.position.call(context, { top: 10, left: 20 });
34+
expect(result).toEqual({ top: 25, left: 45 });
35+
});
36+
37+
it('shifts position with function value', () => {
38+
const shiftFn = jest.fn(({ top, left }) => ({ top: 5, left: 10 }));
39+
const context = {
40+
options: { shift: shiftFn }
41+
};
42+
const result = shift.position.call(context, { top: 10, left: 20 });
43+
expect(shiftFn).toHaveBeenCalledWith({ top: 10, left: 20 });
44+
expect(result).toEqual({ top: 15, left: 30 });
45+
});
46+
47+
it('handles function returning string', () => {
48+
const shiftFn = jest.fn(() => '20 30');
49+
const context = {
50+
options: { shift: shiftFn }
51+
};
52+
const result = shift.position.call(context, { top: 10, left: 20 });
53+
expect(result).toEqual({ top: 30, left: 50 });
54+
});
55+
56+
it('handles function returning object', () => {
57+
const shiftFn = jest.fn(() => ({ top: 100, left: 200 }));
58+
const context = {
59+
options: { shift: shiftFn }
60+
};
61+
const result = shift.position.call(context, { top: 10, left: 20 });
62+
expect(result).toEqual({ top: 110, left: 220 });
63+
});
64+
65+
it('handles negative shift values', () => {
66+
const context = {
67+
options: { shift: '-5 -10' }
68+
};
69+
const result = shift.position.call(context, { top: 10, left: 20 });
70+
expect(result).toEqual({ top: 5, left: 10 });
71+
});
72+
});
73+
});

0 commit comments

Comments
 (0)