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
e9f4d153
Commit
e9f4d153
authored
May 30, 2021
by
Wulan Mantiri
Browse files
Fix test bugs
parent
133c5b9e
Changes
52
Hide whitespace changes
Inline
Side-by-side
package.json
View file @
e9f4d153
...
...
@@ -6,7 +6,7 @@
"android"
:
"react-native run-android"
,
"ios"
:
"react-native run-ios"
,
"start"
:
"react-native start"
,
"test"
:
"jest --
maxWorkers=7
--coverage --watchAll=false --verbose --collectCoverageFrom=
\"
src/**/*.tsx
\"
"
,
"test"
:
"jest --
runInBand
--coverage --watchAll=false --verbose --collectCoverageFrom=
\"
src/**/*.tsx
\"
"
,
"test-only"
:
"jest --verbose -t"
,
"lint"
:
"eslint . --ext .ts,.tsx --fix"
,
"prettify"
:
"prettier --write src"
,
...
...
src/app/schema.ts
View file @
e9f4d153
...
...
@@ -4,6 +4,8 @@ import {
clientNavigation
,
nutritionistNavigation
,
adminNavigation
,
onboardingClientNavigation
,
unpaidClientNavigation
,
}
from
'
constants/navigation
'
;
import
{
UserRole
,
AuthUserResponse
}
from
'
services/auth/models
'
;
import
{
TransactionStatus
}
from
'
services/payment/models
'
;
...
...
@@ -14,16 +16,19 @@ export const getNavigation = (
)
=>
{
if
(
isAuthenticated
)
{
if
(
user
.
role
===
UserRole
.
CLIENT
)
{
let
initialRoute
=
ROUTES
.
clientProfile
;
if
([
TransactionStatus
.
UNPAID
,
null
].
includes
(
user
.
transaction_status
))
{
initialRoute
=
ROUTES
.
checkout
;
}
else
if
(
user
.
transaction_status
===
TransactionStatus
.
PENDING
)
{
initialRoute
=
ROUTES
.
paymentResult
;
return
{
initialRoute
:
ROUTES
.
checkout
,
navigation
:
unpaidClientNavigation
,
};
}
else
if
(
!
user
.
is_finished_onboarding
)
{
initialRoute
=
ROUTES
.
extendedQuestionnaire
;
return
{
initialRoute
:
ROUTES
.
extendedQuestionnaire
,
navigation
:
onboardingClientNavigation
,
};
}
return
{
initialRoute
,
initialRoute
:
ROUTES
.
clientProfile
,
navigation
:
clientNavigation
,
};
}
...
...
@@ -34,6 +39,7 @@ export const getNavigation = (
navigation
:
nutritionistNavigation
,
};
}
if
(
user
.
role
===
UserRole
.
ADMIN
)
{
return
{
initialRoute
:
ROUTES
.
clientListForAdmin
,
...
...
src/components/form/StepByStepForm/styles.ts
View file @
e9f4d153
...
...
@@ -46,6 +46,7 @@ export const styles = StyleSheet.create({
},
button
:
{
padding
:
10
,
paddingHorizontal
:
0
,
backgroundColor
:
colors
.
primaryYellow
,
},
finishButton
:
{
...
...
src/constants/navigation.ts
View file @
e9f4d153
...
...
@@ -97,22 +97,7 @@ export const publicNavigation: NavRoute[] = [
},
];
export
const
clientNavigation
:
NavRoute
[]
=
[
{
name
:
ROUTES
.
checkout
,
component
:
Checkout
,
header
:
'
Checkout
'
,
},
{
name
:
ROUTES
.
payment
,
component
:
PaymentWebView
,
header
:
'
Pembayaran
'
,
},
{
name
:
ROUTES
.
paymentResult
,
component
:
PaymentResult
,
},
...
navigation
,
const
defaultClientNavigation
:
NavRoute
[]
=
[
{
name
:
ROUTES
.
extendedQuestionnaire
,
component
:
ExtendedQuestionnaire
,
...
...
@@ -147,18 +132,55 @@ export const clientNavigation: NavRoute[] = [
...
nav
,
name
:
ROUTES
.
extendedQuestionnaireById
(
id
),
})),
];
export
const
onboardingClientNavigation
:
NavRoute
[]
=
[
...
defaultClientNavigation
,
{
name
:
ROUTES
.
clientProfile
,
component
:
ClientProfile
,
header
:
'
Profil Saya
'
,
},
];
export
const
unpaidClientNavigation
:
NavRoute
[]
=
[
{
name
:
ROUTES
.
checkout
,
component
:
Checkout
,
header
:
'
Checkout
'
,
},
{
name
:
ROUTES
.
payment
,
component
:
PaymentWebView
,
header
:
'
Pembayaran
'
,
},
{
name
:
ROUTES
.
paymentResult
,
component
:
PaymentResult
,
},
...
navigation
,
{
name
:
ROUTES
.
clientProfile
,
component
:
ClientProfile
,
header
:
'
Profil Saya
'
,
},
...
defaultClientNavigation
,
];
export
const
clientNavigation
:
NavRoute
[]
=
[
{
name
:
ROUTES
.
clientProfile
,
component
:
ClientProfile
,
header
:
'
Profil Saya
'
,
},
...
defaultClientNavigation
,
];
export
const
nutritionistNavigation
:
NavRoute
[]
=
[
{
name
:
ROUTES
.
clientListForNutritionist
,
component
:
ClientListNutritionist
,
header
:
'
List
Klien
'
,
header
:
'
Daftar
Klien
'
,
},
{
name
:
ROUTES
.
clientChatNutritionist
,
...
...
@@ -186,7 +208,7 @@ export const adminNavigation: NavRoute[] = [
{
name
:
ROUTES
.
clientListForAdmin
,
component
:
ClientListAdmin
,
header
:
'
List
Klien
'
,
header
:
'
Daftar
Klien
'
,
},
{
name
:
ROUTES
.
clientProfileAdmin
,
...
...
@@ -211,7 +233,7 @@ export const adminNavigation: NavRoute[] = [
];
export
const
testNavigation
:
NavRoute
[]
=
[
...
c
lientNavigation
,
...
unpaidC
lientNavigation
,
...
nutritionistNavigation
,
...
adminNavigation
,
{
...
...
src/hooks/index.ts
View file @
e9f4d153
export
{
default
as
useApi
}
from
'
./useApi
'
;
export
{
default
as
useDownloadFiles
}
from
'
./useDownloadFiles
'
;
export
{
default
as
useForm
}
from
'
./useForm
'
;
export
{
default
as
useLinkingEffect
}
from
'
./useLinkingEffect
'
;
export
{
default
as
useSignupEffect
}
from
'
./useSignupEffect
'
;
src/hooks/useLinkingEffect/index.ts
deleted
100644 → 0
View file @
133c5b9e
import
{
useEffect
}
from
'
react
'
;
import
{
Linking
}
from
'
react-native
'
;
import
{
useNavigation
}
from
'
@react-navigation/native
'
;
import
*
as
ROUTES
from
'
constants/routes
'
;
const
useLinkingEffect
=
()
=>
{
const
navigation
=
useNavigation
();
const
getQueryParams
=
(
path
:
string
|
null
)
=>
{
return
path
?
JSON
.
parse
(
'
{"
'
+
decodeURI
(
path
.
replace
(
/&/g
,
'
","
'
).
replace
(
/
[
=
]
/g
,
'
":"
'
))
+
'
"}
'
,
)
:
{};
};
useEffect
(()
=>
{
const
navigate
=
(
url
:
string
|
null
)
=>
{
if
(
url
)
{
const
splitUrl
=
url
.
split
(
'
?
'
);
const
path
=
splitUrl
[
0
].
split
(
'
/
'
).
slice
(
3
).
join
(
'
/
'
);
const
queryParams
=
getQueryParams
(
splitUrl
[
1
]);
if
(
path
===
'
payment
'
)
{
navigation
.
reset
({
index
:
0
,
routes
:
[{
name
:
ROUTES
.
paymentResult
,
params
:
queryParams
}],
});
}
}
};
const
handleOpenURL
=
(
event
:
{
url
:
string
})
=>
{
navigate
(
event
.
url
);
};
Linking
.
addEventListener
(
'
url
'
,
handleOpenURL
);
return
()
=>
{
Linking
.
removeEventListener
(
'
url
'
,
handleOpenURL
);
};
},
[
navigation
]);
};
export
default
useLinkingEffect
;
src/
__
mocks
__
/auth.ts
→
src/mocks/auth.ts
View file @
e9f4d153
import
{
LoginResponse
,
UserRole
}
from
'
services/auth/models
'
;
import
{
TransactionStatus
}
from
'
services/payment/models
'
;
export
const
validRegistrationValues
:
{
[
_
:
string
]:
any
}
=
{
name
:
'
Doan Didinding
'
,
...
...
@@ -32,5 +33,8 @@ export const authResponse: LoginResponse = {
email
:
validRegistrationValues
.
email
,
name
:
validRegistrationValues
.
name
,
role
:
UserRole
.
CLIENT
,
transaction_status
:
TransactionStatus
.
UNPAID
,
is_finished_onboarding
:
false
,
cart_id
:
1
,
},
};
src/
__
mocks
__
/cart.ts
→
src/mocks/cart.ts
View file @
e9f4d153
File moved
src/
__
mocks
__
/clientList.ts
→
src/mocks/clientList.ts
View file @
e9f4d153
File moved
src/
__
mocks
__
/dietQuestionnaire.ts
→
src/mocks/dietQuestionnaire.ts
View file @
e9f4d153
File moved
src/
__
mocks
__
/dietRecommendation.ts
→
src/mocks/dietRecommendation.ts
View file @
e9f4d153
File moved
src/
__
mocks
__
/quizResult.ts
→
src/mocks/quizResult.ts
View file @
e9f4d153
File moved
src/provider/UserContext/index.ts
View file @
e9f4d153
...
...
@@ -29,6 +29,7 @@ export const initialUser = {
role
:
null
,
transaction_status
:
null
,
is_finished_onboarding
:
false
,
cart_id
:
null
,
};
export
const
UserContext
=
createContext
<
iUserContext
>
({
...
...
src/scenes/admin/ClientListAdmin/index.test.tsx
View file @
e9f4d153
...
...
@@ -4,7 +4,7 @@ import * as ROUTES from 'constants/routes';
import
axios
from
'
axios
'
;
import
ClientListAdmin
from
'
.
'
;
import
{
mockClientList
}
from
'
__
mocks
__
/clientList
'
;
import
{
mockClientList
}
from
'
mocks/clientList
'
;
jest
.
mock
(
'
axios
'
);
const
mockAxios
=
axios
as
jest
.
Mocked
<
typeof
axios
>
;
...
...
@@ -18,6 +18,7 @@ describe('ClientListAdmin', () => {
}),
);
render
(<
ClientListAdmin
/>,
ROUTES
.
clientListForAdmin
);
await
waitFor
(()
=>
expect
(
mockAxios
.
request
).
toBeCalled
());
});
it
(
'
shows correct client list
'
,
async
()
=>
{
...
...
@@ -28,12 +29,11 @@ describe('ClientListAdmin', () => {
}),
);
const
{
queryByText
,
queryAllByText
}
=
render
(
const
{
queryByText
}
=
render
(
<
ClientListAdmin
/>,
ROUTES
.
clientListForAdmin
,
);
await
waitFor
(()
=>
expect
(
queryAllByText
(
/List Klien/i
)).
toBeTruthy
());
await
waitFor
(()
=>
expect
(
mockAxios
.
request
).
toBeCalled
());
expect
(
queryByText
(
mockClientList
[
0
].
user
.
name
)).
toBeTruthy
();
expect
(
queryByText
(
/Download Csv/i
)).
toBeTruthy
();
...
...
src/scenes/auth/Login/index.test.tsx
View file @
e9f4d153
...
...
@@ -4,7 +4,7 @@ import * as ROUTES from 'constants/routes';
import
axios
from
'
axios
'
;
import
Login
from
'
.
'
;
import
{
authResponse
,
validLoginValues
}
from
'
__
mocks
__
/auth
'
;
import
{
authResponse
,
validLoginValues
}
from
'
mocks/auth
'
;
import
{
textField
}
from
'
./schema
'
;
jest
.
mock
(
'
react-native-toast-message
'
);
...
...
src/scenes/auth/Login/index.tsx
View file @
e9f4d153
...
...
@@ -11,7 +11,7 @@ import { generateValidationSchema } from 'utils/form';
import
{
layoutStyles
}
from
'
styles
'
;
import
{
TextField
}
from
'
components/form
'
;
import
{
Section
}
from
'
components/layout
'
;
import
{
useNavigation
}
from
'
@react-navigation/
cor
e
'
;
import
{
useNavigation
}
from
'
@react-navigation/
nativ
e
'
;
import
*
as
ROUTES
from
'
constants/routes
'
;
const
isPasswordField
=
(
name
:
string
)
=>
name
===
'
password
'
;
...
...
src/scenes/auth/LoginChoosePlan/index.tsx
View file @
e9f4d153
import
{
useNavigation
}
from
'
@react-navigation/
cor
e
'
;
import
{
useNavigation
}
from
'
@react-navigation/
nativ
e
'
;
import
{
Link
}
from
'
components/core
'
;
import
React
,
{
FC
}
from
'
react
'
;
import
Login
from
'
../Login
'
;
...
...
src/scenes/auth/ManualRegistrationPage/index.test.tsx
View file @
e9f4d153
...
...
@@ -11,7 +11,7 @@ import {
authResponse
,
validRegistrationValues
,
invalidRegistrationValues
,
}
from
'
__
mocks
__
/auth
'
;
}
from
'
mocks/auth
'
;
jest
.
mock
(
'
react-native-toast-message
'
);
jest
.
mock
(
'
axios
'
);
...
...
src/scenes/auth/ManualRegistrationPage/index.tsx
View file @
e9f4d153
import
React
,
{
FC
,
useContext
}
from
'
react
'
;
import
{
useForm
,
useSignupEffect
}
from
'
hooks
'
;
import
{
ScrollView
}
from
'
react-native-gesture-handler
'
;
import
{
useNavigation
,
useRoute
}
from
'
@react-navigation/
cor
e
'
;
import
{
useNavigation
,
useRoute
}
from
'
@react-navigation/
nativ
e
'
;
import
{
BigButton
,
Link
,
Toast
}
from
'
components/core
'
;
import
{
Section
}
from
'
components/layout
'
;
...
...
src/scenes/auth/NutritionistAdminLogin/index.test.tsx
View file @
e9f4d153
...
...
@@ -4,7 +4,7 @@ import * as ROUTES from 'constants/routes';
import
axios
from
'
axios
'
;
import
NutritionistAdminLogin
from
'
.
'
;
import
{
authResponse
,
validLoginValues
}
from
'
__
mocks
__
/auth
'
;
import
{
authResponse
,
validLoginValues
}
from
'
mocks/auth
'
;
import
{
textField
}
from
'
./schema
'
;
jest
.
mock
(
'
react-native-toast-message
'
);
...
...
Prev
1
2
3
Next
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