taskOwnerBadge.test.tsx2.2 KBView on GitHub /**
* TaskOwnerBadge — the "whose task is this" pill on org-shared conversation tasks.
*
* Pins that it fails CLOSED: it labels a task only once the viewer is positively known and is
* someone other than the owner. `useSession()` resolves asynchronously, and treating an
* unresolved session as "not me" badged every task on a conversation — including the viewer's
* own, which is the whole thing the badge exists to distinguish.
*/
import React from 'react';
import { render, screen } from '@testing-library/react';
const mockSession: { data: { user: { id: string } } | null; isPending: boolean } = {
data: { user: { id: 'me' } },
isPending: false,
};
jest.mock('@/modules/auth/utils/auth-client', () => ({
useSession: () => mockSession,
}));
import { TaskOwnerBadge } from '@/modules/userTasks/components/TaskOwnerBadge';
const TEAMMATE = { id: 'teammate', name: 'Isabelle', email: null, image: null };
const ME = { id: 'me', name: 'Jesse', email: null, image: null };
describe('TaskOwnerBadge', () => {
beforeEach(() => {
mockSession.data = { user: { id: 'me' } };
mockSession.isPending = false;
});
it("badges a teammate's task with their name", () => {
render(<TaskOwnerBadge owner={TEAMMATE} />);
expect(screen.getByText('Isabelle')).toBeInTheDocument();
});
it('renders nothing for the viewer’s own task', () => {
const { container } = render(<TaskOwnerBadge owner={ME} />);
expect(container).toBeEmptyDOMElement();
});
it('renders nothing while the session is still resolving', () => {
mockSession.data = null;
mockSession.isPending = true;
const { container } = render(<TaskOwnerBadge owner={TEAMMATE} />);
expect(container).toBeEmptyDOMElement();
});
it('renders nothing when the session never resolves', () => {
mockSession.data = null;
mockSession.isPending = false;
const { container } = render(<TaskOwnerBadge owner={ME} />);
expect(container).toBeEmptyDOMElement();
});
it('renders nothing for an owner with no id to compare', () => {
const { container } = render(
<TaskOwnerBadge owner={{ id: '', name: null, email: null, image: null }} />,
);
expect(container).toBeEmptyDOMElement();
});
});