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-web
Commits
4f363f59
Commit
4f363f59
authored
May 30, 2021
by
Sean Zeliq Urian
Browse files
[RED] implement test for ActivityLog scene
parent
9a755a4a
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/scenes/ActivityLog/index.test.tsx
0 → 100644
View file @
4f363f59
import
React
from
'
react
'
;
import
axios
from
'
axios
'
;
import
renderer
from
'
react-test-renderer
'
;
import
ActivityLog
from
'
.
'
;
import
{
useMainService
}
from
'
services
'
;
import
{
AppContext
}
from
'
contexts
'
;
import
{
mount
,
shallow
}
from
'
enzyme
'
;
const
dummyLog
=
{
status
:
200
,
data
:
{
username
:
"
Test
"
,
is_admin
:
false
,
previous
:
true
,
next
:
true
,
count
:
1
,
results
:
[
{
action_type
:
"
Delete
"
,
model_name
:
"
Account
"
,
object_id
:
"
1234
"
,
recorded_at
:
"
2020-05-31T23:03:35.854615+07:00
"
,
},
]
}
}
jest
.
mock
(
'
axios
'
);
const
mockedAxios
=
axios
as
jest
.
Mocked
<
typeof
axios
>
;
const
testProps
=
{
services
:
{
main
:
useMainService
(
'
dummyToken
'
),
},
};
it
(
'
render ActivityLog component without crashing
'
,
()
=>
{
shallow
(<
ActivityLog
/>);
});
it
(
'
renders correctly
'
,
()
=>
{
const
instance
=
renderer
.
create
(
<
ActivityLog
/>
);
expect
(
instance
).
toBeTruthy
();
});
it
(
'
CategoryButton are displayed and clickable
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
(
dummyLog
);
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityLog
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
let
categoryButton
=
instance
.
find
(
'
[data-test-id="button-List"]
'
);
categoryButton
.
at
(
0
).
simulate
(
'
click
'
);
expect
(
categoryButton
.
length
).
toBeGreaterThan
(
0
)
categoryButton
=
instance
.
find
(
'
[data-test-id="button-Tabel"]
'
);
categoryButton
.
at
(
0
).
simulate
(
'
click
'
);
expect
(
categoryButton
.
length
).
toBeGreaterThan
(
0
)
});
it
(
'
ActivityList is displayed when List CategoryButton clicked
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
(
dummyLog
);
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityLog
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
let
categoryButton
=
instance
.
find
(
'
[data-test-id="button-List"]
'
);
categoryButton
.
at
(
0
).
simulate
(
'
click
'
);
let
list
=
instance
.
find
(
"
#list-activity
"
);
expect
(
list
).
toBeTruthy
();
});
it
(
'
ActivityTabel is not displayed when List CategoryButton clicked
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
(
dummyLog
);
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityLog
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
let
categoryButton
=
instance
.
find
(
'
[data-test-id="button-List"]
'
);
categoryButton
.
at
(
0
).
simulate
(
'
click
'
);
let
tabel
=
instance
.
find
(
"
#list-activity
"
);
expect
(
tabel
).
toEqual
({});
});
it
(
'
ActivityTabel is displayed when Tabel CategoryButton clicked
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
(
dummyLog
);
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityLog
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
let
categoryButton
=
instance
.
find
(
'
[data-test-id="button-Tabel"]
'
);
categoryButton
.
at
(
0
).
simulate
(
'
click
'
);
let
list
=
instance
.
find
(
"
Tabel
"
);
expect
(
list
).
toBeTruthy
();
});
it
(
'
ActivityList is not displayed when Tabel CategoryButton clicked
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
(
dummyLog
);
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityLog
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
let
categoryButton
=
instance
.
find
(
'
[data-test-id="button-Tabel"]
'
);
categoryButton
.
at
(
0
).
simulate
(
'
click
'
);
let
list
=
instance
.
find
(
"
#list-activity
"
);
expect
(
list
).
toEqual
({});
});
\ 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