Skip to content

Commit

Permalink
refactor: Rename RecipientsAvatars into AvatarList
Browse files Browse the repository at this point in the history
BREAKING CHANGE : If you were importing RecipientsAvatars directly you should now use `import { AvatarList as RecipientsAvatars } from 'cozy-sharing/dist/components/Avatar/AvatarList'`
  • Loading branch information
cballevre committed Mar 11, 2024
1 parent 91d366c commit abef583
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions packages/cozy-sharing/src/SharedRecipients.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react'

import RecipientsAvatars from './components/Recipient/RecipientsAvatars'
import { AvatarList } from './components/Avatar/AvatarList'
import SharingContext from './context'
import withLocales from './hoc/withLocales'

export const SharedRecipients = withLocales(({ docId, onClick, ...rest }) => (
<SharingContext.Consumer>
{({ byDocId, getRecipients, getSharingLink, isOwner } = {}) =>
!byDocId || !byDocId[docId] ? null : (
<RecipientsAvatars
<AvatarList
recipients={getRecipients(docId)}
link={getSharingLink(docId) !== null}
onClick={onClick}
Expand Down
4 changes: 2 additions & 2 deletions packages/cozy-sharing/src/SharedStatus.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import RecipientsAvatars from './components/Recipient/RecipientsAvatars'
import { AvatarList } from './components/Avatar/AvatarList'
import SharingContext from './context'
import withLocales from './hoc/withLocales'

Expand All @@ -11,7 +11,7 @@ export const SharedStatus = withLocales(
!byDocId || !byDocId[docId] ? (
<span className={className + ' ' + noSharedClassName}></span>
) : (
<RecipientsAvatars
<AvatarList
className={className}
recipients={getRecipients(docId)}
link={getSharingLink(docId) !== null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const excludeMeAsOwnerFromRecipients = ({
})
}

const RecipientsAvatars = ({
const AvatarList = ({
recipients,
link,
size,
Expand Down Expand Up @@ -71,7 +71,7 @@ const RecipientsAvatars = ({
onClick={onClick}
>
{link && (
<span data-testid="recipientsAvatars-link">
<span data-testid="AvatarList-link">
<Avatar
className={styles['recipients-avatars--link']}
icon={LinkIcon}
Expand All @@ -80,7 +80,7 @@ const RecipientsAvatars = ({
</span>
)}
{hasExtraRecipients && (
<span data-testid="recipientsAvatars-plusX">
<span data-testid="AvatarList-plusX">
<ExtraAvatar
className={styles['recipients-avatars--plusX']}
extraRecipients={extraRecipients}
Expand All @@ -90,7 +90,7 @@ const RecipientsAvatars = ({
)}
{shownRecipients.map((recipient, idx) => (
<span
data-testid={`recipientsAvatars-avatar${
data-testid={`AvatarList-avatar${
recipient.status === 'owner' ? '-owner' : ''
}`}
key={idx}
Expand All @@ -106,4 +106,4 @@ const RecipientsAvatars = ({
)
}

export default RecipientsAvatars
export { AvatarList }
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import React from 'react'

import { createMockClient } from 'cozy-client'

import RecipientsAvatars, {
import {
AvatarList,
MAX_DISPLAYED_RECIPIENTS,
excludeMeAsOwnerFromRecipients
} from './RecipientsAvatars'
} from './AvatarList'
import AppLike from '../../../test/AppLike'

const mockRecipients = new Array(MAX_DISPLAYED_RECIPIENTS - 1)
Expand Down Expand Up @@ -42,7 +43,7 @@ const mockMoreRecipientsThanMaxDisplayed = [
}
]

describe('RecipientsAvatars', () => {
describe('AvatarList', () => {
const client = createMockClient({})

const setup = ({
Expand All @@ -54,7 +55,7 @@ describe('RecipientsAvatars', () => {
}) => {
return render(
<AppLike client={client}>
<RecipientsAvatars
<AvatarList
recipients={recipients}
onClick={onClick}
isOwner={isOwner}
Expand All @@ -70,27 +71,27 @@ describe('RecipientsAvatars', () => {
link: true
})

expect(getByTestId('recipientsAvatars-link')).toBeTruthy()
expect(getByTestId('AvatarList-link')).toBeTruthy()
})

it('should not render link icon if a link is not generated', () => {
const { queryByTestId } = setup({})

expect(queryByTestId('recipientsAvatars-link')).toBeNull()
expect(queryByTestId('AvatarList-link')).toBeNull()
})

it('should hide me as owner by default', () => {
const { queryByTestId } = setup({})

expect(queryByTestId('recipientsAvatars-avatar-owner')).toBeNull()
expect(queryByTestId('AvatarList-avatar-owner')).toBeNull()
})

it('should show me as owner if required', () => {
const { getByTestId } = setup({
showMeAsOwner: true
})

expect(getByTestId('recipientsAvatars-avatar-owner')).toBeTruthy()
expect(getByTestId('AvatarList-avatar-owner')).toBeTruthy()
})

it('should show a +X icon with the correct number if there is more avatars than expected', () => {
Expand All @@ -102,7 +103,7 @@ describe('RecipientsAvatars', () => {
const delta =
mockMoreRecipientsThanMaxDisplayed.length - MAX_DISPLAYED_RECIPIENTS

expect(getByTestId('recipientsAvatars-plusX')).toBeTruthy()
expect(getByTestId('AvatarList-plusX')).toBeTruthy()
expect(getByText(`+${delta}`)).toBeTruthy()
})

Expand All @@ -113,8 +114,8 @@ describe('RecipientsAvatars', () => {
link: true
})

expect(getByTestId('recipientsAvatars-plusX')).toBeTruthy()
expect(getByTestId('recipientsAvatars-link')).toBeTruthy()
expect(getByTestId('AvatarList-plusX')).toBeTruthy()
expect(getByTestId('AvatarList-link')).toBeTruthy()
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import RecipientsAvatars from './RecipientsAvatars'
import { AvatarList } from './AvatarList'

const meta = {
component: RecipientsAvatars,
component: AvatarList,
args: {}
}

Expand Down

0 comments on commit abef583

Please sign in to comment.