import colorPalette from '../../../../theme/colors';
import { typographyBaseTheme } from '../../typographyTheme';
import {
  getTextSizingStyle,
  getTextColor,
  getTextColorOnBg,
  getTextCommonStyle,
  getTextOpacity,
} from '../textSelectors';

const theme = { typography: typographyBaseTheme };
const {
  opacities,
  colors,
  common,
  onBackground,
  text: { sizings },
} = typographyBaseTheme;

describe('textTheme selectors', () => {
  describe('getTextSizingStyle', () => {
    it.each(Object.keys(sizings))(
      'should return the correct size style object for %s size',
      sizing => {
        expect(getTextSizingStyle(theme, sizing)).toEqual(sizings[sizing]);
      }
    );

    it('should throw if size is not defined in the theme', () => {
      expect(() => getTextSizingStyle(theme, 'invalidSizing')).toThrow();
    });
  });

  describe('getTextOpacity', () => {
    it.each(Object.keys(opacities))(
      'should return the correct opacity for %s emphasis',
      emphasis => {
        expect(getTextOpacity(theme, emphasis)).toEqual(opacities[emphasis]);
      }
    );

    it('should throw if emphasis is not defined in the theme', () => {
      expect(() => getTextOpacity(theme, 'invalidEmphasis')).toThrow();
    });
  });

  describe('getTextColor', () => {
    it.each(Object.keys(colors))(
      'should return the correct color for %s',
      color => {
        expect(getTextColor(theme, color)).toEqual(colors[color]);
      }
    );

    it('should throw if color is not defined in the theme', () => {
      expect(() => getTextColor(theme, 'invalidColor')).toThrow();
    });
  });

  describe('getTextColorOnBg', () => {
    it('should default to the main text color theme if no corresponding background is found', () => {
      expect(getTextColorOnBg(theme, 'noop', 'primary')).toEqual(
        colors.primary
      );
    });

    Object.keys(onBackground).forEach(bgColor => {
      Object.keys(onBackground[bgColor]).forEach(color => {
        it(`should return the correct code for ${color} color for ${bgColor} background`, () => {
          expect(getTextColorOnBg(theme, bgColor, color)).toEqual(
            bgColor === 'warning'
              ? colorPalette.neutral1000
              : colorPalette.neutral0
          );
        });
      });
    });
  });

  describe('getTextCommonStyle', () => {
    it('should return the correct common style object', () => {
      expect(getTextCommonStyle(theme)).toEqual(common);
    });
  });
});

@@ -478,32 +478,24 @@
 () =%3E %7B%0A    
-it.each(
 Object.keys(
@@ -502,26 +502,47 @@
 sizings)
-)(
+.forEach(sizing =%3E %7B
 %0A      
-'
+it(%60
 should r
@@ -585,30 +585,27 @@
 for 
-%25s size',%0A      sizing
+$%7Bsizing%7D size%60, ()
  =%3E 
@@ -681,37 +681,40 @@
 izing%5D);%0A      %7D
+);
 %0A    
+%7D
 );%0A%0A    it('shou
@@ -894,32 +894,24 @@
 () =%3E %7B%0A    
-it.each(
 Object.keys(
@@ -920,26 +920,49 @@
 acities)
-)(
+.forEach(emphasis =%3E %7B
 %0A      
-'
+it(%60
 should r
@@ -995,19 +995,18 @@
 for 
-%25s 
+$%7B
 emphasis
 ',%0A 
@@ -1001,24 +1001,17 @@
 emphasis
-',%0A     
+%7D
  emphasi
@@ -1003,32 +1003,37 @@
 phasis%7D emphasis
+%60, ()
  =%3E %7B%0A        ex
@@ -1103,33 +1103,35 @@
 s%5D);%0A      %7D
+);
 %0A    
+%7D
 );%0A
-%0A
     it('shou
@@ -1319,16 +1319,8 @@
     
-it.each(
 Obje
@@ -1338,18 +1338,38 @@
 ors)
-)(
+.forEach(color =%3E %7B
 %0A      
-'
+it(%60
 shou
@@ -1394,34 +1394,27 @@
 ect 
+$%7B
 color
- for %25s',%0A     
+%7D
  color
+%60, ()
  =%3E 
@@ -1489,21 +1489,24 @@
 %0A      %7D
+);
 %0A    
+%7D
 );%0A%0A    

use forEach instead of it.each to be consistent