// @flow
import {
  _whiteLabelShadingValues,
  _generateAuxColors,
  _generateBrandColors,
  _getColorPaletteOverrides,
} from './theme.utils';

describe('Theme utils', () => {
  describe('_whiteLabelShadingValues', () => {
    it('has the right values', () => {
      expect(_whiteLabelShadingValues.dark).toEqual(0.3);
      expect(_whiteLabelShadingValues.fg).toEqual(0.5);
      expect(_whiteLabelShadingValues.bg).toEqual(0.5);
    });
  });

  describe('_generateAuxColors', () => {
    it('generates the 4 auxiliary colours', () => {
      const results = _generateAuxColors('#ff3399');

      expect(results['aux-1']).toEqual('#FFCCE6');
      expect(results['aux-2']).toEqual('#ff3399');
      expect(results['aux-3']).toEqual('#D6006B');
      expect(results['aux-4']).toEqual('#99004D');
    });
  });

  describe('_generateBrandColors', () => {
    it('can override primary colours', () => {
      const results = _generateBrandColors('primary', '#ff3399');

      expect(results['brand-primary-base']).toBeDefined();
      expect(results['brand-primary-fg']).toBeDefined();
      expect(results['brand-primary-bg']).toBeDefined();
    });

    it('can override secondary colours', () => {
      const results = _generateBrandColors('secondary', '#4286f4');

      expect(results['brand-secondary-base']).toBeDefined();
      expect(results['brand-secondary-fg']).toBeDefined();
      expect(results['brand-secondary-bg']).toBeDefined();
    });

    describe('with missing arguments', () => {
      it('returns an empty object', () => {
        expect(_generateBrandColors('secondary', null)).toEqual({});
        expect(_generateBrandColors('secondary', undefined)).toEqual({});
      });
    });
  });

  describe('_getColorPaletteOverrides', () => {
    const mockColorPalette = {
      // Backgrounds
      white: '#ffffff',
      background: '#fafafa',

      // Greys
      'greyscale-black': '#333333',
      'greyscale-dark': '#737373',
      'greyscale-medium': '#bfbfbf',
      'greyscale-light': '#e6e6e6',

      // Brand colours - primary
      'brand-primary-base': '#b347b3',
      'brand-primary-fg': '#662966',
      'brand-primary-bg': '#fff2ff',

      // Brand colours - secondary
      'brand-secondary-base': '#3689b3',
      'brand-secondary-fg': '#1f4e66',
      'brand-secondary-bg': '#e6f7ff',

      // Flash messages
      'error-fg': '#B82E14',
      'error-bg': '#ffe6e6',
      'success-fg': '#2a8000',
      'success-bg': '#def2da',
      'info-fg': '#A85A00',
      'info-bg': '#fff7e6',

      // Auxiliary colours
      'aux-1': '#fff2ff',
      'aux-2': '#b347b3',
      'aux-3': '#993d99',
      'aux-4': '#662966',
    };

    it('applies all of the colours provided', () => {
      const results = _getColorPaletteOverrides(
        mockColorPalette,
        '#ff3399',
        '#4286f4',
      );

      // Provided colours
      expect(results['brand-primary-base']).toEqual('#ff3399');
      expect(results['brand-secondary-base']).toEqual('#4286f4');

      // Overrides
      expect(results['brand-primary-fg']).toEqual('#99004D');
      expect(results['brand-primary-bg']).toEqual('#FFCCE6');

      expect(results['brand-secondary-fg']).toEqual('#093D92');
      expect(results['brand-secondary-bg']).toEqual('#D4E4FD');

      expect(results['aux-1']).toEqual('#FFCCE6');
      expect(results['aux-2']).toEqual('#ff3399');
      expect(results['aux-3']).toEqual('#D6006B');
      expect(results['aux-4']).toEqual('#99004D');

      // Doesn't change flash messsages
      expect(results['error-fg']).toEqual(mockColorPalette['error-fg']);
      expect(results['error-bg']).toEqual(mockColorPalette['error-bg']);
      expect(results['success-fg']).toEqual(mockColorPalette['success-fg']);
      expect(results['success-bg']).toEqual(mockColorPalette['success-bg']);
      expect(results['info-fg']).toEqual(mockColorPalette['info-fg']);
      expect(results['info-bg']).toEqual(mockColorPalette['info-bg']);
    });
  });
});
