Skip to content

Commit

Permalink
Writing tsests
Browse files Browse the repository at this point in the history
  • Loading branch information
JayaBadarawada committed Jun 13, 2024
1 parent 37a98f4 commit 8d69bce
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions src/__tests__/components/CommentsSection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {render,fireEvent,waitFor } from "@testing-library/react-native";
import { CommentsSection } from "../../components/ChartCard/ChatComments/CommentsSection";
import userLevelStore from "../../store/userLevel";
import { Role } from "../../utility/enums";

import { AlertQuestion } from "../../components/Alerts/AlertQuestion ";

jest.mock("@react-native-firebase/firestore", () => {
return jest.fn();
Expand All @@ -28,6 +28,7 @@ jest.mock("@react-native-firebase/firestore", () => {
userLevel: jest.fn(),
}),
}));


const mockAddComment = jest.fn();
const mockDeleteComment = jest.fn();
Expand Down Expand Up @@ -64,6 +65,10 @@ const comments = [
];






describe("Testing CommentsSection Component", () => {
user()
it('renders comments correctly', () => {
Expand Down Expand Up @@ -124,7 +129,7 @@ describe("Testing CommentsSection Component", () => {
expect(editMenu).toBeTruthy();
});

it('Superadmin can delete any comment', () => {
it('Superadmin should see delete option for all comments', () => {
superAdmin();
const { getAllByTestId} = render(
<CommentsSection
Expand Down Expand Up @@ -153,7 +158,7 @@ describe("Testing CommentsSection Component", () => {
const editMenu = queryByTestId('chat-card-edit-menu');
expect(editMenu).toBeFalsy();
});
it('Delete a comment', async () => {
it('Should delete comment when user who wrote it pressing delete', async () => {
user();
const { getByTestId, getByText,debug } = render(
<CommentsSection
Expand All @@ -167,17 +172,32 @@ describe("Testing CommentsSection Component", () => {

const deleteMenu = getByTestId('chat-card-edit-menu');
fireEvent.press(deleteMenu);
const deleteButton = getByText("Ta bort");


const deleteButton = getByTestId("dropdown-overlay-ta bort");
fireEvent.press(deleteButton);
expect(mockDeleteComment).toBeTruthy();
await waitFor(() => {
expect(mockDeleteComment).toHaveBeenCalledWith({
comment: 'Third comment',
userID: loggedInUser.id,
userFirstName: loggedInUser.firstName,
userLastName: loggedInUser.lastName,
}, 'post1');
});

// TODO: mock alert to test delet function

// await waitFor(() => {
// expect(mockAlert).toHaveBeenCalledWith(
// '',
// 'Vill du ta bort den här kommentar?',
// // expect.any(Array)
// );



// expect(mockDeleteComment).toBeTruthy();


// expect(mockDeleteComment).toHaveBeenCalledWith({
// comment: 'Third comment',
// userID: loggedInUser.id,
// userFirstName: loggedInUser.firstName,
// userLastName: loggedInUser.lastName,
// }, 'post1');
// });
});

});

0 comments on commit 8d69bce

Please sign in to comment.