Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests #227

Merged
merged 29 commits into from
Aug 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
22080d4
update Flash tests
Aug 22, 2018
008cde4
remove flexAuto test
Aug 22, 2018
a69539f
remove todo from flash
Aug 22, 2018
59c082b
update margin and padding tests for FlexItem
Aug 22, 2018
753f35f
update FlexItem snap
Aug 22, 2018
781572b
update Heading tests & snaps
Aug 22, 2018
42687c8
Creating UtilitySystemProps test to test all components for space and…
jonrohan Aug 24, 2018
78ca5a4
remove old tests
Aug 24, 2018
fa86f94
fix heading test
Aug 24, 2018
f027def
set up required props in UtilitySystemProps
Aug 24, 2018
9335e55
fix missing prop error message for OcticonButton
Aug 24, 2018
f83b1a2
update octicon button snap
Aug 24, 2018
966a10e
fix BorderBox lint issues
Aug 24, 2018
327e67f
fix BranchName lint erros
Aug 24, 2018
3ef7fa5
re-enable BranchName system component test
Aug 24, 2018
5e65449
fix Button lint errors
Aug 24, 2018
7dbebd1
reenable CircleBadge system test
Aug 24, 2018
e3b43bf
fix CircleOcticon lint issues
Aug 24, 2018
7223911
re-enable system component test in CounterLabel
Aug 24, 2018
5fb9195
fix auto-fixable lint errors
Aug 24, 2018
08e2561
fix FlexItem lint errors
Aug 24, 2018
52baa4d
fix Heading lint errors
Aug 24, 2018
cf6cd94
fix Link lint errors
Aug 24, 2018
f748ed6
fix Text lint errors
Aug 24, 2018
95f3fd8
fix UtilitySystemProps lint errors
Aug 24, 2018
fa550eb
re-enable system component test for DonutChart
Aug 24, 2018
3ec7957
Merge branch 'release-2.0.1-beta' of github.com:primer/primer-react i…
Aug 24, 2018
b9f133f
one last linting error
Aug 24, 2018
ef208f4
undo lint fixes
Aug 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/__tests__/BorderBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,6 @@ describe('BorderBox', () => {
expect(render(<BorderBox />)).toEqual(render(<Box {...BorderBox.defaultProps} />))
})

it('renders margin', () => {
expect(render(<BorderBox m={1} />)).toHaveStyleRule('margin', px(theme.space[1]))
expect(renderStyles(<BorderBox m={[0, 1]} />)).toMatchKeys({
margin: px(theme.space[0]),
[`@media screen and (min-width:${px(theme.breakpoints[0])})`]: {
margin: px(theme.space[1])
}
})
})

it('renders padding', () => {
expect(render(<BorderBox p={1} />)).toHaveStyleRule('padding', px(theme.space[1]))
expect(renderStyles(<BorderBox p={[0, 1]} />)).toMatchKeys({
padding: px(theme.space[0]),
[`@media screen and (min-width:${px(theme.breakpoints[0])})`]: {
padding: px(theme.space[1])
}
})
})

it('renders borders', () => {
expect(render(<BorderBox borderColor="green.5" />)).toHaveStyleRule('border-color', colors.green[5])
expect(render(<BorderBox borderBottom={0} />)).toHaveStyleRule('border-bottom', '0')
Expand Down
8 changes: 0 additions & 8 deletions src/__tests__/Box.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ describe('Box', () => {
expect(render(<Box position="relative" />)).toMatchSnapshot()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we haven't touched this, but I would expect this snapshot to look like <div position="relative"> since we moved the position props in #202. This test should go away.

})

it('respects bg', () => {
expect(render(<Box bg="yellow.2" theme={theme} />)).toMatchSnapshot()
})

it('respects color', () => {
expect(render(<Box color="red.5" theme={theme} />)).toMatchSnapshot()
})

it('renders shadow', () => {
expect(render(<Box boxShadow="small" theme={theme} />)).toMatchSnapshot()
expect(render(<Box boxShadow="medium" theme={theme} />)).toMatchSnapshot()
Expand Down
7 changes: 0 additions & 7 deletions src/__tests__/BranchName.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ describe('BranchName', () => {
expect(render(<BranchName is="span" href="#" />).props.href).toEqual(null)
})

xit('respects margin utility prop', () => {
expect(rendersClass(<BranchName m={1} />, 'm-1')).toEqual(true)
})

xit('respects padding utility prop', () => {
expect(rendersClass(<BranchName p={1} />, 'p-1')).toEqual(true)
})
it('implements common system props', () => {
expect(BranchName).toImplementSystemProps(COMMON)
})
Expand Down
16 changes: 0 additions & 16 deletions src/__tests__/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ describe('ButtonPrimary', () => {
expect(render(<ButtonPrimary />).type).toEqual('button')
expect(render(<ButtonPrimary />).props.className).toContain('btn-primary')
})

it('implements common system props', () => {
expect(render(<ButtonPrimary m={2} theme={theme} />)).toHaveStyleRule('margin', '8px')
})
})

describe('ButtonDanger', () => {
Expand All @@ -87,10 +83,6 @@ describe('ButtonDanger', () => {
expect(render(<ButtonDanger />).props.className).toContain('btn-danger')
})

it('implements common system props', () => {
expect(render(<ButtonDanger m={2} theme={theme} />)).toHaveStyleRule('margin', '8px')
})

xit('renders children', () => {
expect(
render(
Expand All @@ -113,19 +105,11 @@ describe('ButtonLink', () => {
expect(render(<ButtonLink />).type).toEqual('button')
expect(render(<ButtonLink />).props.className).toContain('btn-link')
})

it('implements common system props', () => {
expect(render(<ButtonLink m={2} theme={theme} />)).toHaveStyleRule('margin', '8px')
})
})

describe('ButtonOutline', () => {
it('renders a <button> by default', () => {
expect(render(<ButtonOutline />).type).toEqual('button')
expect(render(<ButtonOutline />).props.className).toContain('btn-outline')
})

it('implements common system props', () => {
expect(render(<ButtonOutline m={2} theme={theme} />)).toHaveStyleRule('margin', '8px')
})
})
8 changes: 0 additions & 8 deletions src/__tests__/CircleOcticon.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,4 @@ describe('CircleOcticon', () => {
expect(result).toHaveStyleRule('width', '32px')
expect(result).toHaveStyleRule('height', '32px')
})

it('respects margin utility prop', () => {
expect(render(<CircleOcticon icon={Check} m={4} />)).toHaveStyleRule('margin', `${theme.space[4]}px`)
})

it('respects padding utility prop', () => {
expect(render(<CircleOcticon icon={Check} p={4} />)).toHaveStyleRule('padding', `${theme.space[4]}px`)
})
})
8 changes: 0 additions & 8 deletions src/__tests__/Details.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ describe('Details', () => {
expect(render(<Details />)).toHaveClass('details-reset')
})

it('respects margin utility prop', () => {
expect(render(<Details m={1} />)).toHaveStyleRule('margin', '4px')
})

it('respects padding utility prop', () => {
expect(render(<Details p={1} />)).toHaveStyleRule('padding', '4px')
})

it('Respects the open prop', () => {
expect(mount(<Details open />).props().open).toEqual(true)
})
Expand Down
8 changes: 0 additions & 8 deletions src/__tests__/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,4 @@ describe('Dropdown', () => {
expect(rendered.type).toEqual('div')
expect(rendered.props.className).toContain('BtnGroup')
})

it('respects margin utility prop', () => {
expect(render(<Dropdown m={1} />)).toHaveStyleRule('margin', '4px')
})

it('respects padding utility prop', () => {
expect(render(<Dropdown p={1} />)).toHaveStyleRule('padding', '4px')
})
})
15 changes: 1 addition & 14 deletions src/__tests__/Flash.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react'
import Flash from '../Flash'
import theme from '../theme'
import {COMMON} from '../system-props'
import {render, renderStyles} from '../utils/testing'
import {render} from '../utils/testing'

describe('Flash', () => {
it('is a system component', () => {
Expand All @@ -28,16 +27,4 @@ describe('Flash', () => {
expect(render(<Flash scheme="red" />)).toHaveClasses(['flash', 'flash-error'])
expect(render(<Flash scheme="green" />)).toHaveClasses(['flash', 'flash-success'])
})

it('respects margin utility prop', () => {
expect(renderStyles(<Flash m={4} />)).toMatchKeys({
'margin': `${theme.space[4]}px`
})
})

it('respects padding utility prop', () => {
expect(renderStyles(<Flash p={4} />)).toMatchKeys({
'padding': `${theme.space[4]}px`
})
})
})
12 changes: 0 additions & 12 deletions src/__tests__/FlexItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,4 @@ describe('FlexItem', () => {
expect(item.type).toEqual('button')
expect(item).toMatchSnapshot()
})

it('respects margin utility prop', () => {
expect(renderStyles(<FlexItem m={4} />)).toMatchKeys({
'margin': `${theme.space[4]}px`
})
})

it('respects padding utility prop', () => {
expect(renderStyles(<FlexItem p={4} />)).toMatchKeys({
'padding': `${theme.space[4]}px`
})
})
})
10 changes: 0 additions & 10 deletions src/__tests__/Heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ describe('Heading', () => {
it('respects the is prop', () => {
expect(render(<Heading is="h6" />).type).toEqual('h6')
})
it('renders margin & padding', () => {
expect(renderStyles(<Heading m={4} p={4} />)).toMatchKeys({
'margin': `${theme.space[4]}px`,
'padding': `${theme.space[4]}px`
})
})

it('respects color', () => {
expect(render(<Heading color="green.5" theme={theme} />)).toHaveStyleRule('color', theme.colors.green[5])
})

it('respects fontWeight', () => {
expect(render(<Heading fontWeight="bold" theme={theme} />)).toHaveStyleRule('font-weight', 'bold')
Expand Down
8 changes: 0 additions & 8 deletions src/__tests__/Label.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,4 @@ describe('Label', () => {
it('implements space system props', () => {
expect(Label).toImplementSystemProps(['space'])
})

it('respects margin utility prop', () => {
expect(render(<Label m={4} />)).toMatchSnapshot()
})

it('respects padding utility prop', () => {
expect(render(<Label p={4} />)).toMatchSnapshot()
})
})
6 changes: 0 additions & 6 deletions src/__tests__/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,4 @@ describe('Link', () => {
it('renders without any props', () => {
expect(render(<Link />)).toMatchSnapshot()
})

it('renders margin', () => {
expect(render(<Link m={1} theme={theme} />)).toMatchSnapshot()
expect(render(<Link m={[0, 1, 2, 3]} theme={theme} />)).toMatchSnapshot()
expect(render(<Link m={[1, 1, 1, 3]} theme={theme} />)).toMatchSnapshot()
})
})
17 changes: 0 additions & 17 deletions src/__tests__/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,6 @@ describe('Text', () => {
})
})

it('renders margin', () => {
expect(render(<Text m={1} />)).toHaveStyleRule('margin', px(theme.space[1]))
expect(render(<Text m={[0, 1, 2, 3, 4]} />)).toMatchSnapshot()
expect(render(<Text m={[1, 1, 3, 3]} />)).toMatchSnapshot()
})

it('renders padding', () => {
expect(render(<Text p={1} />)).toHaveStyleRule('padding', px(theme.space[1]))
expect(render(<Text p={[0, 1, 2, 3, 4]} />)).toMatchSnapshot()
expect(render(<Text p={[1, 1, 3, 3]} />)).toMatchSnapshot()
})

it('respects color', () => {
expect(render(<Text color="green.5" />)).toHaveStyleRule('color', colors.green[5])
expect(render(<Text color="#f0f" />)).toHaveStyleRule('color', '#f0f')
})

it('respects fontWeight', () => {
expect(render(<Text fontWeight="bold" />)).toHaveStyleRule('font-weight', 'bold')
expect(render(<Text fontWeight="normal" />)).toHaveStyleRule('font-weight', 'normal')
Expand Down
70 changes: 70 additions & 0 deletions src/__tests__/UtilitySystemProps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React from 'react'
import theme from '../theme'
import * as Components from '../index.js'
import {renderStyles} from '../utils/testing'

// TODO: These components need required props,
// Not sure how to set default props for required ones
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do two things here:

  1. Mock console.error() temporarily to silence the required prop errors.
  2. Set up an object that lists props for each component, e.g.
const testProps = {
  OcticonButton: {icon: X, label: ''},
  DonutChart: {data: {pending: 1}},
  MergeStatus: {state: 'ready'}
}

const blacklist = ['OcticonButton', 'DonutChart', 'MergeStatus']

describe('UtilitySystemProps', () => {
for (const Component of Object.values(Components)) {
// Skip any components that don't have displayName yet
if (!Component.displayName || !Component.systemProps || blacklist.includes(Component.displayName)) {
continue
}

if (Component.systemProps.includes('space')) {
it(`${Component.displayName} renders spacing props properly`, () => {
for (const i in theme.space) {
expect(
renderStyles(
<Component
m={i}
mt={i}
mr={i}
mb={i}
ml={i}
mx={i}
my={i}
p={i}
pt={i}
pr={i}
pb={i}
pl={i}
px={i}
py={i}
/>
)
).toMatchKeys({
margin: `${theme.space[i]}px`,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

margin is missing quotes here too

'margin-bottom': `${theme.space[i]}px`,
'margin-left': `${theme.space[i]}px`,
'margin-right': `${theme.space[i]}px`,
'margin-top': `${theme.space[i]}px`,
padding: `${theme.space[i]}px`,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

padding is missing quotes here

'padding-bottom': `${theme.space[i]}px`,
'padding-left': `${theme.space[i]}px`,
'padding-right': `${theme.space[i]}px`,
'padding-top': `${theme.space[i]}px`
})
}
})
}

if (Component.systemProps.includes('color')) {
it(`${Component.displayName} renders color props properly`, () => {
for (const color of Object.keys(theme.colors)) {
if (typeof theme.colors[color] === 'object' && color != 'state') {
for (const i in theme.colors[color]) {
expect(renderStyles(<Component bg={`${color}.${i}`} color={`${color}.${i}`} />)).toMatchKeys({
'background-color': theme.colors[color][i],
color: theme.colors[color][i]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

color is missing quotes here

})
}
}
}
})
}
}
})
3 changes: 3 additions & 0 deletions src/system-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ export function withSystemProps(Component, props = COMMON) {
Wrapped.displayName = Component.displayName
Object.assign(Wrapped.propTypes, Component.propTypes)

// Set what system props we use on this component
Wrapped.systemProps = props
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet


// Copy over non-system keys from components
// eg. Tooltip.js => Tooltip.directions Tooltip.alignments
for (const key of Object.keys(Component)) {
Expand Down