Skip to content

Commit

Permalink
Jest Test Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdMice committed Feb 4, 2024
1 parent ac13374 commit a0eda27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ function MobileView(props: CodingBountiesProps) {
{!bountyPaid && hasAccess && (
<div className="CreatorDescriptionExtraButton">
<ImageButton
data-testid="Edit"
buttonText={'Edit'}
ButtonContainerStyle={{
width: '117px',
Expand All @@ -555,6 +556,7 @@ function MobileView(props: CodingBountiesProps) {
}}
/>
<ImageButton
data-testid="Delete"
buttonText={!props.deletingState ? 'Delete' : 'Deleting'}
ButtonContainerStyle={{
width: '117px',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '@testing-library/jest-dom';
import { render, fireEvent, screen } from '@testing-library/react';
import { render, fireEvent, screen, getByTestId } from '@testing-library/react';
import { CodingBountiesProps } from 'people/interfaces';
import React from 'react';
import NameTag from 'people/utils/NameTag';
Expand Down Expand Up @@ -167,26 +167,12 @@ describe('MobileView component', () => {
expect(completionDate).toBeInTheDocument();
});

test('opens edit modal on "Edit" button click', () => {
render(<MobileView {...defaultProps} />);
const editButton = screen.getByText('Edit');
fireEvent.click(editButton);
expect(screen.getByText('Edit Modal Text')).toBeInTheDocument();
});

test('opens delete modal on "Delete" button click', () => {
render(<MobileView {...defaultProps} />);
const deleteButton = screen.getByText('Delete');
fireEvent.click(deleteButton);
expect(screen.getByText('Delete Modal Text')).toBeInTheDocument();
});

it('renders the delete and edit buttons for the creator', () => {
const { getByText } = render(<MobileView {...defaultProps} />);
expect(getByText('Edit')).toBeInTheDocument();
expect(getByText('Delete')).toBeInTheDocument();
fireEvent.click(getByText('Edit'));
fireEvent.click(getByText('Delete'));
const { getByTestId } = render(<MobileView {...defaultProps} />);
expect(getByTestId('Edit')).toBeInTheDocument();
expect(getByTestId('Delete')).toBeInTheDocument();
fireEvent.click(getByTestId('Edit'));
fireEvent.click(getByTestId('Delete'));
expect(mockEditAction).toHaveBeenCalledTimes(1);
expect(mockDeleteAction).toHaveBeenCalledTimes(1);
});
Expand Down

0 comments on commit a0eda27

Please sign in to comment.