-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add isIpadOs device check (#114)
* add isIpadOs device check * chore: add hermes-estree to .flowconfig * feat: add iPadOs device check
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* @flow */ | ||
|
||
import { isIpadOs } from "../../../src/device"; | ||
|
||
describe("isIpadOs", () => { | ||
beforeEach(() => { | ||
window.navigator = {}; | ||
}); | ||
|
||
it("should return true when userAgent is Safari and has multiple maxTouchPoints", () => { | ||
window.navigator.userAgent = | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Safari/605.1.15"; | ||
// eslint-disable-next-line compat/compat | ||
window.navigator.maxTouchPoints = 5; | ||
const bool = isIpadOs(); | ||
if (!bool) { | ||
throw new Error(`Expected true, got ${JSON.stringify(bool)}`); | ||
} | ||
}); | ||
|
||
it("should return true when userAgent is Firefox and has multiple maxTouchPoints", () => { | ||
window.navigator.userAgent = | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15"; | ||
// eslint-disable-next-line compat/compat | ||
window.navigator.maxTouchPoints = 5; | ||
const bool = isIpadOs(); | ||
if (!bool) { | ||
throw new Error(`Expected true, got ${JSON.stringify(bool)}`); | ||
} | ||
}); | ||
|
||
it("should return true when userAgent is Chrome and has multiple maxTouchPoints", () => { | ||
window.navigator.userAgent = | ||
"Mozilla/5.0 (iPad; CPU OS 17_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/120.0.6099.119 Mobile/15E148 Safari/604.1"; | ||
// eslint-disable-next-line compat/compat | ||
window.navigator.maxTouchPoints = 5; | ||
const bool = isIpadOs(); | ||
if (!bool) { | ||
throw new Error(`Expected true, got ${JSON.stringify(bool)}`); | ||
} | ||
}); | ||
|
||
it("should return true when userAgent is iPad", () => { | ||
window.navigator.userAgent = "iPad"; | ||
const bool = isIpadOs(); | ||
if (!bool) { | ||
throw new Error(`Expected true, got ${JSON.stringify(bool)}`); | ||
} | ||
}); | ||
|
||
it("should return false when userAgent is Safari but has no touchpoints", () => { | ||
window.navigator.userAgent = | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Safari/605.1.15"; | ||
// eslint-disable-next-line compat/compat | ||
window.navigator.maxTouchPoints = 0; | ||
const bool = isIpadOs(); | ||
if (!bool) { | ||
throw new Error(`Expected false, got ${JSON.stringify(bool)}`); | ||
} | ||
}); | ||
|
||
it("should return false when userAgent contains iPhone", () => { | ||
window.navigator.userAgent = "iPhone"; | ||
const bool = isIpadOs(); | ||
if (!bool) { | ||
throw new Error(`Expected false, got ${JSON.stringify(bool)}`); | ||
} | ||
}); | ||
|
||
it("should return false when userAgent contains iPod", () => { | ||
window.navigator.userAgent = "iPod"; | ||
const bool = isIpadOs(); | ||
if (!bool) { | ||
throw new Error(`Expected false, got ${JSON.stringify(bool)}`); | ||
} | ||
}); | ||
}); |