mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 10:24:05 +00:00
017f229cfc
A switch in the account settings, inside the app on a device that can unlock that way (iOS LocalAuthentication, Android BiometricPrompt with the screen lock as fallback). Turning it on asks once, so nobody locks themselves out. With it on, TREK asks at launch and after half a minute in the background before showing anything, and the app switcher shows a blurred cover (iOS) or no snapshot (Android) instead of the screen. The setting stays on the device, not the account.
56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { fireEvent, render, screen, waitFor } from '../../../../tests/helpers/render';
|
|
import {
|
|
appLockSupported,
|
|
biometryAvailable,
|
|
isAppLockEnabled,
|
|
setAppLockEnabled,
|
|
unlockApp,
|
|
} from '../../../native/appLock';
|
|
import MAppLockCard from './MAppLockCard';
|
|
|
|
vi.mock('../../../native/appLock', () => ({
|
|
appLockSupported: vi.fn(),
|
|
biometryAvailable: vi.fn(),
|
|
isAppLockEnabled: vi.fn(),
|
|
setAppLockEnabled: vi.fn(async () => {}),
|
|
unlockApp: vi.fn(),
|
|
}));
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
vi.mocked(appLockSupported).mockReturnValue(true);
|
|
vi.mocked(biometryAvailable).mockResolvedValue({ available: true, type: 'faceID' });
|
|
vi.mocked(isAppLockEnabled).mockReturnValue(false);
|
|
vi.mocked(unlockApp).mockResolvedValue(true);
|
|
});
|
|
|
|
describe('MAppLockCard', () => {
|
|
it('turns the lock on only after one successful unlock', async () => {
|
|
render(<MAppLockCard />);
|
|
const toggle = await screen.findByRole('switch');
|
|
vi.mocked(unlockApp).mockResolvedValueOnce(false);
|
|
fireEvent.click(toggle);
|
|
await waitFor(() => expect(unlockApp).toHaveBeenCalledTimes(1));
|
|
expect(setAppLockEnabled).not.toHaveBeenCalled();
|
|
|
|
fireEvent.click(toggle);
|
|
await waitFor(() => expect(setAppLockEnabled).toHaveBeenCalledWith(true));
|
|
});
|
|
|
|
it('turns it off without asking', async () => {
|
|
vi.mocked(isAppLockEnabled).mockReturnValue(true);
|
|
render(<MAppLockCard />);
|
|
fireEvent.click(await screen.findByRole('switch'));
|
|
await waitFor(() => expect(setAppLockEnabled).toHaveBeenCalledWith(false));
|
|
expect(unlockApp).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('is not offered on a device without Face ID, Touch ID or a passcode', async () => {
|
|
vi.mocked(biometryAvailable).mockResolvedValue({ available: false, type: 'none' });
|
|
const { container } = render(<MAppLockCard />);
|
|
await waitFor(() => expect(biometryAvailable).toHaveBeenCalled());
|
|
expect(container).toBeEmptyDOMElement();
|
|
});
|
|
});
|