Skip to content

Commit

Permalink
fix coverage problems and add color component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro-Gonzalez committed Apr 22, 2022
1 parent f4a49c4 commit 5912a4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"enzyme-to-json/serializer"
],
"collectCoverageFrom": [
"src/**/*.{js,jsx,mjs}"
"<rootDir>/src/**/*.{js,jsx,mjs}",
"!<rootDir>/src/**/index.{js,jsx,mjs}"
],
"coveragePathIgnorePatterns": [
"<rootDir>/src/docs"
Expand Down
15 changes: 11 additions & 4 deletions src/components/Color/Color.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import React from 'react';
import Color from 'components/Color';
import { create } from 'react-test-renderer';
import { getColor } from 'theme/utils';
import 'jest-styled-components';

describe('Color component', () => {
test('must receive a color name/code', () => {
const wrapper = create(<Color color="black" />);
expect(wrapper.root.props).toBeDefined();
});

test("should render nothing if a color wasn't provided", () => {
const wrapper = create(<Color />);
expect(wrapper.toJSON()).toBeNull();
});

test('should render the proper hex code label if showLabel is truthy', () => {
const color = 'statusRed';

Expand All @@ -23,25 +26,29 @@ describe('Color component', () => {

expect(hexaLabel).toBe('#FF4343');
});
/* test('should contain a div to represent a color sample', () => {

test('should contain a div to represent a color sample', () => {
const wrapper = mount(<Color color="#ffbb00" />);
const sample = wrapper.find('div');
expect(sample.exists()).toBe(true);
});

test("must apply provided color as the inner div's background", () => {
const color = 'statusRed';
const wrapper = mount(<Color color={color} />);
const sample = wrapper.find('div').last();
expect(sample).toHaveStyleRule('background-color', findColorInTheme(color));
expect(sample).toHaveStyleRule('background-color', getColor(color));
});

test('should not render text if showLabel is false or undefined', () => {
const color = 'statusRed';
const wrapper = mount(<Color color={color} />);
expect(wrapper.find('span').exists()).toBe(false);
});

test('should render the proper hex code label if showLabel is truthy', () => {
const color = 'statusRed';
const wrapper = mount(<Color color={color} showLabel />);
expect(wrapper.getDOMNode().textContent).toBe(findColorInTheme(color));
}); */
expect(wrapper.getDOMNode().textContent).toBe(getColor(color));
});
});

0 comments on commit 5912a4a

Please sign in to comment.