Skip to content

Commit 6e3c47f

Browse files
committed
test: add unit tests for getSnapAlignOffset utility
1 parent 5626fb1 commit 6e3c47f

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

src/utils/getSnapAlignOffset.spec.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { describe, expect, test } from 'vitest'
2+
3+
import { getSnapAlignOffset } from './getSnapAlignOffset'
4+
5+
describe('getSnapAlignOffset', () => {
6+
describe('with itemsToShow parameter', () => {
7+
test('should return correct offset for start alignment', () => {
8+
expect(getSnapAlignOffset({ align: 'start', itemsToShow: 3 })).toBe(0)
9+
})
10+
11+
test('should return correct offset for center/center-odd alignment', () => {
12+
expect(getSnapAlignOffset({ align: 'center', itemsToShow: 3 })).toBe(1)
13+
expect(getSnapAlignOffset({ align: 'center-odd', itemsToShow: 5 })).toBe(2)
14+
})
15+
16+
test('should return correct offset for center-even alignment', () => {
17+
expect(getSnapAlignOffset({ align: 'center-even', itemsToShow: 4 })).toBe(1)
18+
})
19+
20+
test('should return correct offset for end alignment', () => {
21+
expect(getSnapAlignOffset({ align: 'center-even', itemsToShow: 4 })).toBe(1)
22+
})
23+
})
24+
25+
describe('with slideSize and viewportSize parameters', () => {
26+
test('should return correct offset for start alignment', () => {
27+
expect(
28+
getSnapAlignOffset({
29+
align: 'start',
30+
slideSize: 200,
31+
viewportSize: 800,
32+
})
33+
).toBe(0)
34+
})
35+
36+
test('should return correct offset for center/center-odd alignment', () => {
37+
expect(
38+
getSnapAlignOffset({
39+
align: 'center',
40+
slideSize: 200,
41+
viewportSize: 800,
42+
})
43+
).toBe(300)
44+
45+
expect(
46+
getSnapAlignOffset({
47+
align: 'center-odd',
48+
slideSize: 200,
49+
viewportSize: 800,
50+
})
51+
).toBe(300)
52+
})
53+
54+
test('should return correct offset for center-even alignment', () => {
55+
expect(
56+
getSnapAlignOffset({
57+
align: 'center-even',
58+
slideSize: 200,
59+
viewportSize: 800,
60+
})
61+
).toBe(200)
62+
})
63+
64+
test('should return correct offset for end alignment', () => {
65+
expect(
66+
getSnapAlignOffset({
67+
align: 'end',
68+
slideSize: 200,
69+
viewportSize: 800,
70+
})
71+
).toBe(600)
72+
})
73+
})
74+
75+
describe('edge cases', () => {
76+
test('should return 0 when no parameters provided', () => {
77+
expect(getSnapAlignOffset({ align: 'start' })).toBe(0)
78+
})
79+
80+
test('should return 0 for invalid alignment', () => {
81+
expect(
82+
getSnapAlignOffset({
83+
align: 'invalid' as any,
84+
slideSize: 200,
85+
viewportSize: 800,
86+
})
87+
).toBe(0)
88+
})
89+
90+
test('should handle equal viewport and slide sizes', () => {
91+
expect(
92+
getSnapAlignOffset({
93+
align: 'center',
94+
slideSize: 800,
95+
viewportSize: 800,
96+
})
97+
).toBe(0)
98+
})
99+
})
100+
})

0 commit comments

Comments
 (0)