UNPKG

6.05 kBPlain TextView Raw
1import isMobile, { isMobileResult } from '../';
2
3describe('Apple', () => {
4 let mobile: isMobileResult;
5 let userAgent: string;
6
7 describe('iPhone UserAgent', () => {
8 beforeEach(() => {
9 userAgent =
10 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3';
11 mobile = isMobile(userAgent);
12 });
13
14 test('should be an iPhone', () => {
15 expect(mobile.apple.phone).toBe(true);
16 });
17
18 test('should not be an iPad', () => {
19 expect(mobile.apple.tablet).not.toBe(true);
20 });
21
22 test('should not be an iPod', () => {
23 expect(mobile.apple.ipod).not.toBe(true);
24 });
25
26 test('should be matched as Any Phone', () => {
27 expect(mobile.phone).toBe(true);
28 });
29
30 test('should be an Apple device', () => {
31 expect(mobile.apple.device).toBe(true);
32 });
33 });
34
35 describe('iPad UserAgent', () => {
36 beforeEach(() => {
37 userAgent =
38 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10';
39 mobile = isMobile(userAgent);
40 });
41
42 test('should not be an iPhone', () => {
43 expect(mobile.apple.phone).not.toBe(true);
44 });
45
46 test('should be an iPad', () => {
47 expect(mobile.apple.tablet).toBe(true);
48 });
49
50 test('should not be an iPod', () => {
51 expect(mobile.apple.ipod).not.toBe(true);
52 });
53
54 test('should be matched as Any Tablet', () => {
55 expect(mobile.tablet).toBe(true);
56 });
57
58 test('should be an Apple device', () => {
59 expect(mobile.apple.device).toBe(true);
60 });
61 });
62
63 describe('iPad on iOS 13', () => {
64 beforeEach(() => {
65 const nav = {
66 userAgent:
67 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko)',
68 platform: 'MacIntel',
69 maxTouchPoints: 4,
70 };
71 mobile = isMobile(nav);
72 });
73
74 test('should not be an iPhone', () => {
75 expect(mobile.apple.phone).not.toBe(true);
76 });
77
78 test('should be an iPad', () => {
79 expect(mobile.apple.tablet).toBe(true);
80 });
81
82 test('should not be an iPod', () => {
83 expect(mobile.apple.ipod).not.toBe(true);
84 });
85
86 test('should be matched as Any Tablet', () => {
87 expect(mobile.tablet).toBe(true);
88 });
89
90 test('should be an Apple device', () => {
91 expect(mobile.apple.device).toBe(true);
92 });
93 });
94
95 describe('iPod UserAgent', () => {
96 beforeEach(() => {
97 userAgent =
98 'Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A101a Safari/419.3';
99 mobile = isMobile(userAgent);
100 });
101
102 test('should not be an iPhone', () => {
103 expect(mobile.apple.phone).not.toBe(true);
104 });
105
106 test('should not be an iPad', () => {
107 expect(mobile.apple.tablet).not.toBe(true);
108 });
109
110 test('should be an iPod', () => {
111 expect(mobile.apple.ipod).toBe(true);
112 });
113
114 test('should be an Apple device', () => {
115 expect(mobile.apple.device).toBe(true);
116 });
117 });
118
119 describe('Facebook iPhone App UserAgent', () => {
120 beforeEach(() => {
121 userAgent =
122 'Mozilla/5.0 (iPhone; CPU OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B410 [FBAN/FBIOS;FBAV/20.1.0.15.10;FBBV/5758778;FBDV/iPad5,4;FBMD/iPad;FBSN/iPhone OS;FBSV/8.1;FBSS/2; FBCR/;FBID/tablet;FBLC/fi_FI;FBOP/1]';
123 mobile = isMobile(userAgent);
124 });
125
126 test('should be an iPhone', () => {
127 expect(mobile.apple.phone).toBe(true);
128 });
129
130 test('should not be an iPad', () => {
131 expect(mobile.apple.tablet).not.toBe(true);
132 });
133
134 test('should not be an iPod', () => {
135 expect(mobile.apple.ipod).not.toBe(true);
136 });
137
138 test('should be an Apple device', () => {
139 expect(mobile.apple.device).toBe(true);
140 });
141 });
142
143 describe('Facebook iPad App UserAgent', () => {
144 beforeEach(() => {
145 userAgent =
146 'Mozilla/5.0 (iPad; CPU OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B410 [FBAN/FBIOS;FBAV/20.1.0.15.10;FBBV/5758778;FBDV/iPad5,4;FBMD/iPad;FBSN/iPhone OS;FBSV/8.1;FBSS/2; FBCR/;FBID/tablet;FBLC/fi_FI;FBOP/1]';
147 mobile = isMobile(userAgent);
148 });
149
150 test('should not be an iPhone', () => {
151 expect(mobile.apple.phone).not.toBe(true);
152 });
153
154 test('should be an iPad', () => {
155 expect(mobile.apple.tablet).toBe(true);
156 });
157
158 test('should not be an iPod', () => {
159 expect(mobile.apple.ipod).not.toBe(true);
160 });
161
162 test('should be an Apple device', () => {
163 expect(mobile.apple.device).toBe(true);
164 });
165 });
166
167 describe('Twitter iPhone App UserAgent', () => {
168 beforeEach(() => {
169 userAgent =
170 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_2_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13D15 Twitter for iPhone';
171 mobile = isMobile(userAgent);
172 });
173
174 test('should be an iPhone', () => {
175 expect(mobile.apple.phone).toBe(true);
176 });
177
178 test('should not be an iPad', () => {
179 expect(mobile.apple.tablet).not.toBe(true);
180 });
181
182 test('should not be an iPod', () => {
183 expect(mobile.apple.ipod).not.toBe(true);
184 });
185
186 test('should be an Apple device', () => {
187 expect(mobile.apple.device).toBe(true);
188 });
189 });
190
191 describe('Twitter iPad App UserAgent', () => {
192 beforeEach(() => {
193 userAgent =
194 'Mozilla/5.0 (iPad; CPU OS 9_2_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13D15 Twitter for iPhone';
195 mobile = isMobile(userAgent);
196 });
197
198 test('should not be an iPhone', () => {
199 expect(mobile.apple.phone).not.toBe(true);
200 });
201
202 test('should be an iPad', () => {
203 expect(mobile.apple.tablet).toBe(true);
204 });
205
206 test('should not be an iPod', () => {
207 expect(mobile.apple.ipod).not.toBe(true);
208 });
209
210 test('should be an Apple device', () => {
211 expect(mobile.apple.device).toBe(true);
212 });
213 });
214});