-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46c28a6
commit 7430198
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
import { mobileOSDetectAsync, getOSNameWithUAParser } from "../mobileOSDetectAsync.utils"; | ||
import UAParser from "ua-parser-js"; | ||
|
||
describe("mobileOSDetectAsync", () => { | ||
test('should return "Windows Phone" for Windows Phone user agent', async () => { | ||
jest.spyOn(window.navigator, "userAgent", "get").mockReturnValue("windows phone"); | ||
expect(await mobileOSDetectAsync()).toBe("Windows Phone"); | ||
}); | ||
|
||
test('should return "Android" for Android user agent', async () => { | ||
jest.spyOn(window.navigator, "userAgent", "get").mockReturnValue("android"); | ||
expect(await mobileOSDetectAsync()).toBe("Android"); | ||
}); | ||
|
||
test('should return "iOS" for iOS user agent', async () => { | ||
jest.spyOn(window.navigator, "userAgent", "get").mockReturnValue("iPhone"); | ||
jest.spyOn(window, "MSStream", "get").mockReturnValue({ | ||
msClose: () => {}, | ||
msDetachStream: () => {}, | ||
type: "someType", | ||
}); | ||
expect(await mobileOSDetectAsync()).toBe("iOS"); | ||
}); | ||
|
||
test('should return "iOS" for iOS user agent', async () => { | ||
jest.spyOn(window.navigator, "userAgent", "get").mockReturnValue("iPhone"); | ||
jest.spyOn(window, "MSStream", "get").mockReturnValue({ | ||
msClose: () => {}, | ||
msDetachStream: () => {}, | ||
type: "someType", | ||
}); | ||
expect(await mobileOSDetectAsync()).toBe("iOS"); | ||
}); | ||
|
||
test('should return "unknown" for unknown user agent', async () => { | ||
jest.spyOn(window.navigator, "userAgent", "get").mockReturnValue("unknown"); | ||
expect(await mobileOSDetectAsync()).toBe("unknown"); | ||
}); | ||
|
||
test("should return the OS name", () => { | ||
jest.spyOn(UAParser, "OS", "get").mockReturnValue({ NAME: "name", VERSION: "version" }); | ||
expect(getOSNameWithUAParser()).toBe("name"); | ||
}); | ||
}); |