mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-06-23 03:19:51 +02:00
test: fix a test
This commit is contained in:
@@ -507,9 +507,15 @@ const utils = {
|
|||||||
return str.toString().replace(escapeChars, replaceChar);
|
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
|
// 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));
|
return ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -285,18 +285,18 @@ describe('Utility Methods', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return false if browser is not android', (done) => {
|
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',
|
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();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true if browser is android', (done) => {
|
it('should return true if browser is android', (done) => {
|
||||||
global.navigator = {
|
const 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',
|
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();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user