Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2021
Kelas D
PT Gizi Sehat - Dietela
Dietela Mobile
Commits
d7a54f0a
Commit
d7a54f0a
authored
Jun 06, 2021
by
Kefas Satrio Bangkit Solidedantyo
Browse files
Improve Test For QuestionAnswerCommentCard component
parent
8c3c8a32
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/scenes/nutritionist/DietReportForNutritionist/components/QuestionAnswerCommentCard/index.test.tsx
0 → 100644
View file @
d7a54f0a
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
();
});
});
src/scenes/nutritionist/DietReportForNutritionist/index.test.tsx
View file @
d7a54f0a
...
...
@@ -11,17 +11,21 @@ const mockAxios = axios as jest.Mocked<typeof axios>;
describe
(
'
DietReportForNutritionist
'
,
()
=>
{
const
userReports
=
[
mockUserReportResponse
];
const
retrieveUserReportApi
=
()
=>
Promise
.
resolve
({
status
:
200
,
data
:
userReports
,
});
it
(
'
renders correctly
'
,
async
()
=>
{
mockAxios
.
request
.
mockImplementationOnce
(
retrieveUserReportApi
);
mockAxios
.
request
.
mockImplementationOnce
(()
=>
Promise
.
resolve
({
status
:
200
,
data
:
userReports
,
}),
);
render
(<
DietReportForNutritionist
/>,
ROUTES
.
clientDietReportNutritionist
,
{
routeParams
:
{
id
:
1
},
});
await
waitFor
(()
=>
expect
(
mockAxios
.
request
).
toBeCalled
());
});
afterAll
(()
=>
{
jest
.
clearAllMocks
();
});
});
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment