-
-
Notifications
You must be signed in to change notification settings - Fork 641
Expand file tree
/
Copy pathwidth.test.js
More file actions
72 lines (62 loc) · 2.52 KB
/
Copy pathwidth.test.js
File metadata and controls
72 lines (62 loc) · 2.52 KB
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
import { describe, it, expect } from 'vitest';
import { widthToColumnSpan, widthToPercentage } from '../util/width.js';
describe('widthToColumnSpan', () => {
it('passes spans through', () => {
for (let span = 1; span <= 12; span++) {
expect(widthToColumnSpan(span)).toBe(span);
}
});
it('resolves the percentages that shipped before spans', () => {
expect(widthToColumnSpan(25)).toBe(3);
expect(widthToColumnSpan(33)).toBe(4);
expect(widthToColumnSpan(50)).toBe(6);
expect(widthToColumnSpan(66)).toBe(8);
expect(widthToColumnSpan(75)).toBe(9);
expect(widthToColumnSpan(100)).toBe(12);
});
it('does not resolve the widgets-only size keywords', () => {
expect(widthToColumnSpan('sm')).toBe(12);
expect(widthToColumnSpan('md')).toBe(12);
expect(widthToColumnSpan('lg')).toBe(12);
expect(widthToColumnSpan('full')).toBe(12);
});
it('treats numbers above twelve as percentages', () => {
expect(widthToColumnSpan(13)).toBe(2);
expect(widthToColumnSpan(40)).toBe(5);
expect(widthToColumnSpan(90)).toBe(11);
});
it('clamps percentages beyond a full row', () => {
expect(widthToColumnSpan(200)).toBe(12);
});
it('handles numeric strings', () => {
expect(widthToColumnSpan('50')).toBe(6);
expect(widthToColumnSpan('6')).toBe(6);
});
it('falls back to full width for anything it does not recognise', () => {
expect(widthToColumnSpan(undefined)).toBe(12);
expect(widthToColumnSpan(null)).toBe(12);
expect(widthToColumnSpan('')).toBe(12);
expect(widthToColumnSpan('huge')).toBe(12);
expect(widthToColumnSpan(0)).toBe(12);
expect(widthToColumnSpan(-5)).toBe(12);
expect(widthToColumnSpan(7.5)).toBe(12);
});
});
describe('widthToPercentage', () => {
it('leaves percentages alone', () => {
expect(widthToPercentage(25)).toBe(25);
expect(widthToPercentage(33)).toBe(33);
expect(widthToPercentage(66)).toBe(66);
expect(widthToPercentage(100)).toBe(100);
});
it('derives a percentage from a span', () => {
expect(widthToPercentage(3)).toBe(25);
expect(widthToPercentage(4)).toBe(33);
expect(widthToPercentage(6)).toBe(50);
expect(widthToPercentage(9)).toBe(75);
expect(widthToPercentage(12)).toBe(100);
});
it('reports an unrecognised width as full width', () => {
expect(widthToPercentage(undefined)).toBe(100);
});
});