slackChannelHint.test.ts2.4 KBView on GitHub
/**
 * Opening a Slack channel that is not in the feed.
 *
 * The unified feed is only loaded on the inbox route. Everywhere else — a Slack task on the
 * kanban board, a pasted `?slack=` link — the store's feed is empty, so the lookup that
 * finds a channel's row returns nothing and the column renders blank. Not an error, not a
 * spinner: the click appears to do nothing, which is exactly how this shipped broken.
 *
 * The opener already knows the channel, so it leaves a hint behind. These pin that the hint
 * carries what the channel view cannot work without, and that a real feed row still wins.
 */
import { renderHook, act } from '@testing-library/react';
import { useCedarStore } from '@/modules/store';
import { findSlackItem } from '@/modules/inbox/hooks/use-open-channel-item';
import { selectLoadedInboxItems } from '@/modules/inbox/store/inboxSlice';

describe('slackChannelHint', () => {
  beforeEach(() => {
    act(() => {
      useCedarStore.getState().setSlackChannelHint(null);
      useCedarStore.getState().setChannelFeeds({});
    });
  });

  it('records the workspace, without which the channel cannot be read', () => {
    // `inbox.slackChannelMessages` is keyed by workspace AND channel — a hint carrying only the
    // channel id renders a header over an empty thread.
    const { result } = renderHook(() => useCedarStore((s) => s.slackChannelHint));

    act(() => {
      useCedarStore.getState().setSlackChannelHint({
        channelId: 'C0BNUT9RD8X',
        workspaceId: 'T08AHSLJBTL',
        channelName: 'cedar-payrollintegrations',
        conversationId: 'conv-1',
      });
    });

    expect(result.current).toMatchObject({
      channelId: 'C0BNUT9RD8X',
      workspaceId: 'T08AHSLJBTL',
    });
  });

  it('starts empty, so nothing is rendered off a stale hint', () => {
    expect(useCedarStore.getState().slackChannelHint).toBeNull();
  });

  it('is only a fallback — the feed row is what findSlackItem returns when there is one', () => {
    act(() => {
      useCedarStore.getState().setSlackChannelHint({
        channelId: 'C0BNUT9RD8X',
        workspaceId: 'T08AHSLJBTL',
        channelName: 'hinted',
        conversationId: null,
      });
    });

    // With no feed loaded there is nothing to find — the hint is the only thing standing.
    expect(
      findSlackItem(selectLoadedInboxItems(useCedarStore.getState()), 'C0BNUT9RD8X'),
    ).toBeUndefined();
  });
});