Skip to content

Commit

Permalink
Add test coverage for EuiAvatar. (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal authored Dec 5, 2017
1 parent d0e6cbd commit dc65097
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 1 deletion.
94 changes: 94 additions & 0 deletions src/components/avatar/__snapshots__/avatar.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiAvatar is rendered 1`] = `
<div
aria-label="aria-label"
class="euiAvatar euiAvatar--m testClass1 testClass2"
data-test-subj="test subject string"
style="background-image:none;background-color:#FEB6DB"
>
<span
aria-hidden="true"
>
n
</span>
</div>
`;

exports[`EuiAvatar props imageUrl is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar euiAvatar--m"
style="background-image:url(image url);background-color:#FEB6DB"
/>
`;

exports[`EuiAvatar props size l is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar euiAvatar--l"
style="background-image:none;background-color:#FEB6DB"
>
<span
aria-hidden="true"
>
n
</span>
</div>
`;

exports[`EuiAvatar props size m is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar euiAvatar--m"
style="background-image:none;background-color:#FEB6DB"
>
<span
aria-hidden="true"
>
n
</span>
</div>
`;

exports[`EuiAvatar props size none is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar"
style="background-image:none;background-color:#FEB6DB"
>
<span
aria-hidden="true"
>
n
</span>
</div>
`;

exports[`EuiAvatar props size s is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar euiAvatar--s"
style="background-image:none;background-color:#FEB6DB"
>
<span
aria-hidden="true"
>
n
</span>
</div>
`;

exports[`EuiAvatar props size xl is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar euiAvatar--xl"
style="background-image:none;background-color:#FEB6DB"
>
<span
aria-hidden="true"
>
n
</span>
</div>
`;
2 changes: 1 addition & 1 deletion src/components/avatar/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ export const EuiAvatar = ({
};

EuiAvatar.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
imageUrl: PropTypes.string,
name: PropTypes.string.isRequired,
size: PropTypes.oneOf(SIZES),
};

EuiAvatar.defaultProps = {
Expand Down
51 changes: 51 additions & 0 deletions src/components/avatar/avatar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../test/required_props';

import { EuiAvatar, SIZES } from './avatar';

describe('EuiAvatar', () => {
test('is rendered', () => {
const component = render(
<EuiAvatar
name="name"
{...requiredProps}
/>
);

expect(component)
.toMatchSnapshot();
});

describe('props', () => {
describe('imageUrl', () => {
it('is rendered', () => {
const component = render(
<EuiAvatar
name="name"
imageUrl="image url"
/>
);

expect(component)
.toMatchSnapshot();
});
});

describe('size', () => {
SIZES.forEach(size => {
it(`${size} is rendered`, () => {
const component = render(
<EuiAvatar
name="name"
size={size}
/>
);

expect(component)
.toMatchSnapshot();
});
});
});
});
});

0 comments on commit dc65097

Please sign in to comment.