Skip to content
Snippets Groups Projects
Commit 010a76e9 authored by Aanand Prasad's avatar Aanand Prasad Committed by Jure
Browse files

test(ui): fix test failures

parent 3cebeec2
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,10 @@ const lightGrey = '#b3b3b3' ...@@ -6,6 +6,10 @@ const lightGrey = '#b3b3b3'
const mainGrey = '#666' const mainGrey = '#666'
const whiteRGBA = 'rgba(255, 255, 255, 1)' const whiteRGBA = 'rgba(255, 255, 255, 1)'
const borderRule = position => props => `
border-${position}-width: ${props.noBorder[position] ? '0' : '1px'};
`
const Root = styled.div.attrs({ const Root = styled.div.attrs({
role: 'presentation', role: 'presentation',
})` })`
...@@ -16,12 +20,10 @@ const Root = styled.div.attrs({ ...@@ -16,12 +20,10 @@ const Root = styled.div.attrs({
border-style: solid; border-style: solid;
border-color: ${mainGrey}; border-color: ${mainGrey};
border-top-width: ${props => (props.noBorder.top ? 0 : 1)}px; ${borderRule('top')} ${borderRule('right')} ${borderRule(
border-right-width: ${props => (props.noBorder.right ? 0 : 1)}px; 'bottom',
border-bottom-width: ${props => (props.noBorder.bottom ? 0 : 1)}px; )} ${borderRule('left')} background-color: ${props =>
border-left-width: ${props => (props.noBorder.left ? 0 : 1)}px; props.active ? mainGrey : 'transparent'};
background-color: ${props => (props.active ? mainGrey : 'transparent')};
&:hover { &:hover {
background-color: ${lightGrey}; background-color: ${lightGrey};
......
import React from 'react' import React from 'react'
import { shallow, mount } from 'enzyme' import { shallow, mount } from 'enzyme'
import renderer from 'react-test-renderer' import renderer from 'react-test-renderer'
import 'jest-styled-components'
import AlignmentBox from '../src/atoms/AlignmentBox' import AlignmentBox from '../src/atoms/AlignmentBox'
...@@ -22,9 +23,6 @@ const requiredProps = { ...@@ -22,9 +23,6 @@ const requiredProps = {
id: 'left', id: 'left',
} }
const wrapper = shallow(<AlignmentBox {...requiredProps} />)
const wrapperMounted = mount(<AlignmentBox {...requiredProps} />)
describe('AlignmentBox', () => { describe('AlignmentBox', () => {
test('is rendered correctly', () => { test('is rendered correctly', () => {
const tree = renderer.create(<AlignmentBox {...requiredProps} />).toJSON() const tree = renderer.create(<AlignmentBox {...requiredProps} />).toJSON()
...@@ -32,6 +30,8 @@ describe('AlignmentBox', () => { ...@@ -32,6 +30,8 @@ describe('AlignmentBox', () => {
}) })
test('gets the correct props', () => { test('gets the correct props', () => {
const wrapperMounted = mount(<AlignmentBox {...requiredProps} />)
const noBorderDefaults = { const noBorderDefaults = {
top: false, top: false,
bottom: false, bottom: false,
...@@ -45,21 +45,21 @@ describe('AlignmentBox', () => { ...@@ -45,21 +45,21 @@ describe('AlignmentBox', () => {
}) })
test('with default props has borders and has not active indicator', () => { test('with default props has borders and has not active indicator', () => {
expect(wrapper.is('.active')).toBe(false) const tree = renderer.create(<AlignmentBox {...requiredProps} />).toJSON()
expect(wrapper.is('.noBorderTop')).toBe(false) expect(tree).toHaveStyleRule('background-color', 'transparent')
expect(wrapper.is('.noBorderRight')).toBe(false) expect(tree).toHaveStyleRule('border-top-width', '1px')
expect(wrapper.is('.noBorderBottom')).toBe(false) expect(tree).toHaveStyleRule('border-right-width', '1px')
expect(wrapper.is('.noBorderLeft')).toBe(false) expect(tree).toHaveStyleRule('border-bottom-width', '1px')
expect(tree).toHaveStyleRule('border-left-width', '1px')
}) })
test('with given props has the correct classes', () => { test('with given props has the correct classes', () => {
const newWrapper = shallow(<AlignmentBox {...props} />) const tree = renderer.create(<AlignmentBox {...props} />).toJSON()
expect(tree).toHaveStyleRule('background-color', '#666')
expect(newWrapper.is('.active')).toBe(true) expect(tree).toHaveStyleRule('border-top-width', '0')
expect(newWrapper.is('.noBorderTop')).toBe(true) expect(tree).toHaveStyleRule('border-right-width', '0')
expect(newWrapper.is('.noBorderRight')).toBe(true) expect(tree).toHaveStyleRule('border-bottom-width', '0')
expect(newWrapper.is('.noBorderBottom')).toBe(true) expect(tree).toHaveStyleRule('border-left-width', '0')
expect(newWrapper.is('.noBorderLeft')).toBe(true)
}) })
test('on click the corresponding method is triggered', () => { test('on click the corresponding method is triggered', () => {
......
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`AlignmentBox is rendered correctly 1`] = ` exports[`AlignmentBox is rendered correctly 1`] = `
.c0 {
box-shadow: inset 0 0 0 2px rgba(255,255,255,1);
cursor: pointer;
height: 26px;
width: 17px;
border-style: solid;
border-color: #666;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
background-color: transparent;
}
.c0:hover {
background-color: #b3b3b3;
}
<div <div
className="root" className="c0"
id="left" id="left"
onClick={[Function]} onClick={[Function]}
role="presentation" role="presentation"
......
...@@ -10,7 +10,7 @@ exports[`AlignmentBoxWithLabel is rendered correctly 1`] = ` ...@@ -10,7 +10,7 @@ exports[`AlignmentBoxWithLabel is rendered correctly 1`] = `
Left Left
</span> </span>
<div <div
className="root" className="sc-bdVaJa iAeTlR"
id="left" id="left"
onClick={[Function]} onClick={[Function]}
role="presentation" role="presentation"
......
...@@ -13,7 +13,7 @@ exports[`AlignmentTool is rendered correctly 1`] = ` ...@@ -13,7 +13,7 @@ exports[`AlignmentTool is rendered correctly 1`] = `
Left Left
</span> </span>
<div <div
className="root noBorderRight" className="sc-bdVaJa ieYRgr"
id="left" id="left"
onClick={[Function]} onClick={[Function]}
role="presentation" role="presentation"
...@@ -31,7 +31,7 @@ exports[`AlignmentTool is rendered correctly 1`] = ` ...@@ -31,7 +31,7 @@ exports[`AlignmentTool is rendered correctly 1`] = `
right right
</span> </span>
<div <div
className="root noBorderLeft" className="sc-bdVaJa fCBdDA"
id="right" id="right"
onClick={[Function]} onClick={[Function]}
role="presentation" role="presentation"
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment