From 7ef79981ddfdfebee8cea52799688bda0bebd57d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 5 May 2025 10:57:43 -0400 Subject: [PATCH] test: fix a test --- public/src/utils.common.js | 10 ++++++++-- test/utils.js | 10 +++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/public/src/utils.common.js b/public/src/utils.common.js index 66785a6467..0014b3ae85 100644 --- a/public/src/utils.common.js +++ b/public/src/utils.common.js @@ -507,9 +507,15 @@ const utils = { return str.toString().replace(escapeChars, replaceChar); }, - isAndroidBrowser: function () { + isAndroidBrowser: function (nua) { + if (!nua) { + if (typeof navigator !== 'undefined' && navigator.userAgent) { + nua = navigator.userAgent; + } else { + return false; + } + } // http://stackoverflow.com/questions/9286355/how-to-detect-only-the-native-android-browser - const nua = navigator.userAgent; return ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1)); }, diff --git a/test/utils.js b/test/utils.js index 68371c1afd..0af0de8bf6 100644 --- a/test/utils.js +++ b/test/utils.js @@ -285,18 +285,18 @@ describe('Utility Methods', () => { }); it('should return false if browser is not android', (done) => { - global.navigator = { + const navigator = { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36', }; - assert.equal(utils.isAndroidBrowser(), false); + assert.equal(utils.isAndroidBrowser(navigator.userAgent), false); done(); }); it('should return true if browser is android', (done) => { - global.navigator = { - userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Android /58.0.3029.96 Safari/537.36', + const navigator = { + userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36', }; - assert.equal(utils.isAndroidBrowser(), true); + assert.equal(utils.isAndroidBrowser(navigator.userAgent), true); done(); });