Skip to content

Commit ae0835d

Browse files
committed
Add user agent related method tests
1 parent afd6b8a commit ae0835d

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

test/jasmine/tests/lib_test.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,6 +2956,67 @@ describe('Test lib.js:', function() {
29562956
});
29572957
});
29582958
});
2959+
2960+
describe("User agent", () => {
2961+
const userAgentStrings = {
2962+
iOSSafari: "Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.4 Mobile/15E148 Safari/604.1",
2963+
iOSChrome: "Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/138.0.7204.156 Mobile/15E148 Safari/604.1",
2964+
macChrome: "Mozilla/5.0 (Macintosh; Intel Mac OS X 15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
2965+
macSafari: "Mozilla/5.0 (Macintosh; Intel Mac OS X 15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.4 Safari/605.1.15",
2966+
macWKWebView: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko)",
2967+
winFirefox: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0"
2968+
}
2969+
2970+
describe('isIOS', () => {
2971+
[userAgentStrings.iOSChrome, userAgentStrings.iOSSafari].forEach(uaString => {
2972+
it('matches an iOS user agent string', () => {
2973+
spyOnProperty(navigator, 'userAgent').and.returnValue(uaString)
2974+
expect(Lib.isIOS()).toBe(true)
2975+
})
2976+
})
2977+
2978+
it("doesn't match a non-iOS user agent string", () => {
2979+
spyOnProperty(navigator, 'userAgent').and.returnValue(userAgentStrings.macSafari)
2980+
expect(Lib.isIOS()).toBe(false)
2981+
})
2982+
})
2983+
2984+
describe('isSafari', () => {
2985+
it('matches a Safari user agent string', () => {
2986+
spyOnProperty(navigator, 'userAgent').and.returnValue(userAgentStrings.macSafari)
2987+
expect(Lib.isSafari()).toBe(true)
2988+
})
2989+
2990+
it("doesn't match a non-Safari user agent string", () => {
2991+
spyOnProperty(navigator, 'userAgent').and.returnValue(userAgentStrings.macChrome)
2992+
expect(Lib.isSafari()).toBe(false)
2993+
})
2994+
})
2995+
2996+
describe('isMacWKWebView', () => {
2997+
it('matches a Safari user agent string', () => {
2998+
spyOnProperty(navigator, 'userAgent').and.returnValue(userAgentStrings.macWKWebView)
2999+
expect(Lib.isMacWKWebView()).toBe(true)
3000+
})
3001+
3002+
it("doesn't match a non-Safari user agent string", () => {
3003+
spyOnProperty(navigator, 'userAgent').and.returnValue(userAgentStrings.macSafari)
3004+
expect(Lib.isMacWKWebView()).toBe(false)
3005+
})
3006+
})
3007+
3008+
describe('getFirefoxVersion', () => {
3009+
it('gets the Firefox version from the user agent string', () => {
3010+
spyOnProperty(navigator, 'userAgent').and.returnValue(userAgentStrings.winFirefox)
3011+
expect(Lib.getFirefoxVersion()).toBe(140)
3012+
})
3013+
3014+
it("returns null for a non-Firefox user agent string", () => {
3015+
spyOnProperty(navigator, 'userAgent').and.returnValue(userAgentStrings.macSafari)
3016+
expect(Lib.getFirefoxVersion()).toBe(null)
3017+
})
3018+
})
3019+
})
29593020
});
29603021

29613022
describe('Queue', function() {

0 commit comments

Comments
 (0)