Skip to content

Commit da4c5d7

Browse files
author
Zaydek Michels-Gualtieri
committed
Updated userAgent test suite
1 parent 6da2e9a commit da4c5d7

2 files changed

Lines changed: 11 additions & 44 deletions

File tree

src/lib/Client/userAgent/index.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,16 @@ function testUserAgent(substr) {
55
return navigator.userAgent.indexOf(substr) >= 0
66
}
77

8-
// TODO: Refactor to isAppleDevice?
9-
// TODO: Refactor to isAndroidDevice?
8+
// Tests the user agent.
9+
//
10+
// TODO: Rename to userAgent.isApple?
1011
const userAgent = process.env.NODE_ENV === "test"
1112
? Object.freeze({
12-
// https://apple.com
1313
get isAAPL() {
1414
return testUserAgent("Mac OS X")
1515
},
16-
// https://android.com
17-
get isGOOG() {
18-
return testUserAgent("Android")
19-
},
2016
}) : Object.freeze({
21-
// https://apple.com
2217
isAAPL: testUserAgent("Mac OS X"),
23-
// https://android.com
24-
isGOOG: testUserAgent("Android"),
2518
})
2619

2720
export default userAgent
Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,16 @@
1-
// NOTE: import userAgent from "..." breaks the test runner.
1+
import userAgent from "./index"
2+
3+
import { // Unsorted
4+
mockNonMacOS,
5+
mockMacOS,
6+
} from "lib/Client/mockUserAgent"
27

3-
// https://stackoverflow.com/a/25518045
48
test("isAAPL=false", () => {
5-
Object.defineProperty(window.navigator, "userAgent", {
6-
value: "...",
7-
configurable: true,
8-
})
9-
const isAAPL = navigator.userAgent.indexOf("Mac OS X") >= 0
10-
const userAgent = { isAAPL }
9+
mockNonMacOS()
1110
expect(userAgent.isAAPL).not.toBeTruthy()
1211
})
1312

1413
test("isAAPL=true", () => {
15-
Object.defineProperty(window.navigator, "userAgent", {
16-
value: "... Mac OS X ...",
17-
configurable: true,
18-
})
19-
const isAAPL = navigator.userAgent.indexOf("Mac OS X") >= 0
20-
const userAgent = { isAAPL }
14+
mockMacOS()
2115
expect(userAgent.isAAPL).toBeTruthy()
2216
})
23-
24-
test("isGOOG=false", () => {
25-
Object.defineProperty(window.navigator, "userAgent", {
26-
value: "...",
27-
configurable: true,
28-
})
29-
const isGOOG = navigator.userAgent.indexOf("Android") >= 0
30-
const userAgent = { isGOOG }
31-
expect(userAgent.isGOOG).not.toBeTruthy()
32-
})
33-
34-
test("isGOOG=true", () => {
35-
Object.defineProperty(window.navigator, "userAgent", {
36-
value: "... Android ...",
37-
configurable: true,
38-
})
39-
const isGOOG = navigator.userAgent.indexOf("Android") >= 0
40-
const userAgent = { isGOOG }
41-
expect(userAgent.isGOOG).toBeTruthy()
42-
})

0 commit comments

Comments
 (0)