Skip to content
Open
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
98 changes: 98 additions & 0 deletions src/pages/tickets/__tests__/TicketModalPage.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,39 @@ describe('TicketModalPage Component', () => {
});
});

it('keeps the bounty modal open when the signed-in hunter clicks I can help', async () => {
(useIsMobile as jest.Mock).mockReturnValue(false);
uiStore.setMeInfo(user);

jest
.spyOn(mainStore, 'getBountyById')
.mockReturnValue(
Promise.resolve([
{ ...newBounty, body: { ...mockBountiesMutated[1].body, assignee: { owner_alias: '' } } }
])
);
jest.spyOn(mainStore, 'getBountyIndexById').mockReturnValue(Promise.resolve(1234));

const connectFn = jest.fn();
await act(async () => {
const { getByText, getByTestId } = render(
<MemoryRouter initialEntries={['/bounty/1234']}>
<Route
path="/bounty/:bountyId"
render={(props: any) => <TicketModalPage setConnectPerson={connectFn} {...props} />}
/>
</MemoryRouter>
);

await waitFor(() => getByText('I can help'));
fireEvent.click(getByText('I can help'));

expect(connectFn).toHaveBeenCalled();
expect(getByTestId('testid-modal')).toBeInTheDocument();
expect(getByText(mockBountiesMutated[1].body.title)).toBeInTheDocument();
});
});

it('render bounty title, description, estimated hours and sats', async () => {
jest
.spyOn(mainStore, 'getBountyById')
Expand Down Expand Up @@ -215,6 +248,71 @@ describe('TicketModalPage Component', () => {
});
});

it('clicks the bounty github, tribe, copy link, and twitter action buttons', async () => {
(useIsMobile as jest.Mock).mockReturnValue(false);
uiStore.setMeInfo(user);

const clipboardWrite = jest.fn().mockResolvedValue(undefined);
Object.defineProperty(navigator, 'clipboard', {
value: { writeText: clipboardWrite },
configurable: true
});

const clickedUrls: string[] = [];
const anchorClickSpy = jest
.spyOn(HTMLAnchorElement.prototype, 'click')
.mockImplementation(function (this: HTMLAnchorElement) {
clickedUrls.push(this.href);
});

const ticketUrl = 'https://github.com/stakwork/sphinx-tribes/issues/871';
const tribe = 'sphinx-test';

jest.spyOn(mainStore, 'getBountyById').mockReturnValue(
Promise.resolve([
{
...newBounty,
person: { ...newBounty.person, owner_alias: user.alias },
body: {
...mockBountiesMutated[1].body,
id: 871,
owner_id: user.owner_pubkey,
owner: user,
ticket_url: ticketUrl,
tribe
}
}
])
);
jest.spyOn(mainStore, 'getBountyIndexById').mockReturnValue(Promise.resolve(1234));

await act(async () => {
const { getByText } = render(
<MemoryRouter initialEntries={['/bounty/871']}>
<Route path="/bounty/:bountyId" component={TicketModalPage} />
</MemoryRouter>
);

await waitFor(() => getByText('Github Ticket'));

fireEvent.click(getByText('Github Ticket'));
expect(clickedUrls).toContain(ticketUrl);

fireEvent.click(getByText(tribe));
expect(clickedUrls).toContain(`https://community.sphinx.chat/t/${tribe}`);

fireEvent.click(getByText('Copy Link'));
expect(clipboardWrite).toHaveBeenCalledWith(`${window.location.origin}/bounty/871`);

fireEvent.click(getByText('Share to Twitter'));
expect(clickedUrls.some((url: string) => url.includes('twitter.com/intent/tweet'))).toBe(
true
);
});

anchorClickSpy.mockRestore();
});

it('should render github ticket link button', async () => {
jest.spyOn(mainStore, 'getBountyById').mockReturnValue(
Promise.resolve([
Expand Down