Skip to content

Commit

Permalink
Merge pull request Expensify#53618 from bernhardoj/fix/53257-ws-chat-…
Browse files Browse the repository at this point in the history
…shows-default-avatar-when-uploaded-while-offline

Fix WS chat shows default avatar when uploading the avatar while offline
  • Loading branch information
MarioExpensify authored Dec 10, 2024
2 parents 70b9238 + 1607e1d commit 3982ed0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2071,7 +2071,7 @@ function getWorkspaceIcon(report: OnyxInputOrEntry<Report>, policy?: OnyxInputOr
const isSameAvatarURL = iconFromCache?.icon?.source === policyExpenseChatAvatarSource;
const hasWorkSpaceNameChanged = iconFromCache?.name !== workspaceName;

if (iconFromCache && (isSameAvatarURL || report?.policyAvatar === undefined) && !hasWorkSpaceNameChanged) {
if (iconFromCache && (isSameAvatarURL || policyAvatarURL === undefined) && !hasWorkSpaceNameChanged) {
return iconFromCache.icon;
}

Expand Down
18 changes: 18 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ describe('ReportUtils', () => {
});
});

describe('getWorkspaceIcon', () => {
it('should not use cached icon when avatar is updated', () => {
// Given a new workspace and a workspace chat with undefined `policyAvatar`
const workspace = LHNTestUtils.getFakePolicy('1', 'ws');
const workspaceChat = LHNTestUtils.getFakeReport();
workspaceChat.policyID = workspace.id;

expect(ReportUtils.getWorkspaceIcon(workspaceChat, workspace).source).toBe(ReportUtils.getDefaultWorkspaceAvatar(workspace.name));

// When the user uploads a new avatar
const newAvatarURL = 'https://example.com';
workspace.avatarURL = newAvatarURL;

// Then it should return the new avatar
expect(ReportUtils.getWorkspaceIcon(workspaceChat, workspace).source).toBe(newAvatarURL);
});
});

describe('getDisplayNamesWithTooltips', () => {
test('withSingleParticipantReport', () => {
const participants = ReportUtils.getDisplayNamesWithTooltips(participantsPersonalDetails, false);
Expand Down

0 comments on commit 3982ed0

Please sign in to comment.