Skip to content

Commit 6da2e9a

Browse files
author
Zaydek Michels-Gualtieri
committed
Changed userAgent implementation to use getters because history relies on the runtime value for the user agent. Added back all the history tests.
1 parent 5ee1953 commit 6da2e9a

2 files changed

Lines changed: 33 additions & 39 deletions

File tree

src/RichTextEditor/utils/keyDownTypeFor/history.test.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,18 @@ test("redo(...); non-macOS", () => {
5454
})).toBeTruthy()
5555
})
5656

57-
// // FIXME: Should be working; broken most likely due to eager isCtrlOrMetaKey evaluation
58-
// test("redo(...); macOS", () => {
59-
// mockMacOS()
60-
// expect(history.redo({
61-
// shiftKey: false,
62-
// ctrlKey: false,
63-
// metaKey: false,
64-
// keyCode: keyCodeFor("Z"),
65-
// })).not.toBeTruthy()
66-
// expect(history.redo({
67-
// shiftKey: true,
68-
// ctrlKey: false,
69-
// metaKey: true,
70-
// keyCode: keyCodeFor("Z"),
71-
// })).toBeTruthy()
72-
// })
57+
test("redo(...); macOS", () => {
58+
mockMacOS()
59+
expect(history.redo({
60+
shiftKey: false,
61+
ctrlKey: false,
62+
metaKey: false,
63+
keyCode: keyCodeFor("Z"),
64+
})).not.toBeTruthy()
65+
expect(history.redo({
66+
shiftKey: true,
67+
ctrlKey: false,
68+
metaKey: true,
69+
keyCode: keyCodeFor("Z"),
70+
})).toBeTruthy()
71+
})

src/lib/Client/userAgent/index.js

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

8-
// TODO: Add testedAppleDevice?
9-
// TODO: Add testedAndroidDevice?
10-
const userAgent = {
11-
// https://apple.com
12-
isAAPL: testUserAgent("Mac OS X"),
13-
// https://android.com
14-
isGOOG: testUserAgent("Android"),
15-
}
8+
// TODO: Refactor to isAppleDevice?
9+
// TODO: Refactor to isAndroidDevice?
10+
const userAgent = process.env.NODE_ENV === "test"
11+
? Object.freeze({
12+
// https://apple.com
13+
get isAAPL() {
14+
return testUserAgent("Mac OS X")
15+
},
16+
// https://android.com
17+
get isGOOG() {
18+
return testUserAgent("Android")
19+
},
20+
}) : Object.freeze({
21+
// https://apple.com
22+
isAAPL: testUserAgent("Mac OS X"),
23+
// https://android.com
24+
isGOOG: testUserAgent("Android"),
25+
})
1626

1727
export default userAgent
18-
19-
// const userAgent = {
20-
// // Tests the user agent for a substring.
21-
// //
22-
// // https://css-tricks.com/snippets/javascript/test-mac-pc-javascript
23-
// test(substr) {
24-
// return navigator.userAgent.indexOf(substr) >= 0
25-
// },
26-
// // https://apple.com
27-
// isAAPL: this.test("Mac OS X"),
28-
// // https://android.com
29-
// isGOOG: this.test("Android"),
30-
// }
31-
//
32-
// export default userAgent

0 commit comments

Comments
 (0)