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

Fix dimmed ObjectName #35

Merged
merged 2 commits into from Jul 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/object/ObjectName.js
Expand Up @@ -13,8 +13,14 @@ import createStyles from '../styles/createStyles';
*/
const ObjectName = ({ name, dimmed, styles }, { theme }) => {
const themeStyles = createStyles('ObjectName', theme);
const appliedStyles = {
...themeStyles.base,
...(dimmed ? themeStyles['dimmed'] : {}),
...styles,
};

return (
<span style={{ ...themeStyles.base, ...(dimmed && styles.dimmed), ...styles }}>{name}</span>
<span style={appliedStyles}>{name}</span>
);
};

Expand Down
25 changes: 25 additions & 0 deletions src/object/ObjectName.spec.js
Expand Up @@ -4,6 +4,10 @@ import TestUtils from 'react-addons-test-utils';
import expect from 'expect';
import ObjectName from './ObjectName';

import chromeLight from '../styles/themes/chromeLight';
import makeTheme from '../styles/base';
const defaultTheme = makeTheme(chromeLight);

const renderer = TestUtils.createRenderer();

const defaultProps = {};
Expand All @@ -18,6 +22,27 @@ describe('ObjectName', () => {
expect(tree.type).toEqual('span');
});

it('should apply default theme', () => {
renderer.render(<ObjectName name="testvalue" />);
const tree = renderer.getRenderOutput();

expect(tree.props.style).toInclude(defaultTheme.ObjectName.base);
});

it('should apply dimming if `dimmed` prop is true', () => {
renderer.render(<ObjectName name="testvalue" dimmed={true}/>);
const tree = renderer.getRenderOutput();

expect(tree.props.style).toInclude(defaultTheme.ObjectName.dimmed);
});

it('should not apply dimming if `dimmed` prop is false', () => {
renderer.render(<ObjectName name="testvalue" dimmed={false}/>);
const tree = renderer.getRenderOutput();

expect(tree.props.style).toExclude(defaultTheme.ObjectName.dimmed);
});

it('Accepts and applies additional `style` prop', () => {
// Test that a custom `style` props is passed and applied to <span/>
const style = { color: 'blue' };
Expand Down