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
96614cbd
Commit
96614cbd
authored
May 29, 2021
by
Zafir Rasyidi Taufik
Browse files
[RED] Add test for checking implementation
parent
9b685c5f
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/scenes/LoginPage/index.test.tsx
View file @
96614cbd
...
...
@@ -29,12 +29,14 @@ const testProps = {
cache
:
{},
}
const
mockNavigation
=
jest
.
fn
()
const
mockNavigation
=
jest
.
fn
();
const
mockReset
=
jest
.
fn
();
jest
.
mock
(
'
@react-navigation/native
'
,
()
=>
{
return
{
...
jest
.
requireActual
(
'
@react-navigation/native
'
),
useNavigation
:
()
=>
({
navigate
:
mockNavigation
,
reset
:
mockReset
}),
};
});
...
...
@@ -42,7 +44,7 @@ jest.doMock('@react-native-google-signin/google-signin')
jest
.
mock
(
'
axios
'
);
const
mockedAxios
=
axios
as
jest
.
Mocked
<
typeof
axios
>
;
after
Each
(()
=>
{
before
Each
(()
=>
{
jest
.
clearAllMocks
();
});
...
...
@@ -231,7 +233,7 @@ it('inserts invalid (length<8) password', async () => {
expect
(
testProps
.
alert
.
message
).
toBe
(
"
Unknown Server Error
"
);
});
it
(
'
receives google token when
signin
is successful and succesfully navigates to next scene
'
,
async
()
=>
{
it
(
'
goes to home if google
sign
in
token already has corresponding user
'
,
async
()
=>
{
LocalStorage
.
setSecretKey
(
"
sssttt
"
);
const
instance
=
ReactTestRenderer
.
create
(
...
...
@@ -271,6 +273,17 @@ it('receives google token when signin is successful and succesfully navigates to
GoogleSignin
.
hasPlayServices
=
mockHasPlayServices
GoogleSignin
.
signIn
=
mockSignin
mockedAxios
.
request
.
mockImplementationOnce
(
()
=>
new
Promise
(
resolve
=>
{
resolve
({
status
:
200
,
data
:
{
token
:
"
mock token
"
}
});
})
);
const
googleSignin
=
instance
.
root
.
findByType
(
GoogleSigninButton
);
act
(()
=>
{
...
...
@@ -279,7 +292,6 @@ it('receives google token when signin is successful and succesfully navigates to
await
expect
(
mockHasPlayServices
).
toBeCalledTimes
(
1
);
await
expect
(
mockSignin
).
toBeCalledTimes
(
1
);
await
expect
(
mockNavigation
).
toBeCalledTimes
(
1
);
});
...
...
@@ -373,4 +385,63 @@ it('receives nothing when has no play service failed and fails to navigate to ne
await
expect
(
mockSignin
).
toBeCalledTimes
(
0
);
await
expect
(
mockNavigation
).
toBeCalledTimes
(
0
);
});
it
(
'
receives google token when signin is successful and succesfully navigates to form
'
,
async
()
=>
{
LocalStorage
.
setSecretKey
(
"
sssttt
"
);
const
instance
=
ReactTestRenderer
.
create
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
NavigationContainer
>
<
Stack
.
Navigator
screenOptions
=
{
{
header
:
()
=>
<></>,
}
}
>
<
Stack
.
Screen
name
=
"login"
component
=
{
LoginPage
}
/>
</
Stack
.
Navigator
>
</
NavigationContainer
>
</
AppContext
.
Provider
>,
);
expect
(
instance
.
toJSON
()).
toMatchSnapshot
();
const
mockHasPlayServices
=
jest
.
fn
().
mockImplementationOnce
(()
=>
new
Promise
(
resolve
=>
{
resolve
(
true
);
}));
const
mockSignin
=
jest
.
fn
().
mockImplementationOnce
(()
=>
new
Promise
(
resolve
=>
{
const
data
=
{
idToken
:
"
1234
"
,
serverAuthCode
:
"
4321
"
,
user
:
{
email
:
"
test@gmail.com
"
,
id
:
"
1234
"
,
givenName
:
"
test
"
,
familyName
:
"
test
"
,
photo
:
"
test.com
"
,
// url
name
:
"
test
"
// full name
}
}
resolve
(
data
);
}));
GoogleSignin
.
hasPlayServices
=
mockHasPlayServices
GoogleSignin
.
signIn
=
mockSignin
mockedAxios
.
request
.
mockImplementationOnce
(
()
=>
new
Promise
(
resolve
=>
{
resolve
({
status
:
203
});
})
);
const
googleSignin
=
instance
.
root
.
findByType
(
GoogleSigninButton
);
act
(()
=>
{
googleSignin
.
props
.
onPress
();
})
await
expect
(
mockHasPlayServices
).
toBeCalledTimes
(
1
);
await
expect
(
mockSignin
).
toBeCalledTimes
(
1
);
});
\ 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