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
PPL Sosial
tbcare
tbcare-mobile
Commits
61b6b753
Commit
61b6b753
authored
Jun 06, 2021
by
jahnsmichael
Browse files
[RED] EditProfileForm scene
parent
7687186b
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/scenes/EditProfileForm/index.test.tsx
View file @
61b6b753
import
'
react-native
'
;
import
React
from
'
react
'
;
import
axios
from
'
axios
'
;
import
{
NavigationContainer
}
from
'
@react-navigation/native
'
;
import
{
createStackNavigator
}
from
'
@react-navigation/stack
'
;
import
ReactTestRenderer
,
{
act
}
from
'
react-test-renderer
'
;
import
EditProfileForm
from
'
.
'
;
import
{
AppContext
}
from
'
contexts
'
;
import
{
useMainService
}
from
'
services
'
;
const
Stack
=
createStackNavigator
();
const
testProps
=
{
services
:
{
main
:
useMainService
(
'
dummyToken
'
),
},
user
:
{
name
:
"
test name
"
,
username
:
"
testusername
"
,
email
:
"
test@email.com
"
,
phone_number
:
"
0123456789
"
,
district
:
"
Tapos
"
,
sub_district
:
"
Sukatani
"
,
},
setUser
:
(
data
:
any
)
=>
{
testProps
.
user
=
data
;
},
cache
:
{},
}
jest
.
mock
(
'
axios
'
);
jest
.
useFakeTimers
();
const
mockedAxios
=
axios
as
jest
.
Mocked
<
typeof
axios
>
;
it
(
'
renders correctly
'
,
()
=>
{
const
instance
=
ReactTestRenderer
.
create
(
<
NavigationContainer
>
<
Stack
.
Navigator
screenOptions
=
{
{
header
:
()
=>
<></>,
}
}
>
<
Stack
.
Screen
name
=
"edit-profile"
component
=
{
EditProfileForm
}
/>
</
Stack
.
Navigator
>
</
NavigationContainer
>,
);
expect
(
instance
.
toJSON
()).
toMatchSnapshot
();
});
\ No newline at end of file
describe
(
"
EditProfileForm
"
,
()
=>
{
it
(
'
renders correctly
'
,
()
=>
{
const
instance
=
ReactTestRenderer
.
create
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
NavigationContainer
>
<
Stack
.
Navigator
screenOptions
=
{
{
header
:
()
=>
<></>,
}
}
>
<
Stack
.
Screen
name
=
"edit-profile"
component
=
{
EditProfileForm
}
/>
</
Stack
.
Navigator
>
</
NavigationContainer
>
,
</
AppContext
.
Provider
>
);
expect
(
instance
.
toJSON
()).
toMatchSnapshot
();
});
it
(
'
success with insert fields with valid values
'
,
async
()
=>
{
const
formPage
=
ReactTestRenderer
.
create
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
NavigationContainer
>
<
Stack
.
Navigator
screenOptions
=
{
{
// Empty header
header
:
()
=>
<></>,
}
}
>
<
Stack
.
Screen
name
=
"edit-profile"
component
=
{
EditProfileForm
}
/>
</
Stack
.
Navigator
>
</
NavigationContainer
>
</
AppContext
.
Provider
>
);
expect
(
formPage
).
toBeTruthy
()
const
nameField
=
formPage
.
root
.
find
(
elem
=>
elem
.
props
.
id
===
"
new_name
"
)
expect
(
nameField
).
toBeTruthy
()
const
usernameField
=
formPage
.
root
.
find
(
elem
=>
elem
.
props
.
id
===
"
new_username
"
)
expect
(
usernameField
).
toBeTruthy
()
const
passwordField
=
formPage
.
root
.
find
(
elem
=>
elem
.
props
.
id
===
"
new_password
"
)
expect
(
passwordField
).
toBeTruthy
()
const
confirmPasswordField
=
formPage
.
root
.
find
(
elem
=>
elem
.
props
.
id
===
"
confirm_new_password
"
)
expect
(
confirmPasswordField
).
toBeTruthy
()
const
emailField
=
formPage
.
root
.
find
(
elem
=>
elem
.
props
.
id
===
"
new_email
"
)
expect
(
emailField
).
toBeTruthy
()
const
phoneField
=
formPage
.
root
.
find
(
elem
=>
elem
.
props
.
id
===
"
new_phone_number
"
)
expect
(
phoneField
).
toBeTruthy
()
const
districtField
=
formPage
.
root
.
find
(
elem
=>
elem
.
props
.
id
===
"
new_district
"
)
expect
(
districtField
).
toBeTruthy
()
const
sub_districtField
=
formPage
.
root
.
find
(
elem
=>
elem
.
props
.
id
===
"
new_sub_district
"
)
expect
(
sub_districtField
).
toBeTruthy
()
// Set value
act
(()
=>
{
if
(
nameField
&&
usernameField
&&
passwordField
&&
confirmPasswordField
&&
emailField
&&
phoneField
&&
districtField
&&
sub_districtField
)
{
nameField
.
props
.
updateValue
(
"
your name
"
)
usernameField
.
props
.
updateValue
(
"
username
"
)
passwordField
.
props
.
updateValue
(
"
asdQWE123
"
)
confirmPasswordField
.
props
.
updateValue
(
"
asdQWE123
"
)
emailField
.
props
.
updateValue
(
"
email@gmail.com
"
)
phoneField
.
props
.
updateValue
(
"
081802769312
"
)
districtField
.
props
.
updateValue
(
"
districtku
"
)
sub_districtField
.
props
.
updateValue
(
"
subdistrictku
"
)
}
})
expect
(
formPage
.
toJSON
()).
toMatchSnapshot
()
mockedAxios
.
request
.
mockImplementationOnce
(
()
=>
new
Promise
(
resolve
=>
{
resolve
({
status
:
200
,
data
:
{
"
message
"
:
"
success edit profile
"
,
},
});
})
);
const
submit
=
formPage
.
root
.
find
(
elem
=>
elem
.
props
.
id
===
"
submit
"
)
await
act
(
async
()
=>
{
submit
.
props
.
onPress
()
})
});
})
\ No newline at end of file
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