-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathindex.spec.ts
139 lines (131 loc) · 4.85 KB
/
index.spec.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { Dimensions } from "react-native";
export const mockPlatform = (
OS: "ios" | "android",
isPad: boolean,
isTVOS: boolean
) => {
jest.doMock("react-native/Libraries/Utilities/Platform", () => {
const Platform = jest.requireActual(
"react-native/Libraries/Utilities/Platform"
);
return {
...Platform,
isPad,
isTVOS,
OS,
select: (plataformas: { [x: string]: string }) => plataformas[OS],
};
});
};
jest.mock("react-native/Libraries/Utilities/Dimensions", () => {
let dimensionsMock = jest.fn();
const Dimensions = jest.requireActual(
"react-native/Libraries/Utilities/Dimensions"
);
Dimensions.get = dimensionsMock;
return Dimensions;
});
export const mockCanvasSize = (width: number, height: number) => {
Dimensions.get.mockClear();
Dimensions.get.mockReturnValue({
width,
height,
});
};
describe("getStatusBarHeight", () => {
describe("iOS", () => {
let getStatusBarHeight: (skipAndroid?: boolean) => number;
beforeEach(() => {
jest.resetModules();
mockPlatform("ios", false, false);
});
test("Should return 20 when device is iOS and is iPad", () => {
jest.resetModules();
mockPlatform("ios", true, false);
mockCanvasSize(375, 812);
getStatusBarHeight = require("./").getStatusBarHeight;
const expectedSize = 20;
expect(getStatusBarHeight()).toBe(expectedSize);
});
test("Should return 20 when device is iOS and is tvOS", () => {
jest.resetModules();
mockPlatform("ios", false, true);
mockCanvasSize(375, 812);
getStatusBarHeight = require("./").getStatusBarHeight;
const expectedSize = 20;
expect(getStatusBarHeight()).toBe(expectedSize);
});
test("Should return 20 when device is iOS and have less width than iPhone X", () => {
mockCanvasSize(374, 812);
getStatusBarHeight = require("./").getStatusBarHeight;
const expectedSize = 20;
expect(getStatusBarHeight()).toBe(expectedSize);
});
test("Should return 20 when device is iOS and have less height than iPhone X", () => {
mockCanvasSize(375, 811);
getStatusBarHeight = require("./").getStatusBarHeight;
const expectedSize = 20;
expect(getStatusBarHeight()).toBe(expectedSize);
});
test("Should return 44 when device is iOS and have iPhone X width and height", () => {
mockCanvasSize(375, 812);
getStatusBarHeight = require("./").getStatusBarHeight;
const expectedSize = 44;
expect(getStatusBarHeight()).toBe(expectedSize);
});
test("Should return 44 when device is iOS and have iPhone XS Max width and height", () => {
mockCanvasSize(414, 896);
getStatusBarHeight = require("./").getStatusBarHeight;
const expectedSize = 44;
expect(getStatusBarHeight()).toBe(expectedSize);
});
test("Should return 44 when device is iOS and have iPhone 12 width and height", () => {
mockCanvasSize(390, 844);
getStatusBarHeight = require("./").getStatusBarHeight;
const expectedSize = 47;
expect(getStatusBarHeight()).toBe(expectedSize);
});
test("Should return 44 when device is iOS and have iPhone 12 Max width and height", () => {
mockCanvasSize(428, 926);
getStatusBarHeight = require("./").getStatusBarHeight;
const expectedSize = 47;
expect(getStatusBarHeight()).toBe(expectedSize);
});
test("Should return 49 when device is iOS and have iPhone 14 Max width and height", () => {
mockCanvasSize(393, 852);
getStatusBarHeight = require("./").getStatusBarHeight;
const expectedSize = 49;
expect(getStatusBarHeight()).toBe(expectedSize);
});
test("Should return 49 when device is iOS and have iPhone 14 Pro Max width and height", () => {
mockCanvasSize(430, 932);
getStatusBarHeight = require("./").getStatusBarHeight;
const expectedSize = 49;
expect(getStatusBarHeight()).toBe(expectedSize);
});
});
describe("Android", () => {
let getStatusBarHeight: (skipAndroid?: boolean) => number;
beforeEach(() => {
jest.resetModules();
mockPlatform("android", false, false);
jest.mock("react-native/Libraries/Components/StatusBar/StatusBar", () => {
return {
currentHeight: 50,
};
});
});
test("Should return 50 from status bar size when device is Android and skipAndroid flag is false", () => {
mockCanvasSize(428, 926);
getStatusBarHeight = require("./").getStatusBarHeight;
const expectedSize = 50;
expect(getStatusBarHeight()).toBe(expectedSize);
});
test("Should return 0 from status bar size when device is Android and skipAndroid flag is true", () => {
mockCanvasSize(428, 926);
getStatusBarHeight = require("./").getStatusBarHeight;
const expectedSize = 0;
expect(getStatusBarHeight(true)).toBe(expectedSize);
});
});
});