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
f074b35c
Commit
f074b35c
authored
Jun 06, 2021
by
Sean Zeliq Urian
Browse files
[RED] implement test for indexing item
parent
90b71a87
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/scenes/ActivityLog/components/ActivityTabel/index.test.tsx
View file @
f074b35c
...
...
@@ -7,314 +7,318 @@ import { AppContext } from 'contexts';
import
{
mount
}
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
:
"
12345
"
,
recorded_at
:
"
2020-05-31T23:03:35.854615+07:00
"
,
},
]
}
}
status
:
200
,
data
:
{
username
:
'
Test
'
,
is_admin
:
false
,
previous
:
true
,
next
:
true
,
count
:
1
,
results
:
[
{
action_type
:
'
Delete
'
,
model_name
:
'
Account
'
,
object_id
:
'
12345
'
,
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
'
),
},
services
:
{
main
:
useMainService
(
'
dummyToken
'
),
},
};
it
(
'
ActivityTabel renders correctly
'
,
()
=>
{
const
instance
=
renderer
.
create
(
<
ActivityTabel
/>
);
const
instance
=
renderer
.
create
(<
ActivityTabel
/>);
expect
(
instance
).
toBeTruthy
();
expect
(
instance
).
toBeTruthy
();
});
describe
(
'
load logs and generate log messages correctly
'
,
()
=>
{
it
(
'
Monitoring case
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
200
,
data
:
{
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
"
Create
"
,
model_name
:
"
Monitoring Case
"
,
object_id
:
"
1234
"
,
recorded_at
:
"
2020-05-31T23:03:35.854615+07:00
"
,
},
],
investigation_case
:
{
case_subject
:
{
name
:
"
Test
"
}
}
}
});
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
it
(
'
Monitoring case
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
200
,
data
:
{
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
'
Create
'
,
model_name
:
'
Monitoring Case
'
,
object_id
:
'
1234
'
,
recorded_at
:
'
2020-05-31T23:03:35.854615+07:00
'
,
},
],
investigation_case
:
{
case_subject
:
{
name
:
'
Test
'
,
},
},
},
});
it
(
'
Investigation case
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
200
,
data
:
{
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
"
Create
"
,
model_name
:
"
Investigation Case
"
,
object_id
:
"
1234
"
,
recorded_at
:
"
2020-05-31T23:03:35.854615+07:00
"
,
},
],
case_subject
:
{
name
:
"
Test
"
}
}
});
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
});
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
it
(
'
Case subject
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
200
,
data
:
{
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
"
Create
"
,
model_name
:
"
Case Subject
"
,
object_id
:
"
1234
"
,
recorded_at
:
"
2020-05-31T23:03:35.854615+07:00
"
,
},
],
}
});
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
expect
(
mockedAxios
.
request
).
toBeCalled
();
});
it
(
'
Investigation case
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
200
,
data
:
{
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
'
Create
'
,
model_name
:
'
Investigation Case
'
,
object_id
:
'
1234
'
,
recorded_at
:
'
2020-05-31T23:03:35.854615+07:00
'
,
},
],
case_subject
:
{
name
:
'
Test
'
,
},
},
});
it
(
'
Create account
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
200
,
data
:
{
username
:
"
Test
"
,
is_admin
:
false
,
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
"
Create
"
,
model_name
:
"
Account
"
,
object_id
:
"
1234
"
,
recorded_at
:
"
2020-05-31T23:03:35.854615+07:00
"
,
},
]
}
});
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
});
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
it
(
'
Create account, but account deleted
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
200
,
data
:
{
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
"
Create
"
,
model_name
:
"
Account
"
,
object_id
:
"
1234
"
,
recorded_at
:
"
2020-05-31T23:03:35.854615+07:00
"
,
},
]
}
});
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
expect
(
mockedAxios
.
request
).
toBeCalled
();
});
it
(
'
Case subject
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
200
,
data
:
{
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
'
Create
'
,
model_name
:
'
Case Subject
'
,
object_id
:
'
1234
'
,
recorded_at
:
'
2020-05-31T23:03:35.854615+07:00
'
,
},
],
},
});
it
(
'
Edit account
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
200
,
data
:
{
username
:
"
Test
"
,
is_admin
:
false
,
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
"
Edit
"
,
model_name
:
"
Account
"
,
object_id
:
"
1234
"
,
recorded_at
:
"
2020-05-31T23:03:35.854615+07:00
"
,
},
]
}
});
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
});
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
it
(
'
Edit account, but account deleted
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
404
,
data
:
{
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
"
Edit
"
,
model_name
:
"
Account
"
,
object_id
:
"
1234
"
,
recorded_at
:
"
2020-05-31T23:03:35.854615+07:00
"
,
},
]
}
});
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
});
expect
(
mockedAxios
.
request
).
toBeCalled
();
});
it
(
'
Delete account
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
200
,
data
:
{
username
:
"
Test
"
,
is_admin
:
false
,
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
"
Delete
"
,
model_name
:
"
Account
"
,
object_id
:
"
1234
"
,
recorded_at
:
"
2020-05-31T23:03:35.854615+07:00
"
,
},
]
}
});
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
it
(
'
Create account
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
200
,
data
:
{
username
:
'
Test
'
,
is_admin
:
false
,
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
'
Create
'
,
model_name
:
'
Account
'
,
object_id
:
'
1234
'
,
recorded_at
:
'
2020-05-31T23:03:35.854615+07:00
'
,
},
],
},
});
});
it
(
'
fetch new logs and change page number when press next or previous button
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
(
dummyLog
);
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
});
it
(
'
Create account, but account deleted
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
200
,
data
:
{
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
'
Create
'
,
model_name
:
'
Account
'
,
object_id
:
'
1234
'
,
recorded_at
:
'
2020-05-31T23:03:35.854615+07:00
'
,
},
],
},
});
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
});
it
(
'
Edit account
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
200
,
data
:
{
username
:
'
Test
'
,
is_admin
:
false
,
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
'
Edit
'
,
model_name
:
'
Account
'
,
object_id
:
'
1234
'
,
recorded_at
:
'
2020-05-31T23:03:35.854615+07:00
'
,
},
],
},
});
let
nextButton
=
instance
.
find
(
'
[data-test-id="next-button"]
'
);
let
prevButton
=
instance
.
find
(
'
[data-test-id="prev-button"]
'
);
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
let
pageNumber
=
instance
.
find
(
'
Text
'
).
findWhere
(
elem
=>
elem
.
prop
(
'
id
'
)
===
'
page-number
'
);
expect
(
pageNumber
.
text
()).
toBe
(
'
1
'
);
nextButton
.
at
(
0
).
simulate
(
'
click
'
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
});
it
(
'
Edit account, but account deleted
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
404
,
data
:
{
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
'
Edit
'
,
model_name
:
'
Account
'
,
object_id
:
'
1234
'
,
recorded_at
:
'
2020-05-31T23:03:35.854615+07:00
'
,
},
],
},
});
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
prevButton
.
at
(
0
).
simulate
(
'
click
'
);
pageNumber
=
instance
.
find
(
'
Text
'
).
findWhere
(
elem
=>
elem
.
prop
(
'
id
'
)
===
'
page-number
'
);
expect
(
pageNumber
.
text
()).
toBe
(
'
1
'
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
})
})
;
it
(
'
Sort and filter are displayed and clickable
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
(
dummyLog
);
it
(
'
Delete account
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
({
status
:
200
,
data
:
{
username
:
'
Test
'
,
is_admin
:
false
,
previous
:
null
,
next
:
null
,
count
:
1
,
results
:
[
{
action_type
:
'
Delete
'
,
model_name
:
'
Account
'
,
object_id
:
'
1234
'
,
recorded_at
:
'
2020-05-31T23:03:35.854615+07:00
'
,
},
],
},
});
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
let
sortByDate
=
instance
.
find
(
"
#sortbydate
"
);
let
sortByObj
=
instance
.
find
(
"
#sortbyobj
"
);
let
filter
=
instance
.
find
(
"
#filter
"
);
expect
(
mockedAxios
.
request
).
toBeCalled
(
);
}
);
}
);
sortByDate
.
simulate
(
"
click
"
);
sortByObj
.
simulate
(
"
click
"
);
filter
.
simulate
(
"
click
"
);
it
(
'
fetch new logs and change page number when press next or previous button
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
(
dummyLog
);
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
let
nextButton
=
instance
.
find
(
'
[data-test-id="next-button"]
'
);
let
prevButton
=
instance
.
find
(
'
[data-test-id="prev-button"]
'
);
let
pageNumber
=
instance
.
find
(
'
Text
'
)
.
findWhere
((
elem
)
=>
elem
.
prop
(
'
id
'
)
===
'
page-number
'
);
expect
(
pageNumber
.
text
()).
toBe
(
'
1
'
);
nextButton
.
at
(
0
).
simulate
(
'
click
'
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
prevButton
.
at
(
0
).
simulate
(
'
click
'
);
pageNumber
=
instance
.
find
(
'
Text
'
)
.
findWhere
((
elem
)
=>
elem
.
prop
(
'
id
'
)
===
'
page-number
'
);
expect
(
pageNumber
.
text
()).
toBe
(
'
1
'
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
});
let
table
=
instance
.
find
(
"
Table
"
);
expect
(
table
).
toBeTruthy
();
});
\ No newline at end of file
it
(
'
Sort and filter are displayed and clickable
'
,
()
=>
{
mockedAxios
.
request
.
mockResolvedValue
(
dummyLog
);
const
instance
=
mount
(
<
AppContext
.
Provider
value
=
{
testProps
}
>
<
ActivityTabel
/>
</
AppContext
.
Provider
>
);
expect
(
mockedAxios
.
request
).
toBeCalled
();
let
sortByIndex
=
instance
.
find
(
'
#sortbyindex
'
);
let
sortByDate
=
instance
.
find
(
'
#sortbydate
'
);
let
sortByObj
=
instance
.
find
(
'
#sortbyobj
'
);
let
filter
=
instance
.
find
(
'
#filter
'
);