Skip to content

Commit 38a68e5

Browse files
edschemacodex
authored andcommitted
fix: show hydrated profile avatars in Studio header
Co-authored-by: Codex <codex@openai.com>
1 parent a1df9a9 commit 38a68e5

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

src/studio-header/StudioHeader.test.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,53 @@ describe('Header', () => {
122122
expect(avatarIcon).toBeVisible();
123123
});
124124

125+
it('user menu should use avatar icon when hydrated profile image has no image', async () => {
126+
currentUser = {
127+
...authenticatedUser,
128+
avatar: null,
129+
profileImage: {
130+
hasImage: false,
131+
imageUrlMedium: '/profile-images/abc123-medium.png',
132+
},
133+
};
134+
const { getByTestId, queryByTestId } = render(<RootWrapper {...props} />);
135+
const avatarIcon = getByTestId('avatar-icon');
136+
137+
expect(avatarIcon).toBeVisible();
138+
expect(queryByTestId('avatar-image')).not.toBeInTheDocument();
139+
});
140+
141+
it('user menu should use hydrated profile image when avatar is not present', async () => {
142+
currentUser = {
143+
...authenticatedUser,
144+
avatar: null,
145+
profileImage: {
146+
hasImage: true,
147+
imageUrlMedium: '/profile-images/abc123-medium.png',
148+
},
149+
};
150+
const { getByTestId } = render(<RootWrapper {...props} />);
151+
const avatarImage = getByTestId('avatar-image');
152+
153+
expect(avatarImage).toBeVisible();
154+
expect(avatarImage).toHaveAttribute('src', '/profile-images/abc123-medium.png');
155+
});
156+
157+
it('user menu should prefer avatar over hydrated profile image', async () => {
158+
currentUser = {
159+
...authenticatedUser,
160+
profileImage: {
161+
hasImage: true,
162+
imageUrlMedium: '/profile-images/abc123-medium.png',
163+
},
164+
};
165+
const { getByTestId } = render(<RootWrapper {...props} />);
166+
const avatarImage = getByTestId('avatar-image');
167+
168+
expect(avatarImage).toBeVisible();
169+
expect(avatarImage).toHaveAttribute('src', authenticatedUser.avatar);
170+
});
171+
125172
it('should hide nav items if prop isHiddenMainMenu true', async () => {
126173
const initialProps = { ...props, isHiddenMainMenu: true };
127174
const { queryByTestId } = render(<RootWrapper {...initialProps} />);

src/studio-header/StudioHeader.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ const StudioHeader: FunctionComponent<Props> = ({
4040
}) => {
4141
// @ts-expect-error - frontend-platform doesn't yet have type information :/
4242
const { authenticatedUser, config } = useContext(AppContext);
43+
const profileImage = authenticatedUser?.profileImage;
44+
const authenticatedUserAvatar = authenticatedUser?.avatar
45+
|| (profileImage?.hasImage ? profileImage.imageUrlMedium : null);
4346
const props = {
4447
logo: config.LOGO_URL,
4548
logoAltText: `Studio ${config.SITE_NAME}`,
@@ -49,7 +52,7 @@ const StudioHeader: FunctionComponent<Props> = ({
4952
containerProps,
5053
username: authenticatedUser?.username,
5154
isAdmin: authenticatedUser?.administrator,
52-
authenticatedUserAvatar: authenticatedUser?.avatar,
55+
authenticatedUserAvatar,
5356
studioBaseUrl: isNewHomePage ? '/home' : config.STUDIO_BASE_URL,
5457
logoutUrl: config.LOGOUT_URL,
5558
isHiddenMainMenu,

0 commit comments

Comments
 (0)