Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/components/Avatar/WorkspaceAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@ type WorkspaceAvatarProps = AvatarCommonProps & {
name: string;

/** Workspace/policy ID. Picks the background color of the default workspace avatar. */
avatarID: number | string;
avatarID?: number | string;
};

/** Renders a workspace avatar, falling back to a default icon derived from the workspace name. */
function WorkspaceAvatar({source, imageStyles, iconAdditionalStyles, containerStyles, size = CONST.AVATAR_SIZE.DEFAULT, name, avatarID, testID}: WorkspaceAvatarProps) {
function WorkspaceAvatar({
source,
imageStyles,
iconAdditionalStyles,
containerStyles,
size = CONST.AVATAR_SIZE.DEFAULT,
name,
avatarID = CONST.DEFAULT_NUMBER_ID,
testID,
}: WorkspaceAvatarProps) {
const theme = useTheme();
const StyleUtils = useStyleUtils();
const defaultAvatars = useDefaultAvatars();
Expand Down
8 changes: 8 additions & 0 deletions src/selectors/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ const createWorkspaceListPoliciesSelector =

const isArchived = isArchivedPolicy(policy);
const isJoinRequestPending = !!policy.isJoinRequestPending && !!policy.policyDetailsForNonMembers;

// A `policy_` record is merged field-by-field, so a freshly joined workspace can show up here before its
// `id` has landed. Such a row has no key, no avatar seed and nothing to navigate to, so skip it until the
// next update fills it in. Join requests are exempt because they carry their ID in `nonMemberDetails`.
if (!policy.id && !isJoinRequestPending) {
continue;
}

let nonMemberDetails: WorkspaceListPolicy['nonMemberDetails'];
if (isJoinRequestPending) {
const nonMemberEntry = Object.entries(policy.policyDetailsForNonMembers ?? {}).at(0);
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/AvatarTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,26 @@ describe('Avatar', () => {
expect(getHiddenTestId(workspaceFallbackTestID)).toBeTruthy();
});

it('WorkspaceAvatar still renders the default workspace icon when avatarID is missing', async () => {
const workspaceFallbackTestID = getDefaultWorkspaceAvatarTestID(WORKSPACE_NAME);

// A `policy_` Onyx record is merged field-by-field, so `policy.id` can still be undefined on the
// fallback-icon branch. That used to throw out of render and white-screen the whole app.
render(
<ComposeProviders components={[ThemeProviderWithLight, ThemeStylesProvider, OnyxListItemProvider, LocaleContextProvider]}>
<WorkspaceAvatar
name={WORKSPACE_NAME}
avatarID={undefined}
/>
</ComposeProviders>,
);

await waitForBatchedUpdates();

expect(screen.queryByTestId(AVATAR_IMAGE_TEST_ID)).toBeNull();
expect(getHiddenTestId(workspaceFallbackTestID)).toBeTruthy();
});

it('assigns different workspace avatar colors for distinct hex policy IDs', () => {
const naNColor = getDefaultWorkspaceAvatarColor('NaN');
const hexPolicyColor = getDefaultWorkspaceAvatarColor(HEX_POLICY_ID_STARTING_WITH_LETTER);
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/PolicySelectorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,36 @@ describe('createWorkspaceListPoliciesSelector', () => {
expect(result).toHaveLength(1);
});

it('excludes a policy whose id has not been merged in yet', () => {
// A `policy_` record is merged field-by-field, so a freshly joined workspace can pass shouldShowPolicy
// before its `id` arrives. Such a row has no key, no avatar seed and nothing to navigate to.
const policies = {
[`${P}p1`]: makePolicy({id: undefined}),
};
expect(createWorkspaceListPoliciesSelector(userLogin)(policies)).toEqual([]);
});

it('still includes an id-less policy when it is a pending join request', () => {
const policies = {
[`${P}p1`]: makePolicy({
id: undefined,
isJoinRequestPending: true,
policyDetailsForNonMembers: {
p1: {
name: 'Pending Workspace',
type: CONST.POLICY.TYPE.TEAM,
ownerAccountID: 1,
ownerEmail: 'owner@example.com',
},
},
}),
};
const [item] = createWorkspaceListPoliciesSelector(userLogin)(policies);
expect(item?.isJoinRequestPending).toBe(true);
expect(item?.id).toBeUndefined();
expect(item?.nonMemberDetails?.policyID).toBe('p1');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot Please add expect(item?.id).toBeUndefined(); as well

@MelvinBot MelvinBot Sep 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added and pushed as 6906cc6.

tests/unit/PolicySelectorTest.ts:295-298 now reads:

        const [item] = createWorkspaceListPoliciesSelector(userLogin)(policies);
        expect(item?.isJoinRequestPending).toBe(true);
        expect(item?.id).toBeUndefined();
        expect(item?.nonMemberDetails?.policyID).toBe('p1');

Good call — it pins the part of the shape the test was implicitly relying on. The point of the join-request exemption is that the row survives without an id, and until now nothing asserted that the projected id really is undefined.

Checks run locally:

Check Result
Jest — PolicySelectorTest ✅ 64 passed
oxfmt ✅ clean (formatter left the file untouched)
npm run spell-changed ✅ 4 files, 0 issues
npm run typecheck ✅ tsconfig.json, tsconfig.jest.json, tsconfig.node.json, victory-chart-renderer

Two caveats, both environmental rather than anything to do with this change:

  • ESLint could not run here. eslint-seatbelt isn't installed in this sandbox, so npm run lint-changed fails to resolve eslint-seatbelt/api before it lints anything. CI will still run it.
  • typecheck failed on tsconfig.bun.json for the same reason — scripts/lint.ts can't resolve eslint-seatbelt/api. That failure is in scripts/lint.ts, not in any file this PR touches, and it reproduces on the branch without my change.

I ran oxfmt across all 8973 files and it modified nothing except my edit, so the earlier Oxfmt failure shouldn't recur.


view run · view recording

});

it('projects only the expected fields onto each result item', () => {
const policy = makePolicy({
id: 'p1',
Expand Down
Loading