Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Mar 15, 2020
1 parent 0546c18 commit d008c8e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/material-ui-lab/src/AvatarGroup/AvatarGroup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ export interface AvatarGroupProps
* The avatars to stack.
*/
children: React.ReactNode;
/**
* Spacing between avatars.
*/
spacing?: 'small' | 'medium' | number;
/**
* Max avatars to show before +x.
*/
max?: number;
/**
* Spacing between avatars.
*/
spacing?: 'small' | 'medium' | number;
}

export type AvatarGroupClassKey = 'root' | 'avatar';
Expand Down
18 changes: 14 additions & 4 deletions packages/material-ui-lab/src/AvatarGroup/AvatarGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ export const styles = theme => ({
});

const AvatarGroup = React.forwardRef(function AvatarGroup(props, ref) {
const { children: childrenProp, classes, className, spacing = 'medium', max = 5, ...other } = props;
const {
children: childrenProp,
classes,
className,
spacing = 'medium',
max = 5,
...other
} = props;

const children = React.Children.toArray(childrenProp).filter(child => {
if (process.env.NODE_ENV !== 'production') {
Expand Down Expand Up @@ -54,14 +61,17 @@ const AvatarGroup = React.forwardRef(function AvatarGroup(props, ref) {
},
});
})}
{extraAvatars ?
{extraAvatars ? (
<Avatar
className={classes.avatar}
style={{
zIndex: 0,
marginLeft: spacing && SPACINGS[spacing] !== undefined ? SPACINGS[spacing] : -spacing,
}}>+{extraAvatars}</Avatar>
: null}
}}
>
+{extraAvatars}
</Avatar>
) : null}
</div>
);
});
Expand Down
16 changes: 16 additions & 0 deletions packages/material-ui-lab/src/AvatarGroup/AvatarGroup.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import * as React from 'react';
import { expect } from 'chai';
import { createMount, getClasses } from '@material-ui/core/test-utils';
import describeConformance from '@material-ui/core/test-utils/describeConformance';
import { createClientRender } from 'test/utils/createClientRender';
import AvatarGroup from './AvatarGroup';
import { Avatar } from '@material-ui/core';

describe('<AvatarGroup />', () => {
let mount;
let classes;
const render = createClientRender();

before(() => {
mount = createMount({ strict: true });
Expand All @@ -23,4 +27,16 @@ describe('<AvatarGroup />', () => {
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
}));

it('should not display all the avatars', () => {
const { container } = render(
<AvatarGroup max={1}>
<Avatar src="broken-url" />
<Avatar src="broken-url" />
<Avatar src="broken-url" />
</AvatarGroup>,
);
expect(container.querySelectorAll('img').length).to.equal(1);
expect(container.textContent).to.equal('+2');
});
});

0 comments on commit d008c8e

Please sign in to comment.