import { Platform } from 'react-native';
import sinon from 'sinon';

describe('typography', function () {
  let selectStub;

  beforeEach(function () {
    jest.resetModules();
    selectStub = sinon.stub(Platform, 'select');
  });

  afterEach(function () {
    selectStub.restore();
  });

  describe('setFont', function () {
    it('with existing weight in Android', function () {
      Platform.OS = 'android';
      selectStub.callsFake((args) => args.android);
      const { typography, setFont } = require('./typography');
      expect(
        setFont({
          fontFamily: typography.fonts.regular,
          fontWeight: typography.fontWeight.bold,
        }),
      ).toStrictEqual({
        fontFamily: 'Inter-Bold',
      });
    });

    it('with existing weight in Android but with fount != Inter', function () {
      Platform.OS = 'android';
      selectStub.callsFake((args) => args.android);
      const { typography, setFont } = require('./typography');
      expect(
        setFont({
          fontFamily: 'Montserrat',
          fontWeight: typography.fontWeight.bold,
        }),
      ).toStrictEqual({
        fontFamily: 'Montserrat',
        fontWeight: typography.fontWeight.bold,
      });
    });

    it('without font family in Android', function () {
      Platform.OS = 'android';
      selectStub.callsFake((args) => args.android);
      const { typography, setFont } = require('./typography');
      expect(
        setFont({
          fontWeight: typography.fontWeight.bold,
        }),
      ).toStrictEqual({
        fontWeight: typography.fontWeight.bold,
      });
    });

    it('with existing weight in iOS', function () {
      Platform.OS = 'ios';
      selectStub.callsFake((args) => args.ios);
      const { typography, setFont } = require('./typography');
      expect(
        setFont({
          fontFamily: typography.fonts.regular,
          fontWeight: typography.fontWeight.bold,
        }),
      ).toStrictEqual({
        fontFamily: 'Inter',
        fontWeight: 'bold',
      });
    });

    it('with non existing weight in Android', function () {
      Platform.OS = 'android';
      selectStub.callsFake((args) => args.android);
      const { typography, setFont } = require('./typography');
      expect(
        setFont({
          fontFamily: typography.fonts.bold,
          fontWeight: 'lorem',
        }),
      ).toStrictEqual({
        fontFamily: 'Inter-Regular',
      });
    });

    it('with non existing weight in iOS', function () {
      Platform.OS = 'ios';
      selectStub.callsFake((args) => args.ios);
      const { typography, setFont } = require('./typography');
      expect(
        setFont({
          fontFamily: typography.fonts.regular,
          fontWeight: 'lorem',
        }),
      ).toStrictEqual({
        fontFamily: 'Inter',
        fontWeight: 'lorem',
      });
    });
  });
});
