This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getSizes.test.ts
81 lines (73 loc) · 2.07 KB
/
getSizes.test.ts
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
import getSizes, { Breakpoint } from "./getSizes";
describe("get sizes attribute", () => {
let args: { size: string; breakpoints?: Breakpoint[] };
let argsUnsorted: { size: string; breakpoints?: Breakpoint[] };
beforeEach(() => {
args = {
size: "100vw",
breakpoints: [
{
mediaMinWidth: "1440px",
size: "33vw",
},
{
mediaMinWidth: "960px",
size: "50vw",
},
{
mediaMinWidth: "720px",
size: "100vw",
},
{
mediaMinWidth: "480px",
},
],
};
argsUnsorted = {
size: "100vw",
breakpoints: [
{
mediaMinWidth: "480px",
},
{
mediaMinWidth: "960px",
size: "50vw",
},
{
mediaMinWidth: "720px",
size: "100vw",
},
{
mediaMinWidth: "1440px",
size: "33vw",
},
],
};
});
it("should return a string", () => {
expect(typeof getSizes(args)).toBe("string");
});
it("should return the correct string", () => {
expect(getSizes(args)).toBe(
"(min-width: 1440px) 33vw,(min-width: 960px) 50vw,(min-width: 720px) 100vw,(min-width: 480px) 100vw,100vw"
);
});
it("should return the correct string without breakpoints", () => {
delete args.breakpoints;
expect(getSizes(args)).toBe("100vw");
});
it("should sort breakpoints by media min width if second param is true", () => {
expect(getSizes(argsUnsorted, true)).toBe(
"(min-width: 1440px) 33vw,(min-width: 960px) 50vw,(min-width: 720px) 100vw,(min-width: 480px) 100vw,100vw"
);
});
it("should not sort breakpoints if second param is false", () => {
expect(getSizes(argsUnsorted, false)).toBe(
"(min-width: 480px) 100vw,(min-width: 960px) 50vw,(min-width: 720px) 100vw,(min-width: 1440px) 33vw,100vw"
);
});
it("should return the correct string without breakpoints if second param is true", () => {
delete args.breakpoints;
expect(getSizes(args, true)).toBe("100vw");
});
});