os: add isAndroid() function

This will be used to test if the app is running on Android.
This commit is contained in:
David Lechner
2021-08-12 15:55:24 -05:00
committed by David Lechner
parent a0130ada99
commit 56c739fa08
2 changed files with 23 additions and 1 deletions
+12 -1
View File
@@ -1,12 +1,23 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2021 The Pybricks Authors
import { isMacOS, isWindows, prefersDarkMode } from './os';
import { isAndroid, isMacOS, isWindows, prefersDarkMode } from './os';
afterEach(() => {
jest.resetAllMocks();
});
describe('isAndroid', () => {
test('is true', () => {
jest.spyOn(navigator, 'userAgent', 'get').mockReturnValue('Android');
expect(isAndroid()).toBeTruthy();
});
test('is false', () => {
jest.spyOn(navigator, 'userAgent', 'get').mockReturnValue('Linux');
expect(isAndroid()).toBeFalsy();
});
});
describe('isMacOS', () => {
test('is true', () => {
jest.spyOn(navigator, 'platform', 'get').mockReturnValue('MacIntel');