Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
#20 fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fadi-albasha committed Apr 1, 2022
1 parent f776c46 commit bdd760c
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 39 deletions.
10 changes: 0 additions & 10 deletions src/components/dashboard/MedicalView/PatientInfo/PatientInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,6 @@ function PatientInfo({ PID }: Props) {

const patientRef = firestore.collection('users').doc(PID);

const handleCloseFile = () => {
setModalContent(0);
handleOpen();
};

const handleViewAppointments = () => {
setModalContent(1);
handleOpen();
};

const handleViewHistory = () => {
setModalContent(2);
handleOpen();
Expand Down
54 changes: 35 additions & 19 deletions src/test/Dashboards/medicalDashboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,40 @@
import { cleanup, fireEvent, render } from '@testing-library/react';
import React, { useState } from 'react';
import { BrowserRouter } from 'react-router-dom';
import MedicalDashboard from '../../components/dashboard/MedicalView';
import MedicalDashboard from '../../components/dashboard/MedicalView/MedicalDashboard';
import { UserProvider } from '../../context/UserContext';

jest.mock('firebase/compat/app', () => {
const onSnapshot = () => ({
onSnapshot,
});
const where = () => ({
onSnapshot,
});
const collection = () => ({
where,
});
// mock Firestore
const Firestore = () => ({
collection,
collection: () => ({
where: () => ({
onSnapshot: () => null,
where: () => ({
onSnapshot: () => null,
}),
}),
doc: () => ({
get: () => ({
then: () => null,
}),
}),
}),
// to mock attributes
FieldValue: {
serverTimestamp: jest.fn(),
},

});

Firestore.FieldValue = {
serverTimestamp: jest.fn(),
};
const firestore = Firestore;

const app = jest.requireActual('firebase/compat/app');

const auth = () => ({
onAuthStateChanged: () => new Promise<void>((resolve) => resolve()),
onAuthStateChanged: () => {
jest.fn();
},
});
auth.GoogleAuthProvider = jest.fn();
auth.signInWithEmailAndPassword = jest.fn();
Expand All @@ -44,15 +52,23 @@ jest.mock('firebase/compat/app', () => {
};
});

jest.mock('firebase/firestore');

afterEach(cleanup);

test('Medical Dashboard Default User Greeting', () => {
const component = render(<BrowserRouter><UserProvider><MedicalDashboard /></UserProvider></BrowserRouter>);
const component = render(
<BrowserRouter>
<UserProvider>
<MedicalDashboard handlePatientClick={undefined} />
</UserProvider>
</BrowserRouter>,
);
expect(component.getByText('Welcome Dr.')).toBeTruthy();
});

test('Medical Dashboard Renders Test', () => {
const component = render(<BrowserRouter><MedicalDashboard /></BrowserRouter>);
const component = render(<BrowserRouter><MedicalDashboard handlePatientClick={undefined} /></BrowserRouter>);
expect(component.getByText('Track and manage your patients')).toBeTruthy();
expect(component.getByText('Name')).toBeTruthy();
expect(component.getByText('Age')).toBeTruthy();
Expand All @@ -62,8 +78,8 @@ test('Medical Dashboard Renders Test', () => {
expect(component.getByText('Latest Symptoms')).toBeTruthy();
});

test('Medical Dashboard Renders View Appointments', () => {
const component = render(<BrowserRouter><MedicalDashboard /></BrowserRouter>);
test('Medical Dashboard Renders Patients table', () => {
const component = render(<BrowserRouter><MedicalDashboard handlePatientClick={undefined} /></BrowserRouter>);
expect(component.getByText('Track and manage your patients')).toBeTruthy();
expect(component.getByText('Name')).toBeTruthy();
expect(component.getByText('Age')).toBeTruthy();
Expand Down
89 changes: 89 additions & 0 deletions src/test/Dashboards/medicalView.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* eslint-disable no-promise-executor-return */
/* eslint-disable @typescript-eslint/ban-ts-comment */
/* eslint-disable global-require */
import { cleanup, fireEvent, render } from '@testing-library/react';
import React, { useState } from 'react';
import { BrowserRouter } from 'react-router-dom';
import MedicalView from '../../components/dashboard/MedicalView/MedicalView';
import { UserProvider } from '../../context/UserContext';

jest.mock('firebase/compat/app', () => {
// mock Firestore
const Firestore = () => ({
collection: () => ({
where: () => ({
onSnapshot: () => null,
where: () => ({
onSnapshot: () => null,
}),
}),
doc: () => ({
get: () => ({
then: () => null,
}),
}),
}),
// to mock attributes
FieldValue: {
serverTimestamp: jest.fn(),
},

});

const firestore = Firestore;

const app = jest.requireActual('firebase/compat/app');

const auth = () => ({
onAuthStateChanged: () => {
jest.fn();
},
});
auth.GoogleAuthProvider = jest.fn();
auth.signInWithEmailAndPassword = jest.fn();
return {
__esModule: true,
...app,
default: {
auth,
initializeApp: jest.fn(),
firestore,
},
};
});

jest.mock('firebase/firestore');

afterEach(cleanup);

test('Medical View Default User Greeting', () => {
const component = render(<BrowserRouter><UserProvider><MedicalView /></UserProvider></BrowserRouter>);
expect(component.getByText('Welcome Dr.')).toBeTruthy();
});

test('Medical View Renders Test', () => {
const component = render(<BrowserRouter><MedicalView /></BrowserRouter>);
expect(component.getByText('Track and manage your patients')).toBeTruthy();
expect(component.getByText('Name')).toBeTruthy();
expect(component.getByText('Age')).toBeTruthy();
expect(component.getByText('Appointment Dates')).toBeTruthy();
expect(component.getByText('Status')).toBeTruthy();
expect(component.getByText('Severity')).toBeTruthy();
expect(component.getByText('Latest Symptoms')).toBeTruthy();
});

test('Medical View Renders Patients table', () => {
const component = render(<BrowserRouter><MedicalView /></BrowserRouter>);
expect(component.getByText('Track and manage your patients')).toBeTruthy();
expect(component.getByText('Name')).toBeTruthy();
expect(component.getByText('Age')).toBeTruthy();
expect(component.getByText('Appointment Dates')).toBeTruthy();
expect(component.getByText('Status')).toBeTruthy();
expect(component.getByText('Severity')).toBeTruthy();
expect(component.getByText('Latest Symptoms')).toBeTruthy();
});

test('Medical View Renders View Appointments', () => {
const component = render(<BrowserRouter><MedicalView /></BrowserRouter>);
expect(component.getAllByText('View Appointments').length).toBeGreaterThan(0);
});
10 changes: 0 additions & 10 deletions src/test/patientInfo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,8 @@ afterEach(cleanup);
test('Patient Info Renders correctly', async () => {
const component = render(<BrowserRouter><PatientInfo PID="123" /></BrowserRouter>);

const closeButton = component.getByText("Close Patient's File");
expect(closeButton).toBeTruthy();
await fireEvent.click(closeButton);

const appointmentButton = component.getByText('View Appointments');
expect(appointmentButton).toBeTruthy();
await fireEvent.click(appointmentButton);

expect(component.getByText("Patient's Info")).toBeTruthy();
expect(component.getByText('Latest Symptoms')).toBeTruthy();
expect(component.getByText('Latest Covid Test')).toBeTruthy();
expect(component.getByText('Case Severity')).toBeTruthy();

const historyButton = component.getByText('History');
expect(historyButton).toBeTruthy();
Expand Down

0 comments on commit bdd760c

Please sign in to comment.