-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: RecipientsAvatars doesn't show owner avatar if it's 'me'
- Loading branch information
Showing
2 changed files
with
168 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
packages/cozy-sharing/src/components/RecipientsAvatars.spec.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import React from 'react' | ||
import { createMockClient } from 'cozy-client' | ||
import { render } from '@testing-library/react' | ||
|
||
import { RecipientsAvatars, MAX_DISPLAYED_RECIPIENTS } from './Recipient' | ||
import AppLike from '../../test/AppLike' | ||
|
||
const mockRecipients = new Array(MAX_DISPLAYED_RECIPIENTS - 1) | ||
.fill( | ||
{ | ||
status: 'owner', | ||
public_name: 'cozy' | ||
}, | ||
0, | ||
1 | ||
) | ||
.fill( | ||
{ | ||
status: 'pending', | ||
name: 'Mitch Young' | ||
}, | ||
1 | ||
) | ||
|
||
const mockMoreRecipientsThanMaxDisplayed = [ | ||
...mockRecipients, | ||
{ | ||
status: 'mail-not-send', | ||
name: 'Lyn Webster' | ||
}, | ||
{ | ||
status: 'ready', | ||
name: 'Richelle Young' | ||
}, | ||
{ | ||
status: 'ready', | ||
name: 'John Connor' | ||
} | ||
] | ||
|
||
describe('RecipientsAvatars', () => { | ||
const client = createMockClient({}) | ||
|
||
const setup = ({ | ||
recipients = mockRecipients, | ||
link = false, | ||
isOwner = true, | ||
onClick = () => jest.fn(), | ||
...rest | ||
}) => { | ||
return render( | ||
<AppLike client={client}> | ||
<RecipientsAvatars | ||
recipients={recipients} | ||
onClick={onClick} | ||
isOwner={isOwner} | ||
link={link} | ||
{...rest} | ||
/> | ||
</AppLike> | ||
) | ||
} | ||
|
||
it('should render link icon if a link is generated', () => { | ||
const { getByTestId } = setup({ | ||
link: true | ||
}) | ||
|
||
expect(getByTestId('recipientsAvatars-link')).toBeTruthy() | ||
}) | ||
|
||
it('should not render link icon if a link is not generated', () => { | ||
const { queryByTestId } = setup({}) | ||
|
||
expect(queryByTestId('recipientsAvatars-link')).toBeNull() | ||
}) | ||
|
||
it('should hide me as owner by default', () => { | ||
const { queryByTestId } = setup({}) | ||
|
||
expect(queryByTestId('recipientsAvatars-avatar-owner')).toBeNull() | ||
}) | ||
|
||
it('should show me as owner if required', () => { | ||
const { getByTestId } = setup({ | ||
showMeAsOwner: true | ||
}) | ||
|
||
expect(getByTestId('recipientsAvatars-avatar-owner')).toBeTruthy() | ||
}) | ||
|
||
it('should show a +X icon with the correct number if there is more avatars than expected', () => { | ||
const { getByTestId, getByText } = setup({ | ||
recipients: mockMoreRecipientsThanMaxDisplayed, | ||
showMeAsOwner: true | ||
}) | ||
|
||
const delta = | ||
mockMoreRecipientsThanMaxDisplayed.length - MAX_DISPLAYED_RECIPIENTS | ||
|
||
expect(getByTestId('recipientsAvatars-plusX')).toBeTruthy() | ||
expect(getByText(`+${delta}`)).toBeTruthy() | ||
}) | ||
|
||
it('should show both +X and link icon if necessary', () => { | ||
const { getByTestId } = setup({ | ||
recipients: mockMoreRecipientsThanMaxDisplayed, | ||
showMeAsOwner: true, | ||
link: true | ||
}) | ||
|
||
expect(getByTestId('recipientsAvatars-plusX')).toBeTruthy() | ||
expect(getByTestId('recipientsAvatars-link')).toBeTruthy() | ||
}) | ||
}) |