Fakultas Ilmu Komputer UI
Skip to content
GitLab
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
45fda602
Commit
45fda602
authored
Mar 29, 2021
by
Wulan Mantiri
Browse files
Integrate Dietela Quiz response to Quiz Result page
parent
96decd10
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/scenes/questionnaire/AllAccessQuestionnaire/index.test.tsx
View file @
45fda602
...
...
@@ -91,7 +91,7 @@ describe('AllAccessQuestionnaire', () => {
expect
(
nextPage
).
toBeTruthy
();
});
it
(
'
redirects to
initial
page if all form values are valid and submit success
'
,
async
()
=>
{
it
(
'
redirects to
quiz result
page if all form values are valid and submit success
'
,
async
()
=>
{
const
createDietProfileApi
=
()
=>
Promise
.
resolve
({
status
:
201
,
...
...
@@ -126,11 +126,11 @@ describe('AllAccessQuestionnaire', () => {
const
submitButton
=
getByText
(
'
Selesai
'
);
await
waitFor
(()
=>
fireEvent
.
press
(
submitButton
));
const
initial
Page
=
getByText
(
/
konsultasi sekarang
/i
);
expect
(
initial
Page
).
toBeTruthy
();
const
quizResult
Page
=
getByText
(
/
Quiz Result
/i
);
expect
(
quizResult
Page
).
toBeTruthy
();
});
it
(
'
does not redirect to
initial
page if all form values are valid but submit fails
'
,
async
()
=>
{
it
(
'
does not redirect to
quiz result
page if all form values are valid but submit fails
'
,
async
()
=>
{
const
createDietProfileApi
=
()
=>
Promise
.
reject
({
status
:
400
,
...
...
@@ -162,7 +162,11 @@ describe('AllAccessQuestionnaire', () => {
const
submitButton
=
getByText
(
'
Selesai
'
);
await
waitFor
(()
=>
fireEvent
.
press
(
submitButton
));
const
initialPage
=
queryByText
(
/konsultasi sekarang/i
);
expect
(
initialPage
).
toBeFalsy
();
const
quizResultPage
=
queryByText
(
/Quiz Result/i
);
expect
(
quizResultPage
).
toBeFalsy
();
});
afterAll
(()
=>
{
jest
.
clearAllMocks
();
});
});
src/scenes/questionnaire/AllAccessQuestionnaire/index.tsx
View file @
45fda602
...
...
@@ -44,7 +44,7 @@ const AllAccessQuestionnaire: FC = () => {
CACHE_KEYS
.
dietProfileId
,
`
${
response
.
data
?.
id
}
`
,
);
navigation
.
navigate
(
ROUTES
.
initial
);
navigation
.
navigate
(
ROUTES
.
dietelaQuizResult
,
response
.
data
);
}
else
{
Toast
.
show
({
type
:
'
error
'
,
...
...
src/services/api.ts
View file @
45fda602
...
...
@@ -7,16 +7,20 @@ export enum RequestMethod {
DELETE
=
'
DELETE
'
,
}
export
async
function
api
(
export
interface
Response
<
T
>
{
success
:
boolean
;
data
?:
T
;
error
?:
any
;
}
export
type
ApiResponse
<
T
>
=
Promise
<
Response
<
T
>>
;
export
async
function
api
<
T
>
(
method
:
RequestMethod
=
RequestMethod
.
GET
,
url
:
string
,
body
:
object
=
{},
headers
:
object
=
{},
):
Promise
<
{
success
:
boolean
;
data
?:
any
;
error
?:
any
;
}
>
{
):
ApiResponse
<
T
>
{
const
requestData
:
AxiosRequestConfig
=
{
url
:
`https://dietela-backend.herokuapp.com/
${
url
}
`
,
method
,
...
...
src/services/dietelaQuiz/index.ts
View file @
45fda602
import
{
api
,
RequestMethod
}
from
'
../api
'
;
import
{
api
,
RequestMethod
,
ApiResponse
}
from
'
../api
'
;
import
*
as
apiUrls
from
'
./urls
'
;
import
{
DietProfileRequest
}
from
'
./models
'
;
import
{
DietProfileRequest
,
DietProfileResponse
}
from
'
./models
'
;
export
const
createDietProfileApi
=
(
body
:
DietProfileRequest
)
=>
{
export
const
createDietProfileApi
=
(
body
:
DietProfileRequest
,
):
ApiResponse
<
DietProfileResponse
>
=>
{
return
api
(
RequestMethod
.
POST
,
apiUrls
.
dietProfile
,
body
);
};
src/services/dietelaQuiz/models.ts
View file @
45fda602
...
...
@@ -20,3 +20,11 @@ export interface DietProfileRequest {
problem_to_solve
:
number
;
health_problem
:
number
[];
}
// TODO: Doan
export
interface
DietelaQuizResult
{}
export
interface
DietProfileResponse
extends
DietProfileRequest
{
id
:
number
;
quiz_result
:
DietelaQuizResult
;
}
src/utils/testing.tsx
View file @
45fda602
...
...
@@ -3,7 +3,6 @@ import { render, RenderOptions } from '@testing-library/react-native';
import
{
NavigationContainer
}
from
'
@react-navigation/native
'
;
import
{
createStackNavigator
}
from
'
@react-navigation/stack
'
;
import
*
as
ROUTES
from
'
constants/routes
'
;
import
{
navigation
}
from
'
constants/navigation
'
;
const
Stack
=
createStackNavigator
();
...
...
@@ -16,7 +15,7 @@ interface TestProvider {
const
TestProvider
:
FC
<
TestProvider
>
=
({
route
,
children
})
=>
{
return
(
<
NavigationContainer
>
<
Stack
.
Navigator
initialRouteName
=
{
ROUTES
.
allAccessQuestionnair
e
}
>
<
Stack
.
Navigator
initialRouteName
=
{
rout
e
}
>
{
navigation
.
map
((
nav
,
i
)
=>
(
<
Stack
.
Screen
key
=
{
`nav
${
i
}
`
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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