Fakultas Ilmu Komputer UI

Commit 59d47491 authored by Kefas Satrio Bangkit Solidedantyo's avatar Kefas Satrio Bangkit Solidedantyo
Browse files

Merge branch 'pbi-14-progress-diet-nutritionist' into 'staging'

Improve Test For QuestionAnswerCommentCard component

See merge request !72
parents 8c3c8a32 d7a54f0a
Pipeline #81521 passed with stages
in 42 minutes and 46 seconds
import React from 'react';
import { render } from 'utils/testing';
import * as ROUTES from 'constants/routes';
import QuestionAnswerCommentCard from '.';
import { dietReportPage } from '../../pages/types';
describe('DietReportPage', () => {
it('name renders correctly', () => {
const { getByText } = render(
<QuestionAnswerCommentCard
pageName={dietReportPage.PAGE1}
questionName={'name'}
question={'name'}
answer={'Ryujin'}
/>,
ROUTES.clientDietReportNutritionist,
);
expect(getByText(/Ryujin/i)).toBeTruthy();
});
it('email renders correctly', () => {
const { getByText } = render(
<QuestionAnswerCommentCard
pageName={dietReportPage.PAGE1}
questionName={'email'}
question={'email'}
answer={'ryujin@ryujin.com'}
/>,
ROUTES.clientDietReportNutritionist,
);
expect(getByText(/ryujin@ryujin.com/i)).toBeTruthy();
});
it('page 3 renders correctly', () => {
const { getByText } = render(
<QuestionAnswerCommentCard
pageName={dietReportPage.PAGE3}
questionName={'sweet_beverages'}
question={'Minuman manis'}
answer={'4'}
/>,
ROUTES.clientDietReportNutritionist,
);
expect(getByText(/Minuman manis/i)).toBeTruthy();
expect(getByText(/4/i)).toBeTruthy();
});
it('page 2 renders correctly with score description', () => {
const { getByText } = render(
<QuestionAnswerCommentCard
pageName={dietReportPage.PAGE2}
questionName={'hunger_level'}
question={
'Secara rata-rata, sebelum waktu makan selama 1 minggu terakhir ini, dimana level rasa lapar yang Anda rasakan?'
}
answer={'4'}
lowestScoreDescription={'Sangat kelaparan'}
highestScoreDescription={'Sangat begah (kenyang berlebihan)'}
/>,
ROUTES.clientDietReportNutritionist,
);
expect(getByText(/Secara rata-rata, sebelum waktu makan/i)).toBeTruthy();
expect(getByText(/4/i)).toBeTruthy();
expect(getByText(/Sangat kelaparan/i)).toBeTruthy();
expect(getByText(/Sangat begah/i)).toBeTruthy();
});
it('page 2 renders correctly without score description', () => {
const { getByText } = render(
<QuestionAnswerCommentCard
pageName={dietReportPage.PAGE2}
questionName={'water_consumption'}
question={
'Selama 1 minggu terakhir, berapa rata-rata total gelas air putih yang Anda minum?'
}
answer={'3'}
/>,
ROUTES.clientDietReportNutritionist,
);
expect(
getByText(/Selama 1 minggu terakhir, berapa rata-rata total gelas air/i),
).toBeTruthy();
expect(getByText(/3/i)).toBeTruthy();
});
});
...@@ -11,17 +11,21 @@ const mockAxios = axios as jest.Mocked<typeof axios>; ...@@ -11,17 +11,21 @@ const mockAxios = axios as jest.Mocked<typeof axios>;
describe('DietReportForNutritionist', () => { describe('DietReportForNutritionist', () => {
const userReports = [mockUserReportResponse]; const userReports = [mockUserReportResponse];
const retrieveUserReportApi = () =>
Promise.resolve({
status: 200,
data: userReports,
});
it('renders correctly', async () => { it('renders correctly', async () => {
mockAxios.request.mockImplementationOnce(retrieveUserReportApi); mockAxios.request.mockImplementationOnce(() =>
Promise.resolve({
status: 200,
data: userReports,
}),
);
render(<DietReportForNutritionist />, ROUTES.clientDietReportNutritionist, { render(<DietReportForNutritionist />, ROUTES.clientDietReportNutritionist, {
routeParams: { id: 1 }, routeParams: { id: 1 },
}); });
await waitFor(() => expect(mockAxios.request).toBeCalled()); await waitFor(() => expect(mockAxios.request).toBeCalled());
}); });
afterAll(() => {
jest.clearAllMocks();
});
}); });
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment