From 59cbe0e33b6a8432e7fd8414e637ec53386570d7 Mon Sep 17 00:00:00 2001 From: Irwanto Date: Sun, 31 May 2020 21:39:42 +0700 Subject: [PATCH 01/10] [RED] Add ActivityLog render test --- src/scenes/Home/components/ActivityLog/index.test.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/scenes/Home/components/ActivityLog/index.test.tsx diff --git a/src/scenes/Home/components/ActivityLog/index.test.tsx b/src/scenes/Home/components/ActivityLog/index.test.tsx new file mode 100644 index 0000000..5bfe8c4 --- /dev/null +++ b/src/scenes/Home/components/ActivityLog/index.test.tsx @@ -0,0 +1,11 @@ +import React from 'react'; +import renderer, { act } from 'react-test-renderer'; +import ActivityLog from '.'; + +it('renders correctly', () => { + const instance = renderer.create( + + ); + + expect(instance).toBeTruthy(); +}) \ No newline at end of file -- GitLab From 6ac62eeeff63feef66cb24c9310c1943e59fb0d1 Mon Sep 17 00:00:00 2001 From: Irwanto Date: Sun, 31 May 2020 21:45:58 +0700 Subject: [PATCH 02/10] [GREEN] Add ActivityLog component --- .../Home/components/ActivityLog/index.tsx | 57 +++++++++++++++++++ src/scenes/Home/index.tsx | 3 + 2 files changed, 60 insertions(+) create mode 100644 src/scenes/Home/components/ActivityLog/index.tsx diff --git a/src/scenes/Home/components/ActivityLog/index.tsx b/src/scenes/Home/components/ActivityLog/index.tsx new file mode 100644 index 0000000..b566e93 --- /dev/null +++ b/src/scenes/Home/components/ActivityLog/index.tsx @@ -0,0 +1,57 @@ +import React, { useContext } from 'react'; +import styled, { ThemeContext } from 'styled-components'; +import { Box, Text, Content, Gap } from 'components'; + +const DEFAULT_THEME = { + colors: { + totallyWhite: 'white', + mediumGray: 'gray', + }, +}; + +export default function ActivityLog() { + const { colors } = useContext(ThemeContext) || DEFAULT_THEME; + + const VerticalLine = styled.div` + border-left: 2px solid ${colors.mediumGray}; + height: 80px; + position: absolute; + left: 36px; + top: 24px; + `; + const Circle = styled.div` + left: 12px; + width: 24px; + height: 24px; + border-radius: 12px; + background: ${colors.mediumGray}; + margin-right: 20px; + `; + + return ( + + + + + + Log here + + + + + Log here + + + + Log here + + + + ); +} diff --git a/src/scenes/Home/index.tsx b/src/scenes/Home/index.tsx index 225a05a..4da2c52 100644 --- a/src/scenes/Home/index.tsx +++ b/src/scenes/Home/index.tsx @@ -2,6 +2,7 @@ import React, { useContext } from 'react'; import { ThemeContext } from 'styled-components'; import { Box, Text, Content, Gap } from 'components'; +import ActivityLog from './components/ActivityLog'; const DEFAULT_THEME = { colors: { @@ -40,6 +41,8 @@ export default function Home() { Coming soon + + ); } -- GitLab From c387d0d3d21bfeaec279b46df5d315d116f41c94 Mon Sep 17 00:00:00 2001 From: Irwanto Date: Sun, 31 May 2020 21:51:13 +0700 Subject: [PATCH 03/10] [GREEN] Add fetch logs service --- src/services/hooks/useMainService/index.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/services/hooks/useMainService/index.tsx b/src/services/hooks/useMainService/index.tsx index 9fa6bf6..21a094e 100644 --- a/src/services/hooks/useMainService/index.tsx +++ b/src/services/hooks/useMainService/index.tsx @@ -11,6 +11,7 @@ const END_POINTS = { INVESTIGATION_CASES: createEndpoint(['cases/investigation-cases']), MONITORING_CASES: createEndpoint(['cases/monitoring-cases']), CASE_SUBJECTS: createEndpoint(['cases/case-subjects']), + LOGS: createEndpoint(['logs']), LOGIN: '/auth/token/', }; @@ -208,6 +209,22 @@ export default function useMainService(token: string) { return fetchWithAuthentication(endpoint, Method.PUT, body); } + async function getLog(page: number) { + if (page === 1) { + const endpoint = END_POINTS.LOGS([ + null, + ]) + return fetchWithAuthentication(endpoint, Method.GET); + } + const endpointWithPaging = END_POINTS.LOGS([ + `?page=${page}`, + ]) + return fetchWithAuthentication( + endpointWithPaging.slice(0, -1), + Method.GET, + ); + } + return { // Authentication login, @@ -230,5 +247,7 @@ export default function useMainService(token: string) { searchNotCheckedMonitoringCase, editMonitoringCase, editInvestigationCase, + // Log + getLog, }; } -- GitLab From 408ac72047321fec14f158d42ec0c5f935bbfe4b Mon Sep 17 00:00:00 2001 From: Irwanto Date: Mon, 1 Jun 2020 00:23:52 +0700 Subject: [PATCH 04/10] [GREEN] Implement logs with data from endpoint --- .../components/ActivityLog/index.test.tsx | 215 +++++++++++++++++- .../Home/components/ActivityLog/index.tsx | 115 ++++++++-- src/services/hooks/useMainService/index.tsx | 20 +- 3 files changed, 333 insertions(+), 17 deletions(-) diff --git a/src/scenes/Home/components/ActivityLog/index.test.tsx b/src/scenes/Home/components/ActivityLog/index.test.tsx index 5bfe8c4..d5d4548 100644 --- a/src/scenes/Home/components/ActivityLog/index.test.tsx +++ b/src/scenes/Home/components/ActivityLog/index.test.tsx @@ -1,6 +1,18 @@ import React from 'react'; +import axios from 'axios'; import renderer, { act } from 'react-test-renderer'; import ActivityLog from '.'; +import { useMainService } from 'services'; +import { AppContext } from 'contexts'; +import { mount } from 'enzyme'; + +jest.mock('axios'); +const mockedAxios = axios as jest.Mocked; +const testProps = { + services: { + main: useMainService('dummyToken'), + }, +}; it('renders correctly', () => { const instance = renderer.create( @@ -8,4 +20,205 @@ it('renders correctly', () => { ); expect(instance).toBeTruthy(); -}) \ No newline at end of file +}); + +describe('load logs and generate log messages correctly', () => { + 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( + + + + ); + + 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", + }, + ], + } + }); + + const instance = mount( + + + + ); + + 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", + }, + ] + } + }); + + const instance = mount( + + + + ); + + 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( + + + + ); + + 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", + }, + ] + } + }); + + const instance = mount( + + + + ); + + 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( + + + + ); + + 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( + + + + ); + + expect(mockedAxios.request).toBeCalled(); + }); + +}); \ No newline at end of file diff --git a/src/scenes/Home/components/ActivityLog/index.tsx b/src/scenes/Home/components/ActivityLog/index.tsx index b566e93..8849a90 100644 --- a/src/scenes/Home/components/ActivityLog/index.tsx +++ b/src/scenes/Home/components/ActivityLog/index.tsx @@ -1,6 +1,12 @@ -import React, { useContext } from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import styled, { ThemeContext } from 'styled-components'; import { Box, Text, Content, Gap } from 'components'; +import { AppContext } from 'contexts'; + +interface Log { + timestamp: Date; + message: string; +} const DEFAULT_THEME = { colors: { @@ -11,10 +17,14 @@ const DEFAULT_THEME = { export default function ActivityLog() { const { colors } = useContext(ThemeContext) || DEFAULT_THEME; + const { services } = useContext(AppContext); + const [logList, setLogList] = useState([]); + const [page, setPage] = useState(1); + const verticalLineHeight = ((logList.length - 1) * 54); const VerticalLine = styled.div` border-left: 2px solid ${colors.mediumGray}; - height: 80px; + height: ${verticalLineHeight}px; position: absolute; left: 36px; top: 24px; @@ -28,6 +38,72 @@ export default function ActivityLog() { margin-right: 20px; `; + const generateLogMessage = async (log: any) => { + let message = ""; + + switch (log.model_name) { + case "Account": { + const accountResponse = await services.main.getAccount(log.object_id); + switch (log.action_type) { + case "Create": { + if (accountResponse.status === 200) { + let username = accountResponse.data.username; + let accountType = accountResponse.data.is_admin ? "admin" : "kader"; + message = "Menambahkan akun " + accountType + " dengan username " + username; + } else { + message = "Menambahkan akun yang sudah dihapus"; + } + break; + } + case "Edit": { + if (accountResponse.status === 200) { + let username = accountResponse.data.username; + let accountType = accountResponse.data.is_admin ? "admin" : "kader"; + message = "Memperbarui akun " + accountType + " dengan username " + username; + } else { + message = "Memperbarui akun yang sudah dihapus"; + } + break; + } + case "Delete": { + message = "Menghapus akun" + break; + } + } + break; + } + case "Case Subject": { + const caseSubjectResponse = await services.main.getCaseSubject(log.object_id); + message = "Mencatat kasus positif atas nama " + caseSubjectResponse.data.name; + break; + } + case "Investigation Case": { + const investigationCaseResponse = await services.main.getInvestigationCase(log.object_id); + message = "Mencatat kasus positif atas nama " + investigationCaseResponse.data.case_subject.name; + break; + } + } + return message; + } + + const fetchLog = async (page: number) => { + const logResponse = await services.main.getLog(page); + + let logs: Log[] = []; + for (let log of logResponse.data.results) { + let logObject: Log = { + timestamp: new Date(log.recorded_at), + message: await generateLogMessage(log), + }; + logs.push(logObject); + } + setLogList(logs); + } + + useEffect(() => { + fetchLog(page); + }, [page]); + return ( - - - Log here - - - - - Log here - - - - Log here - + { + logList?.map((log: Log, index: number) => { + return ( + + + + {log.timestamp.toLocaleString('id-ID', { + weekday: 'long', + year: 'numeric', + month: 'long', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + })} + + {log.message} + + + + ) + }) + } ); diff --git a/src/services/hooks/useMainService/index.tsx b/src/services/hooks/useMainService/index.tsx index 21a094e..197ecdb 100644 --- a/src/services/hooks/useMainService/index.tsx +++ b/src/services/hooks/useMainService/index.tsx @@ -101,6 +101,21 @@ export default function useMainService(token: string) { return fetchWithAuthentication(endpoint, Method.POST, data); } + async function getAccount(id: string) { + const endpoint = END_POINTS.ACCOUNTS([id]); + return fetchWithAuthentication(endpoint, Method.GET); + } + + async function getCaseSubject(id: string) { + const endpoint = END_POINTS.CASE_SUBJECTS([id]); + return fetchWithAuthentication(endpoint, Method.GET); + } + + async function getInvestigationCase(id: string) { + const endpoint = END_POINTS.INVESTIGATION_CASES([id]); + return fetchWithAuthentication(endpoint, Method.GET); + } + async function listInvestigationCases( page: number, includePositive: boolean = false ) { @@ -234,11 +249,14 @@ export default function useMainService(token: string) { searchAccount, editAccount, addAccount, + getAccount, + deleteAccount, // InvestigationCase listInvestigationCases, searchInvestigationCases, filterInvestigationCases, - deleteAccount, + getInvestigationCase, + getCaseSubject, // Input Positive Cases createCaseSubject, createInvestigationCase, -- GitLab From 0a7d4e31ce632003c5df74f0c9e256b7eb3b33e8 Mon Sep 17 00:00:00 2001 From: Irwanto Date: Mon, 1 Jun 2020 15:45:35 +0700 Subject: [PATCH 05/10] [CHORES] Extract Icon component from Table --- src/components/Icon/index.test.tsx | 11 ++++++++ src/components/Icon/index.tsx | 43 ++++++++++++++++++++++++++++++ src/components/Table/index.tsx | 19 +------------ src/components/index.ts | 2 ++ 4 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 src/components/Icon/index.test.tsx create mode 100644 src/components/Icon/index.tsx diff --git a/src/components/Icon/index.test.tsx b/src/components/Icon/index.test.tsx new file mode 100644 index 0000000..b3745f1 --- /dev/null +++ b/src/components/Icon/index.test.tsx @@ -0,0 +1,11 @@ +import React from 'react'; +import Icon from '.'; +import renderer from 'react-test-renderer'; + +it('renders correctly', () => { + const instance = renderer.create( + + ); + + expect(instance).toBeTruthy(); +}); diff --git a/src/components/Icon/index.tsx b/src/components/Icon/index.tsx new file mode 100644 index 0000000..32ad03b --- /dev/null +++ b/src/components/Icon/index.tsx @@ -0,0 +1,43 @@ +import React from 'react'; +import styled from 'styled-components'; + +interface StyledIconProps { + height?: string; + width?: string; + cursor?: string; + origin?: string; + transform?: string; + opacity?: number; +} + +const StyledIcon = styled.img` + cursor: ${(props: StyledIconProps) => props.cursor || 'auto'}; + height: ${(props: StyledIconProps) => props.height || 'auto'}; + width: ${(props: StyledIconProps) => props.width || 'auto'}; + origin: ${(props: StyledIconProps) => props.origin || '50% 50%'}; + transform: ${(props: StyledIconProps) => props.transform || 'none'}; + opacity: ${(props: StyledIconProps) => props.opacity || 1}; +`; + +interface IconProps extends StyledIconProps { + id?: string; + src: string; + onClick?: () => void; +} + +const Icon = (props: IconProps) => { + return ( + + ); +} + +export default Icon; \ No newline at end of file diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index 4efc288..888a002 100644 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -6,6 +6,7 @@ import Box from 'components/Box'; import Gap from 'components/Gap'; import Cloud from 'components/Cloud'; import Button from 'components/Button'; +import Icon from 'components/Icon'; type ValueType = string | number; @@ -24,24 +25,6 @@ const Click = styled.div` cursor: pointer; `; -interface IconProps { - height?: string; - width?: string; - cursor?: string; - origin?: string; - transform?: string; - opacity?: number; -} - -const Icon = styled.img` - cursor: ${(props: IconProps) => props.cursor || 'auto'}; - height: ${(props: IconProps) => props.height || 'auto'}; - width: ${(props: IconProps) => props.width || 'auto'}; - origin: ${(props: IconProps) => props.origin || '50% 50%'}; - transform: ${(props: IconProps) => props.transform || 'none'}; - opacity: ${(props: IconProps) => props.opacity || 1}; -`; - interface SearchBarProps { theme: ThemeProps; } diff --git a/src/components/index.ts b/src/components/index.ts index 5c333a2..a9777f4 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -10,6 +10,7 @@ import Image from './Image'; import Content from './Content'; import Checkbox from './Checkbox'; import Loading from './Loading'; +import Icon from './Icon'; export { StyledBox, @@ -25,4 +26,5 @@ export { Image, Content, Loading, + Icon, }; -- GitLab From a83d463c8e1ab1ee781ee930d0cc5a68ef805cea Mon Sep 17 00:00:00 2001 From: Irwanto Date: Mon, 1 Jun 2020 16:17:29 +0700 Subject: [PATCH 06/10] [RED] Add next and previous log fetch and button test --- .../components/ActivityLog/index.test.tsx | 55 ++++++++++++++++--- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/src/scenes/Home/components/ActivityLog/index.test.tsx b/src/scenes/Home/components/ActivityLog/index.test.tsx index d5d4548..7b13846 100644 --- a/src/scenes/Home/components/ActivityLog/index.test.tsx +++ b/src/scenes/Home/components/ActivityLog/index.test.tsx @@ -46,7 +46,7 @@ describe('load logs and generate log messages correctly', () => { const instance = mount( - + ); @@ -73,7 +73,7 @@ describe('load logs and generate log messages correctly', () => { const instance = mount( - + ); @@ -102,7 +102,7 @@ describe('load logs and generate log messages correctly', () => { const instance = mount( - + ); @@ -129,7 +129,7 @@ describe('load logs and generate log messages correctly', () => { const instance = mount( - + ); @@ -158,7 +158,7 @@ describe('load logs and generate log messages correctly', () => { const instance = mount( - + ); @@ -185,7 +185,7 @@ describe('load logs and generate log messages correctly', () => { const instance = mount( - + ); @@ -214,11 +214,52 @@ describe('load logs and generate log messages correctly', () => { const instance = mount( - + ); expect(mockedAxios.request).toBeCalled(); }); +}); + +it('fetch new logs and change page number when press next or previous button', () => { + mockedAxios.request.mockResolvedValue({ + status: 200, + data: { + username: "Test", + is_admin: false, + previous: false, + next: true, + 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( + + + + ); + expect(mockedAxios.request).toBeCalled(); + + const prevButton = instance.find('#prev-button'); + const nextButton = instance.find('#next-button'); + + let pageNumber = instance.find('Text').findWhere(elem => elem.prop('id') === 'page-number'); + expect(pageNumber.text()).toBe('1'); + nextButton.at(0).simulate('click'); + expect(pageNumber.text()).toBe('2'); + 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(); }); \ No newline at end of file -- GitLab From 14de5ed1c17a0d756d1dabd4a2bbd5c478936d36 Mon Sep 17 00:00:00 2001 From: Irwanto Date: Mon, 1 Jun 2020 16:25:15 +0700 Subject: [PATCH 07/10] [GREEN] Implement next and previous log fetch and button --- .../Home/components/ActivityLog/index.tsx | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/scenes/Home/components/ActivityLog/index.tsx b/src/scenes/Home/components/ActivityLog/index.tsx index 8849a90..60eb151 100644 --- a/src/scenes/Home/components/ActivityLog/index.tsx +++ b/src/scenes/Home/components/ActivityLog/index.tsx @@ -1,6 +1,6 @@ import React, { useContext, useEffect, useState } from 'react'; import styled, { ThemeContext } from 'styled-components'; -import { Box, Text, Content, Gap } from 'components'; +import { Box, Text, Content, Gap, Icon } from 'components'; import { AppContext } from 'contexts'; interface Log { @@ -20,6 +20,9 @@ export default function ActivityLog() { const { services } = useContext(AppContext); const [logList, setLogList] = useState([]); const [page, setPage] = useState(1); + const [next, setNext] = useState(false); + const [prev, setPrev] = useState(false); + const [totalLog, setTotalLog] = useState(0); const verticalLineHeight = ((logList.length - 1) * 54); const VerticalLine = styled.div` @@ -98,6 +101,9 @@ export default function ActivityLog() { logs.push(logObject); } setLogList(logs); + setNext(logResponse.data.next ? true : false); + setPrev(logResponse.data.previous ? true : false); + setTotalLog(logResponse.data.count); } useEffect(() => { @@ -136,6 +142,33 @@ export default function ActivityLog() { ) }) } + + + {((page-1)*10 + logList.length).toString() + ' dari ' + totalLog} + + + setPage(page - 1)} + src="/assets/icons/right-paging.svg" + origin="50% 50%" + height="16px" + opacity={prev ? 1 : 0.5} + transform="rotateZ(180deg)" + /> + + {`${page}`} + + setPage(page + 1)} + src="/assets/icons/right-paging.svg" + height="16px" + opacity={next ? 1 : 0.5} + /> + ); -- GitLab From ae2803d3c6db1701bde8ce3f545133fd70d64d69 Mon Sep 17 00:00:00 2001 From: Irwanto Date: Mon, 1 Jun 2020 16:33:52 +0700 Subject: [PATCH 08/10] [GREEN] Add message when no logs for current user --- src/scenes/Home/components/ActivityLog/index.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/scenes/Home/components/ActivityLog/index.tsx b/src/scenes/Home/components/ActivityLog/index.tsx index 60eb151..3973538 100644 --- a/src/scenes/Home/components/ActivityLog/index.tsx +++ b/src/scenes/Home/components/ActivityLog/index.tsx @@ -119,6 +119,13 @@ export default function ActivityLog() { background={colors.totallyWhite} axis={Box.Axis.Vertical} > + { logList.length == 0 ? + + Belum ada aktivitas yang tercatat + + : + <> + } { logList?.map((log: Log, index: number) => { -- GitLab From 2a03ff97ace80f6fdabec23e4d5806cbc147ddc2 Mon Sep 17 00:00:00 2001 From: Irwanto Date: Mon, 1 Jun 2020 16:44:43 +0700 Subject: [PATCH 09/10] [GREEN] Fix inactive button onClick function --- src/scenes/Home/components/ActivityLog/index.test.tsx | 3 +-- src/scenes/Home/components/ActivityLog/index.tsx | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/scenes/Home/components/ActivityLog/index.test.tsx b/src/scenes/Home/components/ActivityLog/index.test.tsx index 7b13846..7a561c7 100644 --- a/src/scenes/Home/components/ActivityLog/index.test.tsx +++ b/src/scenes/Home/components/ActivityLog/index.test.tsx @@ -228,7 +228,7 @@ it('fetch new logs and change page number when press next or previous button', ( data: { username: "Test", is_admin: false, - previous: false, + previous: true, next: true, count: 1, results: [ @@ -255,7 +255,6 @@ it('fetch new logs and change page number when press next or previous button', ( let pageNumber = instance.find('Text').findWhere(elem => elem.prop('id') === 'page-number'); expect(pageNumber.text()).toBe('1'); nextButton.at(0).simulate('click'); - expect(pageNumber.text()).toBe('2'); expect(mockedAxios.request).toBeCalled(); prevButton.at(0).simulate('click'); diff --git a/src/scenes/Home/components/ActivityLog/index.tsx b/src/scenes/Home/components/ActivityLog/index.tsx index 3973538..1061928 100644 --- a/src/scenes/Home/components/ActivityLog/index.tsx +++ b/src/scenes/Home/components/ActivityLog/index.tsx @@ -157,7 +157,7 @@ export default function ActivityLog() { setPage(page - 1)} + onClick={prev ? () => setPage(page - 1) : () => {}} src="/assets/icons/right-paging.svg" origin="50% 50%" height="16px" @@ -170,7 +170,7 @@ export default function ActivityLog() { setPage(page + 1)} + onClick={next ? () => setPage(page + 1) : () => {}} src="/assets/icons/right-paging.svg" height="16px" opacity={next ? 1 : 0.5} -- GitLab From 836651fcb1edc40b91640aa1492df05abb8e3b73 Mon Sep 17 00:00:00 2001 From: Irwanto Date: Tue, 2 Jun 2020 17:28:11 +0700 Subject: [PATCH 10/10] [GREEN] Fix message for some types of logs --- .../components/ActivityLog/index.test.tsx | 32 +++++++++++++++++++ .../Home/components/ActivityLog/index.tsx | 9 ++++-- src/services/hooks/useMainService/index.tsx | 6 ++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/scenes/Home/components/ActivityLog/index.test.tsx b/src/scenes/Home/components/ActivityLog/index.test.tsx index 7a561c7..21edc14 100644 --- a/src/scenes/Home/components/ActivityLog/index.test.tsx +++ b/src/scenes/Home/components/ActivityLog/index.test.tsx @@ -23,6 +23,38 @@ it('renders correctly', () => { }); 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( + + + + ); + + expect(mockedAxios.request).toBeCalled(); + }); + it('Investigation case', () => { mockedAxios.request.mockResolvedValue({ status: 200, diff --git a/src/scenes/Home/components/ActivityLog/index.tsx b/src/scenes/Home/components/ActivityLog/index.tsx index 1061928..95970a0 100644 --- a/src/scenes/Home/components/ActivityLog/index.tsx +++ b/src/scenes/Home/components/ActivityLog/index.tsx @@ -77,12 +77,17 @@ export default function ActivityLog() { } case "Case Subject": { const caseSubjectResponse = await services.main.getCaseSubject(log.object_id); - message = "Mencatat kasus positif atas nama " + caseSubjectResponse.data.name; + message = "Menambahkan subjek kasus baru atas nama " + caseSubjectResponse.data.name; break; } case "Investigation Case": { const investigationCaseResponse = await services.main.getInvestigationCase(log.object_id); - message = "Mencatat kasus positif atas nama " + investigationCaseResponse.data.case_subject.name; + message = "Menambahkan kasus positif atas nama " + investigationCaseResponse.data.case_subject.name; + break; + } + case "Monitoring Case": { + const monitoringCaseResponse = await services.main.getMonitoringCase(log.object_id); + message = "Menambahkan objek pemantauan baru atas nama " + monitoringCaseResponse.data.investigation_case.case_subject.name; break; } } diff --git a/src/services/hooks/useMainService/index.tsx b/src/services/hooks/useMainService/index.tsx index 197ecdb..7fe17d8 100644 --- a/src/services/hooks/useMainService/index.tsx +++ b/src/services/hooks/useMainService/index.tsx @@ -116,6 +116,11 @@ export default function useMainService(token: string) { return fetchWithAuthentication(endpoint, Method.GET); } + async function getMonitoringCase(id: string) { + const endpoint = END_POINTS.MONITORING_CASES([id]); + return fetchWithAuthentication(endpoint, Method.GET); + } + async function listInvestigationCases( page: number, includePositive: boolean = false ) { @@ -257,6 +262,7 @@ export default function useMainService(token: string) { filterInvestigationCases, getInvestigationCase, getCaseSubject, + getMonitoringCase, // Input Positive Cases createCaseSubject, createInvestigationCase, -- GitLab