import { checkIfUserAgentIsMobile, isMobile } from '@utils/mobile';

describe('checkIfUserAgentIsMobile', () => {
    it('should return false for desktop device', () => {
        const userAgent =
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36';

        expect(checkIfUserAgentIsMobile(userAgent)).toBe(false);
    });

    it('should return true for mobile android device', () => {
        const userAgent =
            'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19';

        expect(checkIfUserAgentIsMobile(userAgent)).toBe(true);
    });

    it('should return true for mobile ios device with chrome', () => {
        const userAgent =
            'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1';

        expect(checkIfUserAgentIsMobile(userAgent)).toBe(true);
    });

    it('should return true for mobile ios device with safari', () => {
        const userAgent =
            'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/603.1.23 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1';

        expect(checkIfUserAgentIsMobile(userAgent)).toBe(true);
    });
});

describe('isMobile', () => {
    it('returns true for mobile userAgent', () => {
        spyOnProperty(window.navigator, 'userAgent').and.returnValue(
            'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/603.1.23 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1',
        );

        expect(isMobile()).toBe(true);
    });

    it('returns true for mobile vendor', () => {
        spyOnProperty(window.navigator, 'userAgent').and.returnValue(undefined);
        spyOnProperty(window.navigator, 'vendor').and.returnValue(
            'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/603.1.23 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1',
        );

        expect(isMobile()).toBe(true);
    });

    it('returns true for mobile window.opera', () => {
        spyOnProperty(window.navigator, 'userAgent').and.returnValue(undefined);
        spyOnProperty(window.navigator, 'vendor').and.returnValue(undefined);
        (window as any).opera =
            'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/603.1.23 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1';

        expect(isMobile()).toBe(true);
    });

    it('returns false for desktop userAgent', () => {
        spyOnProperty(window.navigator, 'userAgent').and.returnValue(
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36',
        );

        expect(isMobile()).toBe(false);
    });
});
