-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
81 lines (70 loc) · 2.45 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// generateScale.test.js
const { generateScale, getConfig, getNextSize } = require('./index.js');
// Mock configurations to be used in tests
const mockConfig = {
classPrefix: 'p-',
classSuffix: '-s',
unit: 'px',
scale: 1,
from: 0,
to: 10,
increment: {
default: 1,
below: {
5: 0.5,
},
above: {
8: 2,
},
},
};
describe('generateScale', () => {
it('should generate a scale with the default configuration', () => {
const result = generateScale({});
expect(result).toEqual(expect.any(Object)); // Ensure result is an object
expect(Object.keys(result).length).toBeGreaterThan(0); // Ensure it generates classes
});
it('should generate a scale with custom configuration', () => {
const result = generateScale(mockConfig);
expect(result).toEqual({
'p-0-s': '0px',
'p-0.5-s': '0.5px',
'p-1-s': '1px',
'p-1.5-s': '1.5px',
'p-2-s': '2px',
'p-2.5-s': '2.5px',
'p-3-s': '3px',
'p-3.5-s': '3.5px',
'p-4-s': '4px',
'p-4.5-s': '4.5px',
'p-5-s': '5px',
'p-6-s': '6px',
'p-7-s': '7px',
'p-8-s': '8px',
'p-10-s': '10px', // increments by 2 after 8
});
});
});
// Additional tests for helper functions if they were exported
describe('getConfig', () => {
it('should merge custom config with default values', () => {
const config = getConfig({ classPrefix: 'test-' });
expect(config.classPrefix).toBe('test-');
expect(config.unit).toBe('rem'); // Check default
expect(config.increment.default).toBe(1); // Check default increment
});
});
describe('getNextSize', () => {
it('should return the correct next size based on default increment', () => {
const nextSize = getNextSize(10, { default: 2 }, [], []);
expect(nextSize).toBe(12);
});
it('should use below increment when applicable', () => {
const nextSize = getNextSize(6, { below: { 5: 0.5 }, default: 1 }, [5], []);
expect(nextSize).toBe(7); // Since size is not > 5, it uses default
});
it('should use above increment when applicable', () => {
const nextSize = getNextSize(9, { above: { 10: 2 }, default: 1 }, [], [10]);
expect(nextSize).toBe(10); // Uses default since current size is not <= 10 yet
});
});