-
Notifications
You must be signed in to change notification settings - Fork 536
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
Update tests #227
Changes from 1 commit
22080d4
008cde4
a69539f
59c082b
753f35f
781572b
42687c8
78ca5a4
fa86f94
f027def
9335e55
f83b1a2
966a10e
327e67f
3ef7fa5
5e65449
7dbebd1
e3b43bf
7223911
5fb9195
08e2561
52baa4d
cf6cd94
f748ed6
95f3fd8
fa550eb
3ec7957
b9f133f
ef208f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could do two things here:
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`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
'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`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
'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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) { | ||
|
There was a problem hiding this comment.
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.