Skip to content

Commit

Permalink
test(bountyCard): add status calculation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammadUmer44 committed Dec 29, 2024
1 parent 775f760 commit 4e80319
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/people/WorkSpacePlanner/BountyCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const BountyCardComponent: React.FC<BountyCardProps> = ({
{truncate(workspace?.name ?? 'No Workspace', 20)}
</span>
<StatusText className="last-span" status={status}>
{status || 'Todo'}
{status}
</StatusText>
</RowB>
</CardContainer>
Expand Down
126 changes: 126 additions & 0 deletions src/store/__test__/bountyCard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,130 @@ describe('BountyCardStore', () => {
await waitFor(() => store.loadNextPage());
});
});

describe('calculateBountyStatus', () => {
let store: BountyCardStore;

beforeEach(async () => {
store = await waitFor(() => new BountyCardStore(mockWorkspaceId));
});

it('should return "Paid" when bounty is paid', async () => {
const mockBounty = {
id: '1',
title: 'Test Bounty',
paid: true,
completed: true,
payment_pending: false,
assignee_img: 'test.jpg'
};

fetchStub.resolves({
ok: true,
json: async () => [mockBounty]
} as Response);

await store.loadWorkspaceBounties();
expect(store.bountyCards[0].status).toBe('Paid');
});

it('should return "Complete" when bounty is completed but not paid', async () => {
const mockBounty = {
id: '1',
title: 'Test Bounty',
paid: false,
completed: true,
payment_pending: false,
assignee_img: 'test.jpg'
};

fetchStub.resolves({
ok: true,
json: async () => [mockBounty]
} as Response);

await store.loadWorkspaceBounties();
expect(store.bountyCards[0].status).toBe('Complete');
});

it('should return "Complete" when payment is pending', async () => {
const mockBounty = {
id: '1',
title: 'Test Bounty',
paid: false,
completed: false,
payment_pending: true,
assignee_img: 'test.jpg'
};

fetchStub.resolves({
ok: true,
json: async () => [mockBounty]
} as Response);

await store.loadWorkspaceBounties();
expect(store.bountyCards[0].status).toBe('Complete');
});

it('should return "Assigned" when bounty has assignee but not completed or paid', async () => {
const mockBounty = {
id: '1',
title: 'Test Bounty',
paid: false,
completed: false,
payment_pending: false,
assignee_img: 'test.jpg'
};

fetchStub.resolves({
ok: true,
json: async () => [mockBounty]
} as Response);

await store.loadWorkspaceBounties();
expect(store.bountyCards[0].status).toBe('Assigned');
});

it('should return "Todo" when bounty has no assignee and is not completed or paid', async () => {
const mockBounty = {
id: '1',
title: 'Test Bounty',
paid: false,
completed: false,
payment_pending: false,
assignee_img: undefined
};

fetchStub.resolves({
ok: true,
json: async () => [mockBounty]
} as Response);

await store.loadWorkspaceBounties();
expect(store.bountyCards[0].status).toBe('Todo');
});

describe('computed status lists', () => {
it('should correctly filter bounties by status', async () => {
const mockBounties = [
{ id: '1', title: 'Bounty 1', paid: true, completed: true, assignee_img: 'test.jpg' },
{ id: '2', title: 'Bounty 2', completed: true, assignee_img: 'test.jpg' },
{ id: '3', title: 'Bounty 3', assignee_img: 'test.jpg' },
{ id: '4', title: 'Bounty 4' }
];

fetchStub.resolves({
ok: true,
json: async () => mockBounties
} as Response);

await store.loadWorkspaceBounties();

expect(store.paidItems.length).toBe(1);
expect(store.completedItems.length).toBe(1);
expect(store.assignedItems.length).toBe(1);
expect(store.todoItems.length).toBe(1);
});
});
});
});

0 comments on commit 4e80319

Please sign in to comment.