From bf8562d298e7de0476f1ce00ff41112a96d5800c Mon Sep 17 00:00:00 2001
From: Fog3211 <23151576+Fog3211@users.noreply.github.com>
Date: Fri, 23 Feb 2024 01:26:09 +0800
Subject: [PATCH] test: add test case for TicketModalPage Edit Actions
fix: type error
---
.../__tests__/TicketModalPage.spec.tsx | 244 +++++++++++++++++-
1 file changed, 240 insertions(+), 4 deletions(-)
diff --git a/src/pages/tickets/__tests__/TicketModalPage.spec.tsx b/src/pages/tickets/__tests__/TicketModalPage.spec.tsx
index 7a9bd660..e0d87a29 100644
--- a/src/pages/tickets/__tests__/TicketModalPage.spec.tsx
+++ b/src/pages/tickets/__tests__/TicketModalPage.spec.tsx
@@ -1,5 +1,15 @@
import '@testing-library/jest-dom';
-import { act, render, waitFor, fireEvent, screen, within } from '@testing-library/react';
+import {
+ act,
+ render,
+ waitFor,
+ fireEvent,
+ screen,
+ within,
+ getByTestId,
+ getAllByText,
+ queryByText
+} from '@testing-library/react';
import { user } from '__test__/__mockData__/user';
import { mockBountiesMutated, newBounty } from 'bounties/__mock__/mockBounties.data';
import { DollarConverter, formatSat, getSessionValue, satToUsd } from 'helpers';
@@ -8,9 +18,10 @@ import { MemoryRouter, Route } from 'react-router-dom';
import { mainStore } from 'store/main';
import { useIsMobile } from 'hooks';
import { uiStore } from 'store/ui';
+import { unpaidString } from 'people/widgetViews/summaries/constants';
+import userEvent from '@testing-library/user-event';
import { TicketModalPage } from '../TicketModalPage';
import { withCreateModal } from '../../../components/common/withCreateModal';
-import { unpaidString } from 'people/widgetViews/summaries/constants';
jest.mock('hooks', () => ({
useIsMobile: jest.fn()
@@ -130,7 +141,7 @@ describe('TicketModalPage Component', () => {
}
+ render={(props: any) => }
/>
);
@@ -487,7 +498,7 @@ describe('TicketModalPage Component', () => {
expect(getByText(DollarConverter(mockBountiesMutated[1].body.price))).toBeInTheDocument();
// usd conversion
expect(
- getByText(satToUsd(parseInt(mockBountiesMutated[1].body.price)) + ' USD')
+ getByText(`${satToUsd(parseInt(mockBountiesMutated[1].body.price))} USD`)
).toBeInTheDocument();
screen.debug(undefined, Infinity);
// Estimated Hours
@@ -596,4 +607,229 @@ describe('TicketModalPage Component', () => {
});
});
});
+
+ it('test that if a bounty is open and I am the creator of the bounty, I should be able to invite a bounty hunter', async () => {
+ (useIsMobile as jest.Mock).mockReturnValue(false);
+ uiStore.setMeInfo(user);
+
+ jest.spyOn(mainStore, 'getBountyById').mockReturnValue(
+ Promise.resolve([
+ {
+ ...newBounty,
+ person: { ...newBounty.person, owner_alias: user.alias },
+ body: {
+ ...mockBountiesMutated[1].body,
+ owner: user
+ }
+ }
+ ])
+ );
+ jest.spyOn(mainStore, 'getBountyIndexById').mockReturnValue(Promise.resolve(1234));
+ jest.spyOn(mainStore, 'saveBounty').mockResolvedValue();
+
+ await act(async () => {
+ const { getByText } = render(
+
+
+
+ );
+
+ await waitFor(() => getByText('Not Assigned'));
+ fireEvent.click(getByText('Not Assigned'));
+
+ await waitFor(() => {
+ expect(getByText('Assign Developer')).toBeInTheDocument();
+ });
+ });
+ });
+
+ it('test that when I invite a new hunter, the hunter should be the assignee for that bounty', async () => {
+ (useIsMobile as jest.Mock).mockReturnValue(false);
+ uiStore.setMeInfo(user);
+
+ jest.spyOn(mainStore, 'getBountyById').mockReturnValue(
+ Promise.resolve([
+ {
+ ...newBounty,
+ person: { ...newBounty.person, owner_alias: user.alias },
+ body: {
+ ...mockBountiesMutated[1].body,
+ owner: user
+ }
+ }
+ ])
+ );
+ jest.spyOn(mainStore, 'getBountyIndexById').mockReturnValue(Promise.resolve(1234));
+ jest.spyOn(mainStore, 'saveBounty').mockResolvedValue();
+ jest.spyOn(mainStore, 'getPeopleByNameAliasPubkey').mockResolvedValue(
+ Promise.resolve([
+ {
+ id: 1,
+ owner_alias: 'TEST_NAME_1',
+ extras: {
+ coding_languages: [
+ { value: 'R', label: 'R' },
+ { value: 'C++', label: 'C++' }
+ ]
+ }
+ } as any
+ ])
+ );
+
+ await act(async () => {
+ const { getByText } = render(
+
+
+
+ );
+
+ await waitFor(() => getByText('Not Assigned'));
+ fireEvent.click(getByText('Not Assigned'));
+ await waitFor(() => {
+ expect(getByText('Assign Developer')).toBeInTheDocument();
+ });
+
+ fireEvent.click(screen.getByPlaceholderText('Type to search ...'));
+ await userEvent.type(screen.getByPlaceholderText('Type to search ...'), 'TEST_NAME');
+
+ await waitFor(() => getByText('TEST_NAME_1'));
+
+ fireEvent.click(screen.getAllByText('Assign')[0]);
+
+ jest.spyOn(mainStore, 'getBountyById').mockReturnValue(
+ Promise.resolve([
+ {
+ ...newBounty,
+ person: { ...newBounty.person, owner_alias: user.alias },
+ body: {
+ ...mockBountiesMutated[1].body,
+ owner: user
+ }
+ }
+ ])
+ );
+
+ await waitFor(() => {
+ expect(screen.queryByText('Assign Developer')).toBe(null);
+ expect(mainStore.saveBounty).toHaveBeenCalled();
+ expect(mainStore.getBountyById).toHaveBeenCalled();
+ });
+
+ expect(screen.getByText('Edit')).toBeInTheDocument();
+ expect(screen.getByText('TEST_NAME_1')).toBeInTheDocument();
+ });
+ });
+
+ it('test that the creator of a bounty can click on the Edit Bounty, and the Edit Modal should pop up', async () => {
+ (useIsMobile as jest.Mock).mockReturnValue(false);
+ uiStore.setMeInfo(user);
+
+ jest.spyOn(mainStore, 'getBountyById').mockReturnValue(
+ Promise.resolve([
+ {
+ ...newBounty,
+ person: { ...newBounty.person, owner_alias: user.alias },
+ body: {
+ ...mockBountiesMutated[1].body,
+ owner: user
+ }
+ }
+ ])
+ );
+ jest.spyOn(mainStore, 'getBountyIndexById').mockReturnValue(Promise.resolve(1234));
+ jest.spyOn(mainStore, 'saveBounty').mockResolvedValue();
+
+ await act(async () => {
+ const { getByText, getByTestId } = render(
+
+
+
+ );
+
+ await waitFor(() => getByText('Edit'));
+ fireEvent.click(getByText('Edit'));
+ await waitFor(() => getByText('Edit Bounty'));
+ expect(getByText('Edit Bounty')).toBeInTheDocument();
+ expect(getByText('Save')).toBeInTheDocument();
+ expect(getByText('Cancel')).toBeInTheDocument();
+ expect(getByTestId('testid-modal')).toBeInTheDocument();
+ });
+ });
+
+ it('test that when I click Save on the Edit Modal, an Edit action is carried out.', async () => {
+ (useIsMobile as jest.Mock).mockReturnValue(false);
+ uiStore.setMeInfo(user);
+
+ jest.spyOn(mainStore, 'getBountyById').mockReturnValue(
+ Promise.resolve([
+ {
+ ...newBounty,
+ person: { ...newBounty.person, owner_alias: user.alias },
+ body: {
+ ...mockBountiesMutated[1].body,
+ owner: user
+ }
+ }
+ ])
+ );
+ jest.spyOn(mainStore, 'getBountyIndexById').mockReturnValue(Promise.resolve(1234));
+ jest.spyOn(mainStore, 'saveBounty').mockResolvedValue();
+
+ await act(async () => {
+ const { getByText } = render(
+
+
+
+ );
+
+ await waitFor(() => getByText('Edit'));
+ fireEvent.click(getByText('Edit'));
+ await waitFor(() => getByText('Edit Bounty'));
+ expect(getByText('Edit Bounty')).toBeInTheDocument();
+
+ expect(getByText('Save')).toBeInTheDocument();
+ fireEvent.click(getByText('Save'));
+
+ await waitFor(() => getByText('Edit'));
+
+ await waitFor(() => {
+ expect(mainStore.saveBounty).toHaveBeenCalled();
+ });
+ });
+ });
+
+ it('test that when I click on Cancel on the Edit Modal, it hides the Edit Modal and shows the Bounty Modal', async () => {
+ (useIsMobile as jest.Mock).mockReturnValue(false);
+ uiStore.setMeInfo(user);
+
+ jest.spyOn(mainStore, 'getBountyById').mockReturnValue(
+ Promise.resolve([
+ {
+ ...newBounty,
+ person: { ...newBounty.person, owner_alias: user.alias },
+ body: {
+ ...mockBountiesMutated[1].body,
+ owner: user
+ }
+ }
+ ])
+ );
+ jest.spyOn(mainStore, 'getBountyIndexById').mockReturnValue(Promise.resolve(1234));
+
+ await act(async () => {
+ const { getByText, queryByText } = render(
+
+
+
+ );
+
+ await waitFor(() => getByText('Edit'));
+ fireEvent.click(getByText('Edit'));
+ await waitFor(() => getByText('Edit Bounty'));
+ fireEvent.click(getByText('Cancel'));
+ await waitFor(() => getByText('Edit'));
+ expect(queryByText('Edit Bounty')).not.toBeInTheDocument();
+ expect(queryByText('Edit')).toBeInTheDocument();
+ });
+ });
});