From f6eddfb5e7c71dc512f126ba283b4f4b1b5748e7 Mon Sep 17 00:00:00 2001 From: Irwanto Date: Sun, 5 Apr 2020 21:34:04 +0700 Subject: [PATCH 01/89] [RED] Add Base Monitoring Form render test --- .../BaseMonitoringForm/index.test.tsx | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/components/BaseMonitoringForm/index.test.tsx diff --git a/src/components/BaseMonitoringForm/index.test.tsx b/src/components/BaseMonitoringForm/index.test.tsx new file mode 100644 index 0000000..3ea8617 --- /dev/null +++ b/src/components/BaseMonitoringForm/index.test.tsx @@ -0,0 +1,31 @@ +import 'react-native'; +import React from 'react'; +import {NavigationContainer} from '@react-navigation/native'; +import {createStackNavigator} from '@react-navigation/stack'; +import BaseMonitoringForm from '.'; + +import renderer from 'react-test-renderer'; + +const Stack = createStackNavigator(); + +it('renders correctly', () => { + const defaultPage = renderer + .create( + + <>, + }}> + + + } + /> + + + ) + .toJSON(); + + expect(defaultPage).toMatchSnapshot(); +}); \ No newline at end of file -- GitLab From b2bd520404cd940f2e079c67add9775a13101653 Mon Sep 17 00:00:00 2001 From: Irwanto Date: Sun, 5 Apr 2020 21:40:32 +0700 Subject: [PATCH 02/89] [GREEN] Implement base monitoring form --- .../__snapshots__/index.test.tsx.snap | 371 ++++++++++++++++++ src/components/BaseMonitoringForm/index.tsx | 24 ++ .../__snapshots__/index.test.tsx.snap | 1 + 3 files changed, 396 insertions(+) create mode 100644 src/components/BaseMonitoringForm/__snapshots__/index.test.tsx.snap create mode 100644 src/components/BaseMonitoringForm/index.tsx diff --git a/src/components/BaseMonitoringForm/__snapshots__/index.test.tsx.snap b/src/components/BaseMonitoringForm/__snapshots__/index.test.tsx.snap new file mode 100644 index 0000000..efb79e4 --- /dev/null +++ b/src/components/BaseMonitoringForm/__snapshots__/index.test.tsx.snap @@ -0,0 +1,371 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders correctly 1`] = ` + + + + + + + + + + + + + + + + + + + + + Beranda + + + + + + This is header + + + + + + + + + + + + + + + + + + + + + + + + +`; diff --git a/src/components/BaseMonitoringForm/index.tsx b/src/components/BaseMonitoringForm/index.tsx new file mode 100644 index 0000000..dba082a --- /dev/null +++ b/src/components/BaseMonitoringForm/index.tsx @@ -0,0 +1,24 @@ +import React from 'react'; +import styled from 'styled-components/native'; +import Header from 'components/Header'; + +interface BaseMonitoringFormProps { + header: string; +} + +const ScrollView = styled.ScrollView` + background: #ffffff; +`; + +const BaseMonitoringForm = (props: BaseMonitoringFormProps) => { + return ( + +
+ + ); +} + +export default BaseMonitoringForm; \ No newline at end of file diff --git a/src/scenes/OfficerSignupForm/__snapshots__/index.test.tsx.snap b/src/scenes/OfficerSignupForm/__snapshots__/index.test.tsx.snap index 6905ad4..af290dd 100644 --- a/src/scenes/OfficerSignupForm/__snapshots__/index.test.tsx.snap +++ b/src/scenes/OfficerSignupForm/__snapshots__/index.test.tsx.snap @@ -375,6 +375,7 @@ exports[`renders correctly 1`] = ` -- GitLab From cb17a1f11390721620394ba16c726a121e61d92e Mon Sep 17 00:00:00 2001 From: Irwanto Date: Sun, 5 Apr 2020 22:44:37 +0700 Subject: [PATCH 03/89] [RED] Add monitoring status test --- .../MonitoringStatus/index.test.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/components/MonitoringStatus/index.test.tsx diff --git a/src/components/MonitoringStatus/index.test.tsx b/src/components/MonitoringStatus/index.test.tsx new file mode 100644 index 0000000..a242737 --- /dev/null +++ b/src/components/MonitoringStatus/index.test.tsx @@ -0,0 +1,19 @@ +import 'react-native'; +import React from 'react'; +import MonitoringStatus from '.'; + +import renderer from 'react-test-renderer'; + +it('renders correctly', () => { + const status = renderer.create( + + ).toJSON(); + + expect(status).toMatchSnapshot(); +}); -- GitLab From 126a68f6c65623867cd1b1830004efec26b6a6b4 Mon Sep 17 00:00:00 2001 From: Irwanto Date: Sun, 5 Apr 2020 22:54:02 +0700 Subject: [PATCH 04/89] [RED] Add monitoring status in monitoring form test --- src/components/BaseMonitoringForm/index.test.tsx | 9 ++++++++- src/components/MonitoringStatus/index.test.tsx | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/BaseMonitoringForm/index.test.tsx b/src/components/BaseMonitoringForm/index.test.tsx index 3ea8617..ed09874 100644 --- a/src/components/BaseMonitoringForm/index.test.tsx +++ b/src/components/BaseMonitoringForm/index.test.tsx @@ -19,7 +19,14 @@ it('renders correctly', () => { - + } /> diff --git a/src/components/MonitoringStatus/index.test.tsx b/src/components/MonitoringStatus/index.test.tsx index a242737..656953f 100644 --- a/src/components/MonitoringStatus/index.test.tsx +++ b/src/components/MonitoringStatus/index.test.tsx @@ -9,7 +9,7 @@ it('renders correctly', () => { -- GitLab From e39b87188b0ec099562defac2287839c3b0536ab Mon Sep 17 00:00:00 2001 From: Irwanto Date: Sun, 5 Apr 2020 23:00:26 +0700 Subject: [PATCH 05/89] [GREEN] Implement monitoring status --- .../__snapshots__/index.test.tsx.snap | 135 ++++++++++++++++++ src/components/BaseMonitoringForm/index.tsx | 28 +++- .../__snapshots__/index.test.tsx.snap | 125 ++++++++++++++++ src/components/MonitoringStatus/index.tsx | 44 ++++++ 4 files changed, 329 insertions(+), 3 deletions(-) create mode 100644 src/components/MonitoringStatus/__snapshots__/index.test.tsx.snap create mode 100644 src/components/MonitoringStatus/index.tsx diff --git a/src/components/BaseMonitoringForm/__snapshots__/index.test.tsx.snap b/src/components/BaseMonitoringForm/__snapshots__/index.test.tsx.snap index efb79e4..6a24fe3 100644 --- a/src/components/BaseMonitoringForm/__snapshots__/index.test.tsx.snap +++ b/src/components/BaseMonitoringForm/__snapshots__/index.test.tsx.snap @@ -337,6 +337,141 @@ exports[`renders correctly 1`] = ` /> + + + + Sri Tanjung + | + 19 + Tahun, + Laki-laki + + + Pondok Cina, Beji + + + + + Status: + + + Belum Diperiksa + + + + diff --git a/src/components/BaseMonitoringForm/index.tsx b/src/components/BaseMonitoringForm/index.tsx index dba082a..5c999a8 100644 --- a/src/components/BaseMonitoringForm/index.tsx +++ b/src/components/BaseMonitoringForm/index.tsx @@ -1,22 +1,44 @@ import React from 'react'; import styled from 'styled-components/native'; import Header from 'components/Header'; +import MonitoringStatus from 'components/MonitoringStatus'; interface BaseMonitoringFormProps { - header: string; + header: string, + name: string, + age: string, + is_male: boolean, + address: string, + status: string } const ScrollView = styled.ScrollView` - background: #ffffff; + background: #ffffff; +`; + +const Body = styled.View` + background: #ffffff; + padding: 12px; + padding-top: 0; `; const BaseMonitoringForm = (props: BaseMonitoringFormProps) => { return ( -
+ + + + ); } diff --git a/src/components/MonitoringStatus/__snapshots__/index.test.tsx.snap b/src/components/MonitoringStatus/__snapshots__/index.test.tsx.snap new file mode 100644 index 0000000..7556b69 --- /dev/null +++ b/src/components/MonitoringStatus/__snapshots__/index.test.tsx.snap @@ -0,0 +1,125 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders correctly 1`] = ` + + + Sri Tanjung + | + 19 + Tahun, + Male + + + Pondok Cina, Beji + + + + + Status: + + + Belum Diperiksa + + + +`; diff --git a/src/components/MonitoringStatus/index.tsx b/src/components/MonitoringStatus/index.tsx new file mode 100644 index 0000000..d91d235 --- /dev/null +++ b/src/components/MonitoringStatus/index.tsx @@ -0,0 +1,44 @@ +import React from 'react'; +import styled from 'styled-components/native'; +import Text from 'components/Text'; +import Gap from 'components/Gap'; + +interface MonitoringStatusProps { + name: string, + age: string, + gender: string, + address: string, + status: string +} + +const Container = styled.View` + background: #fafafa; + padding-top: 18px; + padding-bottom: 12px; + padding-left: 12px; + padding-right: 12px; + border-top-left-radius: 20px; + border-bottom-right-radius: 60px +`; + +const Status = styled.View` + background: #f5f5f5; + width: 60%; + border-radius: 40px; +`; + +const MonitoringStatus = (props: MonitoringStatusProps) => { + return ( + + {props.name} | {props.age} Tahun, {props.gender} + {props.address} + + + Status: + {props.status} + + + ); +} + +export default MonitoringStatus; \ No newline at end of file -- GitLab From 8da4dabdccb07fd7b11ba03af0a3fb87d478b769 Mon Sep 17 00:00:00 2001 From: Irwanto Date: Sun, 5 Apr 2020 23:04:50 +0700 Subject: [PATCH 06/89] [CHORES] Add children element to base monitoring form --- src/components/BaseMonitoringForm/index.tsx | 4 +++- src/components/MonitoringStatus/index.tsx | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/BaseMonitoringForm/index.tsx b/src/components/BaseMonitoringForm/index.tsx index 5c999a8..b39877a 100644 --- a/src/components/BaseMonitoringForm/index.tsx +++ b/src/components/BaseMonitoringForm/index.tsx @@ -9,7 +9,8 @@ interface BaseMonitoringFormProps { age: string, is_male: boolean, address: string, - status: string + status: string, + children?: Element } const ScrollView = styled.ScrollView` @@ -37,6 +38,7 @@ const BaseMonitoringForm = (props: BaseMonitoringFormProps) => { address='Pondok Cina, Beji' status='Belum Diperiksa' /> + {props.children} diff --git a/src/components/MonitoringStatus/index.tsx b/src/components/MonitoringStatus/index.tsx index d91d235..59721ce 100644 --- a/src/components/MonitoringStatus/index.tsx +++ b/src/components/MonitoringStatus/index.tsx @@ -18,7 +18,8 @@ const Container = styled.View` padding-left: 12px; padding-right: 12px; border-top-left-radius: 20px; - border-bottom-right-radius: 60px + border-bottom-right-radius: 60px; + margin-bottom: 20px; `; const Status = styled.View` -- GitLab From eee3a0c42c8915d45ea2d9959ebc7d83e30a3ae0 Mon Sep 17 00:00:00 2001 From: Irwanto Date: Sun, 5 Apr 2020 23:21:05 +0700 Subject: [PATCH 07/89] [CHORES] Add test for branching in base monitoring form --- .../__snapshots__/index.test.tsx.snap | 507 ++++++++++++++++++ .../BaseMonitoringForm/index.test.tsx | 29 +- .../__snapshots__/index.test.tsx.snap | 1 + 3 files changed, 536 insertions(+), 1 deletion(-) diff --git a/src/components/BaseMonitoringForm/__snapshots__/index.test.tsx.snap b/src/components/BaseMonitoringForm/__snapshots__/index.test.tsx.snap index 6a24fe3..cd64adf 100644 --- a/src/components/BaseMonitoringForm/__snapshots__/index.test.tsx.snap +++ b/src/components/BaseMonitoringForm/__snapshots__/index.test.tsx.snap @@ -357,6 +357,7 @@ exports[`renders correctly 1`] = ` "backgroundColor": "#fafafa", "borderBottomRightRadius": 60, "borderTopLeftRadius": 20, + "marginBottom": 20, "paddingBottom": 12, "paddingLeft": 12, "paddingRight": 12, @@ -504,3 +505,509 @@ exports[`renders correctly 1`] = ` `; + +exports[`renders correctly 2`] = ` + + + + + + + + + + + + + + + + + + + + + Beranda + + + + + + This is header + + + + + + + + + + + + + Sri Tanjung + | + 19 + Tahun, + Perempuan + + + Pondok Cina, Beji + + + + + Status: + + + Belum Diperiksa + + + + + + + + + + + + + + + + + + + +`; diff --git a/src/components/BaseMonitoringForm/index.test.tsx b/src/components/BaseMonitoringForm/index.test.tsx index ed09874..a0705e4 100644 --- a/src/components/BaseMonitoringForm/index.test.tsx +++ b/src/components/BaseMonitoringForm/index.test.tsx @@ -9,7 +9,7 @@ import renderer from 'react-test-renderer'; const Stack = createStackNavigator(); it('renders correctly', () => { - const defaultPage = renderer + let defaultPage = renderer .create( { .toJSON(); expect(defaultPage).toMatchSnapshot(); + + defaultPage = renderer + .create( + + <>, + }}> + + + } + /> + + + ) + .toJSON(); + + expect(defaultPage).toMatchSnapshot(); }); \ No newline at end of file diff --git a/src/components/MonitoringStatus/__snapshots__/index.test.tsx.snap b/src/components/MonitoringStatus/__snapshots__/index.test.tsx.snap index 7556b69..84e9302 100644 --- a/src/components/MonitoringStatus/__snapshots__/index.test.tsx.snap +++ b/src/components/MonitoringStatus/__snapshots__/index.test.tsx.snap @@ -8,6 +8,7 @@ exports[`renders correctly 1`] = ` "backgroundColor": "#fafafa", "borderBottomRightRadius": 60, "borderTopLeftRadius": 20, + "marginBottom": 20, "paddingBottom": 12, "paddingLeft": 12, "paddingRight": 12, -- GitLab From 705a341fed6c46c8f220a7bc944683995e2e1af0 Mon Sep 17 00:00:00 2001 From: Josh Sudung Date: Mon, 6 Apr 2020 11:21:24 +0700 Subject: [PATCH 08/89] [RED] Added test cases for Monitoring Selection --- src/App/index.tsx | 5 + src/scenes/Home/index.tsx | 11 +- .../__snapshots__/index.test.tsx.snap | 695 ++++++++++++++++++ src/scenes/MonitoringSelection/dummy.ts | 17 + src/scenes/MonitoringSelection/index.test.tsx | 30 + src/scenes/MonitoringSelection/index.tsx | 0 .../__snapshots__/index.test.tsx.snap | 1 + src/scenes/index.tsx | 2 + 8 files changed, 758 insertions(+), 3 deletions(-) create mode 100644 src/scenes/MonitoringSelection/__snapshots__/index.test.tsx.snap create mode 100644 src/scenes/MonitoringSelection/dummy.ts create mode 100644 src/scenes/MonitoringSelection/index.test.tsx create mode 100644 src/scenes/MonitoringSelection/index.tsx diff --git a/src/App/index.tsx b/src/App/index.tsx index 2745880..2fca55f 100644 --- a/src/App/index.tsx +++ b/src/App/index.tsx @@ -21,6 +21,7 @@ import { ContactInvestigationFormStep2, ContactInvestigationFormStep3, ContactInvestigationFormStep4, + MonitoringSelection, } from 'scenes'; import {Dimensions} from 'react-native'; import initialCacheState, { @@ -142,6 +143,10 @@ const App = () => { name="office-signup-finish" component={OfficerSignupFormFinishPage} /> + diff --git a/src/scenes/Home/index.tsx b/src/scenes/Home/index.tsx index a458ed5..d8017ed 100644 --- a/src/scenes/Home/index.tsx +++ b/src/scenes/Home/index.tsx @@ -32,13 +32,18 @@ const Home = () => { - + diff --git a/src/scenes/MonitoringSelection/__snapshots__/index.test.tsx.snap b/src/scenes/MonitoringSelection/__snapshots__/index.test.tsx.snap new file mode 100644 index 0000000..1bf819c --- /dev/null +++ b/src/scenes/MonitoringSelection/__snapshots__/index.test.tsx.snap @@ -0,0 +1,695 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders correctly 1`] = ` + + + + + + + + + + + + + + + + + + + + + + Beranda + + + + + + Pilih Obyek Pemantauan + + + + + + + + + + + + + + Cari Kasus + + + + + + + + + + + + + + + + + + + + Pantau Kasus > + + + + + + + + + + + + + + + + + + + + +`; diff --git a/src/scenes/MonitoringSelection/dummy.ts b/src/scenes/MonitoringSelection/dummy.ts new file mode 100644 index 0000000..59f8218 --- /dev/null +++ b/src/scenes/MonitoringSelection/dummy.ts @@ -0,0 +1,17 @@ +export interface TempMonitoringCase { + caseId: string; + name: string; + description: string; + state: string; +} + +const dummyData: TempMonitoringCase[] = Array(11) + .fill(1) + .map((_, i) => ({ + caseId: `monitor-${i}`, + name: `Nama Penderita ${i}`, + description: `Deskripsi Penderita ${i}`, + state: `Status Penderita ${i}`, + })); + +export default dummyData; diff --git a/src/scenes/MonitoringSelection/index.test.tsx b/src/scenes/MonitoringSelection/index.test.tsx new file mode 100644 index 0000000..7c11066 --- /dev/null +++ b/src/scenes/MonitoringSelection/index.test.tsx @@ -0,0 +1,30 @@ + +import 'react-native'; +import React from 'react'; +import {NavigationContainer} from '@react-navigation/native'; +import {createStackNavigator} from '@react-navigation/stack'; +import MonitoringSelection from '.'; + +// Note: test renderer must be required after react-native. +import ReactTestRenderer from 'react-test-renderer'; + +const Stack = createStackNavigator(); + +it('renders correctly', () => { + const instance = ReactTestRenderer.create( + + <>, + }}> + + + , + ); + + expect(instance.toJSON()).toMatchSnapshot(); +}); diff --git a/src/scenes/MonitoringSelection/index.tsx b/src/scenes/MonitoringSelection/index.tsx new file mode 100644 index 0000000..e69de29 diff --git a/src/scenes/OfficerSignupForm/__snapshots__/index.test.tsx.snap b/src/scenes/OfficerSignupForm/__snapshots__/index.test.tsx.snap index 6905ad4..af290dd 100644 --- a/src/scenes/OfficerSignupForm/__snapshots__/index.test.tsx.snap +++ b/src/scenes/OfficerSignupForm/__snapshots__/index.test.tsx.snap @@ -375,6 +375,7 @@ exports[`renders correctly 1`] = ` diff --git a/src/scenes/index.tsx b/src/scenes/index.tsx index b4ea9d4..f900ae5 100644 --- a/src/scenes/index.tsx +++ b/src/scenes/index.tsx @@ -4,6 +4,7 @@ import ContactInvestigationFormStep2 from './ContactInvestigationFormStep2'; import ContactInvestigationFormStep3 from './ContactInvestigationFormStep3'; import ContactInvestigationFormStep4 from './ContactInvestigationFormStep4'; import LoginPage from './LoginPage'; +import MonitoringSelection from './MonitoringSelection'; import OfficerSignupForm from './OfficerSignupForm'; import { OfficerSignupFormFinishPage, @@ -20,4 +21,5 @@ export { ContactInvestigationFormStep2, ContactInvestigationFormStep3, ContactInvestigationFormStep4, + MonitoringSelection, } \ No newline at end of file -- GitLab From fb478447c892cebca2243362d96298769b9eabc3 Mon Sep 17 00:00:00 2001 From: Josh Sudung Date: Mon, 6 Apr 2020 14:38:12 +0700 Subject: [PATCH 09/89] [GREEN] Implement monitoring case selection page with dummy data --- src/scenes/MonitoringSelection/index.tsx | 162 +++++++++++++++++++++++ 1 file changed, 162 insertions(+) diff --git a/src/scenes/MonitoringSelection/index.tsx b/src/scenes/MonitoringSelection/index.tsx index e69de29..7236151 100644 --- a/src/scenes/MonitoringSelection/index.tsx +++ b/src/scenes/MonitoringSelection/index.tsx @@ -0,0 +1,162 @@ +import React, {useState, useEffect} from 'react'; +import styled from 'styled-components/native'; +import {ScrollView, View, TouchableWithoutFeedback} from 'react-native'; +import {Header, Field, Text, Button} from 'components'; +import RadioForm, { + RadioButton, + RadioButtonInput, +} from 'react-native-simple-radio-button'; +import {TempMonitoringCase} from './dummy'; +import dummyData from './dummy'; + +interface MonitoringCaseChoicesProps { + onChange?: Function; + data: TempMonitoringCase[]; +} + +const MonitoringCaseChoices = (props: MonitoringCaseChoicesProps) => { + const [, setSelectedValue] = useState(null); + const [selectedIndex, setSelectedIndex] = useState(null); + + const onSelectChange = (value: TempMonitoringCase, index: number) => { + setSelectedIndex(index); + setSelectedValue(value); + if (props.onChange) { + props.onChange(value); + } + }; + + return ( + + {props.data.slice(0, 5).map((val, index) => ( + + + + onSelectChange(val, index)} + /> + onSelectChange(val, index)}> + + + {val.name} + {' - ' + val.description} + + + {val.state} + + + + + + + ))} + + ); +}; + +const MonitoringSelection = () => { + const [searchQuery, setSearchQuery] = useState(''); + const [masterData, setMasterData] = useState([]); + const [filteredData, setFilteredData] = useState([]); + + useEffect(() => { + const fetchData = async () => { + const resp = dummyData; // Replace with fetch monitoring cases + setMasterData(resp); + setFilteredData(resp); + }; + fetchData(); + }, []); + + useEffect(() => { + if (searchQuery) { + const newData = masterData.filter(data => + JSON.stringify(data) + .toLowerCase() + .includes(searchQuery.toLowerCase()), + ); + setFilteredData(newData); + } else { + setFilteredData(masterData); + } + }, [searchQuery, masterData]); + + return ( + + +
+ + + + {}} data={filteredData} /> + + + + + + + + ); +}; + +const ContainerContent = styled.View` + padding: 2% 5% 5% 5%; + background-color: white; +`; + +const ButtonStyle = styled.View` + align-items: flex-end; +`; + +const RadioButtonMaster = styled.View` + margin-bottom: 5%; +`; + +const ChoiceSpan = styled.View` + display: flex; + min-height: ${props => props.theme.vh * 0.62}; +`; + +const RadioMaster = styled.View` + display: flex; + flex-direction: row; + align-items: center; +`; +const ChoiceTag = styled.View` + padding: 2%; + align-items: flex-end; + background-color: #f5f5f5; + width: 85%; + margin-left: 5%; + border-top-left-radius: 30px; + border-bottom-left-radius: 30px; +`; + +const ChoiceState = styled.View` + margin: 2% 0; + background-color: #e3e3e3; + padding: 1%; + border-radius: 10px; + min-width: 60%; + align-items: center; +`; + +const ChoiceHeader = styled.View` + display: flex; + flex-direction: row; +`; + +export default MonitoringSelection; -- GitLab From 8deb6a22951cc5a08d1b2cce5ad1eeaf63588ad3 Mon Sep 17 00:00:00 2001 From: Nandhika Prayoga Date: Thu, 9 Apr 2020 10:41:40 +0700 Subject: [PATCH 10/89] [GREEN] Fix caching reducer --- src/App/index.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/App/index.tsx b/src/App/index.tsx index 58af8b6..fc1754e 100644 --- a/src/App/index.tsx +++ b/src/App/index.tsx @@ -1,4 +1,4 @@ -import React, {useState, useEffect, useRef} from 'react'; +import React, {useState, useEffect, useReducer, useRef} from 'react'; import styled, {ThemeProvider} from 'styled-components/native'; import {NavigationContainer} from '@react-navigation/native'; import {createStackNavigator} from '@react-navigation/stack'; @@ -101,10 +101,9 @@ function cacheReducer(oldCache: CacheType, action: CacheAction): CacheType { } const App = () => { - const [cache, setCache] = useState(initialCacheState); + const [cache, cacheDispatch] = useReducer(cacheReducer, initialCacheState); const [token, setToken] = useState(); const [user, setUser] = useState(); - const [isFirstTimeHandleToken, setIsFirstTimeHandleToken] = useState(true); const navigatorRef = useRef() const mainService = useMainService(token); -- GitLab From fb73d1645be75cc6d6b09c74e357bef5058b850d Mon Sep 17 00:00:00 2001 From: Nandhika Prayoga Date: Thu, 9 Apr 2020 10:41:53 +0700 Subject: [PATCH 11/89] [REFACTOR] Change routing --- src/components/Header/index.tsx | 2 +- src/scenes/OfficerSignupForm/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx index d7cab53..64f887f 100644 --- a/src/components/Header/index.tsx +++ b/src/components/Header/index.tsx @@ -45,7 +45,7 @@ const Header = ({ diff --git a/src/scenes/OfficerSignupForm/index.tsx b/src/scenes/OfficerSignupForm/index.tsx index 3925a9b..d31f3e5 100644 --- a/src/scenes/OfficerSignupForm/index.tsx +++ b/src/scenes/OfficerSignupForm/index.tsx @@ -191,7 +191,7 @@ const OfficerSignupForm = () => { if (response.status === 201) { setIsLoading(false); - navigation.navigate("officer-signup-finish"); + navigation.navigate("login"); } else if (response.status === 500) { if (response.data.includes("IntegrityError")) { setServerHasError(false); -- GitLab From f74333dbd60d9fd5398b40e2352720ed52febff9 Mon Sep 17 00:00:00 2001 From: Nandhika Prayoga Date: Thu, 9 Apr 2020 11:49:07 +0700 Subject: [PATCH 12/89] [GREEN] Able to set initial value for Dropdown Field --- src/components/Field/index.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/Field/index.tsx b/src/components/Field/index.tsx index 5613e65..0c081bc 100644 --- a/src/components/Field/index.tsx +++ b/src/components/Field/index.tsx @@ -63,6 +63,12 @@ function Field({ const { colors } = useContext(ThemeContext) || {}; const [innerValue, setInnerValue] = useState(value); + useEffect(() => { + if (values && values.length > 0 && type === Type.Dropdown) { + setInnerValue(values[0].value) + } + }, []) + useEffect(() => { updateValue(innerValue); }, [innerValue]); -- GitLab From ce16edb1e4db227f29e42d938498523533e7b8e0 Mon Sep 17 00:00:00 2001 From: Nandhika Prayoga Date: Thu, 9 Apr 2020 11:49:47 +0700 Subject: [PATCH 13/89] [REFACTOR] Reset stacking and routing --- .../FinishPage/OfficerSignupFormFinishPage/index.tsx | 7 ++++++- src/scenes/OfficerSignupForm/index.tsx | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/scenes/FinishPage/OfficerSignupFormFinishPage/index.tsx b/src/scenes/FinishPage/OfficerSignupFormFinishPage/index.tsx index 9203d36..e087fed 100644 --- a/src/scenes/FinishPage/OfficerSignupFormFinishPage/index.tsx +++ b/src/scenes/FinishPage/OfficerSignupFormFinishPage/index.tsx @@ -36,7 +36,12 @@ const OfficerSignupFormFinishPage = () => { - diff --git a/src/scenes/OfficerSignupForm/index.tsx b/src/scenes/OfficerSignupForm/index.tsx index d31f3e5..efef60b 100644 --- a/src/scenes/OfficerSignupForm/index.tsx +++ b/src/scenes/OfficerSignupForm/index.tsx @@ -191,7 +191,10 @@ const OfficerSignupForm = () => { if (response.status === 201) { setIsLoading(false); - navigation.navigate("login"); + navigation.reset({ + index: 0, + routes: [{name: "officer-signup-finish"}], + }); } else if (response.status === 500) { if (response.data.includes("IntegrityError")) { setServerHasError(false); -- GitLab From 3561d3def4e8f67dd49066489fe33858c192cf02 Mon Sep 17 00:00:00 2001 From: Josh Sudung Date: Thu, 9 Apr 2020 12:14:13 +0700 Subject: [PATCH 14/89] [CHORES] Fix homepage not re rendering --- .../ContactInvestigationFormFinishPage/index.tsx | 7 ++++++- src/services/hooks/useMainService/index.tsx | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/scenes/FinishPage/ContactInvestigationFormFinishPage/index.tsx b/src/scenes/FinishPage/ContactInvestigationFormFinishPage/index.tsx index aff3fb8..1276602 100644 --- a/src/scenes/FinishPage/ContactInvestigationFormFinishPage/index.tsx +++ b/src/scenes/FinishPage/ContactInvestigationFormFinishPage/index.tsx @@ -27,7 +27,12 @@ const ContactInvestigationFormFinishPage = () => { - diff --git a/src/services/hooks/useMainService/index.tsx b/src/services/hooks/useMainService/index.tsx index 5434c78..0d4433d 100644 --- a/src/services/hooks/useMainService/index.tsx +++ b/src/services/hooks/useMainService/index.tsx @@ -6,7 +6,7 @@ const END_POINTS = { SIGNUP: '/signup', ME: '/accounts/me/', ACCOUNT: '/accounts/', - CREATE_CASE_SUBJECT: "cases/case-subjects", + CREATE_CASE_SUBJECT: "/cases/case-subjects", CREATE_INVESTIGATION_CASE: "/cases/investigation-cases", GET_LOG: "/logs", LIST_POSITIVE_CASE: "/cases/positive-cases", -- GitLab From 540cba84c57ca7ac3c8b9cef15cb59e2699db71f Mon Sep 17 00:00:00 2001 From: Irwanto Date: Mon, 13 Apr 2020 22:54:55 +0700 Subject: [PATCH 15/89] [CHORES] Add test for Splash scene --- .../Home/__snapshots__/index.test.tsx.snap | 103 +++++++++++++++++- src/scenes/Splash/index.test.tsx | 29 ++++- 2 files changed, 128 insertions(+), 4 deletions(-) diff --git a/src/scenes/Home/__snapshots__/index.test.tsx.snap b/src/scenes/Home/__snapshots__/index.test.tsx.snap index 5aa1751..e73be7c 100644 --- a/src/scenes/Home/__snapshots__/index.test.tsx.snap +++ b/src/scenes/Home/__snapshots__/index.test.tsx.snap @@ -267,7 +267,7 @@ exports[`renders correctly 1`] = ` } > Halo, - Dep + ! + + + + LOGOUT + + + + { +it('renders correctly without token', async () => { + LocalStorage.setSecretKey('sssttt'); const instance = renderer.create( { , ); expect(instance).toBeTruthy() + + const token = await LocalStorage.getItem("token"); + expect(token).toBeNull(); +}); + +it('renders correctly with token', async () => { + LocalStorage.setSecretKey('sssttt'); + LocalStorage.setItem("token", "token listrik"); + + const instance = renderer.create( + + <>, + }}> + + + , + ); + expect(instance).toBeTruthy() + + const token = await LocalStorage.getItem("token"); + expect(token).toBe("token listrik"); }); -- GitLab From e95deb417f78500ff72a77ef2e3582638594b62a Mon Sep 17 00:00:00 2001 From: Irwanto Date: Tue, 14 Apr 2020 00:04:58 +0700 Subject: [PATCH 16/89] [RED] Add test for login page scenes --- src/scenes/LoginPage/index.test.tsx | 142 +++++++++++++++++++++++++++- 1 file changed, 141 insertions(+), 1 deletion(-) diff --git a/src/scenes/LoginPage/index.test.tsx b/src/scenes/LoginPage/index.test.tsx index 1d580cf..b5381fb 100644 --- a/src/scenes/LoginPage/index.test.tsx +++ b/src/scenes/LoginPage/index.test.tsx @@ -1,12 +1,24 @@ import 'react-native'; +import axios from 'axios'; import React from 'react'; +import {LocalStorage, useMainService} from 'services'; import {NavigationContainer} from '@react-navigation/native'; import {createStackNavigator} from '@react-navigation/stack'; import LoginPage from '.'; -import ReactTestRenderer from 'react-test-renderer'; +import ReactTestRenderer, { act } from 'react-test-renderer'; +import { AppContext } from 'contexts'; const Stack = createStackNavigator(); +const testProps = { + services: { + main: useMainService('dummyToken'), + }, + cache: {}, +} + +jest.mock('axios'); +const mockedAxios = axios as jest.Mocked; it('renders correctly', () => { const instance = ReactTestRenderer.create( @@ -22,3 +34,131 @@ it('renders correctly', () => { expect(instance.toJSON()).toMatchSnapshot(); }); + +it('insert username and password correctly', async () => { + LocalStorage.setSecretKey("sssttt"); + + const instance = ReactTestRenderer.create( + + + <>, + }}> + + + + , + ); + + expect(instance.toJSON()).toMatchSnapshot(); + + const usernameField = instance.root.find(elem => elem.props.id === "username"); + expect(usernameField).toBeTruthy(); + + const passwordField = instance.root.find(elem => elem.props.id === "password"); + expect(passwordField).toBeTruthy(); + + act(() => { + if (usernameField && passwordField) { + usernameField.props.updateValue("username"); + passwordField.props.updateValue("passW0rd"); + } + + }) + expect(instance).toBeTruthy(); + + mockedAxios.request.mockImplementationOnce( + () => new Promise(resolve => { + resolve({ + status: 200, + data: { + "token": "your token", + }, + }); + }) + ); + + const submit = instance.root.find(elem => elem.props.id === "submit"); + console.log(submit); + await act(async () => { + submit.props.onPress(); + }) + const token = await LocalStorage.getItem("token"); + expect(token).toBe("your token"); +}); + +it('insert invalid username and password', async () => { + LocalStorage.setSecretKey("sssttt"); + + const instance = ReactTestRenderer.create( + + + <>, + }}> + + + + , + ); + + expect(instance.toJSON()).toMatchSnapshot(); + + const usernameField = instance.root.find(elem => elem.props.id === "username"); + expect(usernameField).toBeTruthy(); + + const passwordField = instance.root.find(elem => elem.props.id === "password"); + expect(passwordField).toBeTruthy(); + + act(() => { + if (usernameField && passwordField) { + usernameField.props.updateValue(""); + passwordField.props.updateValue(""); + } + + }) + expect(instance).toBeTruthy(); + + mockedAxios.request.mockImplementationOnce( + () => new Promise(resolve => { + resolve({ + status: 404 + }); + }) + ); + + const submit = instance.root.find(elem => elem.props.id === "submit"); + console.log(submit); + await act(async () => { + submit.props.onPress(); + }); + + expect(usernameField.props.information).toBe("Username tidak boleh kosong atau hanya mengandung karakter alphanumerik"); + expect(passwordField.props.information).toBe("Password tidak boleh kosong atau harus mengandung setidaknya 1 huruf kecil, 1 huruf besar, 1 angka dengan panjang minimal 8 karakter"); +}); + +it('press signup button', async () => { + LocalStorage.setSecretKey("sssttt"); + + const instance = ReactTestRenderer.create( + + + <>, + }}> + + + + , + ); + + expect(instance.toJSON()).toMatchSnapshot(); + + const signup = instance.root.find(elem => elem.props.id === "signup"); + act(() => { + signup.props.onPress(); + }) +}); \ No newline at end of file -- GitLab From 74d4dcbce0f4c0b705d2c341f2702220db4883b7 Mon Sep 17 00:00:00 2001 From: Irwanto Date: Tue, 14 Apr 2020 00:05:27 +0700 Subject: [PATCH 17/89] [GREEN] Add id to elements in login page --- .../__snapshots__/index.test.tsx.snap | 2562 +++++++++++++++++ src/scenes/LoginPage/index.tsx | 6 +- 2 files changed, 2567 insertions(+), 1 deletion(-) diff --git a/src/scenes/LoginPage/__snapshots__/index.test.tsx.snap b/src/scenes/LoginPage/__snapshots__/index.test.tsx.snap index b3bb338..8e9e07a 100644 --- a/src/scenes/LoginPage/__snapshots__/index.test.tsx.snap +++ b/src/scenes/LoginPage/__snapshots__/index.test.tsx.snap @@ -1,5 +1,2567 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`insert invalid username and password 1`] = ` + + + + + + + + + + + + + + + Masuk TBCare + + + + + + + Username + + + + + + + + + + + + + + + + + + + Password + + + + + + + + + + + + + + + + + + + Masuk Aplikasi + + + + + + Ajukan Akun Kader + + + + + + + + + + + + + + + + +`; + +exports[`insert username and password correctly 1`] = ` + + + + + + + + + + + + + + + Masuk TBCare + + + + + + + Username + + + + + + + + + + + + + + + + + + + Password + + + + + + + + + + + + + + + + + + + Masuk Aplikasi + + + + + + Ajukan Akun Kader + + + + + + + + + + + + + + + + +`; + +exports[`press signup button 1`] = ` + + + + + + + + + + + + + + + Masuk TBCare + + + + + + + Username + + + + + + + + + + + + + + + + + + + Password + + + + + + + + + + + + + + + + + + + Masuk Aplikasi + + + + + + Ajukan Akun Kader + + + + + + + + + + + + + + + + +`; + exports[`renders correctly 1`] = ` { { { -- GitLab From 801e92c8be1c10f58c1f257b3327aa18c739536b Mon Sep 17 00:00:00 2001 From: Nandhika Prayoga Date: Tue, 14 Apr 2020 12:23:54 +0700 Subject: [PATCH 19/89] [GREEN] Fix unresolve token --- src/App/index.tsx | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/App/index.tsx b/src/App/index.tsx index fc1754e..7a2c7de 100644 --- a/src/App/index.tsx +++ b/src/App/index.tsx @@ -130,23 +130,35 @@ const App = () => { }; useEffect(() => { + const startFromHomePage = () => { + navigatorRef.current?.reset({ + index: 0, + routes: [{name: 'home'}] + }) + } + + const startFromLoginPage = () => { + navigatorRef.current?.reset({ + index: 0, + routes: [{name: 'login'}] + }) + } + if (token) { const getUser = async () => { const response = await mainService.me() if (response.status === 200) { + // Token is valid setUser(response.data) - navigatorRef.current?.reset({ - index: 0, - routes: [{name: 'home'}] - }) + startFromHomePage() + } else { + // Token is not valid + setToken('') } } getUser() } else if (token === '') { - navigatorRef.current?.reset({ - index: 0, - routes: [{name: 'login'}] - }) + startFromLoginPage() } }, [token]) -- GitLab From 84518fbe555f8096719c79265b1cabd8bdad0e39 Mon Sep 17 00:00:00 2001 From: Irwanto Date: Tue, 14 Apr 2020 12:28:04 +0700 Subject: [PATCH 20/89] [CHORES] Add test for investigation form step 4 --- .../__snapshots__/index.test.tsx.snap | 5829 +++++++++++++++++ .../index.test.tsx | 149 +- .../ContactInvestigationFormStep4/index.tsx | 2 + 3 files changed, 5978 insertions(+), 2 deletions(-) diff --git a/src/scenes/ContactInvestigationFormStep4/__snapshots__/index.test.tsx.snap b/src/scenes/ContactInvestigationFormStep4/__snapshots__/index.test.tsx.snap index 7c8fd1c..685441d 100644 --- a/src/scenes/ContactInvestigationFormStep4/__snapshots__/index.test.tsx.snap +++ b/src/scenes/ContactInvestigationFormStep4/__snapshots__/index.test.tsx.snap @@ -1,5 +1,5834 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`click previous button successful 1`] = ` + + + + + + + + + + + + + + + + + + + + + Beranda + + + + + + Masukkan Data Investigasi Kontak + + + + + + + + + + + + + + + + + + + + + + Identitas + + + + + + + + + Skrining + + + + + + + + + Rujukan + + + + + + + + + Langkah + 3 + /3 + + + + + + Nama Kasus Acuan + + + + - + + + + + + + + Apakah Perlu Rujukan? + + + + + + + + + Ya + + + + + Tidak + + + + + + + + + + + + Fasilitas Kesehatan Rujukan + + + + + + + + + + + + + + + + + + + < Sebelumnya + + + + + + Masukkan Data > + + + + + + + + + + + + + + + + + + + + +`; + +exports[`create investigation case succesful 1`] = ` + + + + + + + + + + + + + + + + + + + + + Beranda + + + + + + Masukkan Data Investigasi Kontak + + + + + + + + + + + + + + + + + + + + + + Identitas + + + + + + + + + Skrining + + + + + + + + + Rujukan + + + + + + + + + Langkah + 3 + /3 + + + + + + Nama Kasus Acuan + + + + - + + + + + + + + Apakah Perlu Rujukan? + + + + + + + + + Ya + + + + + Tidak + + + + + + + + + + + + Fasilitas Kesehatan Rujukan + + + + + + + + + + + + + + + + + + + < Sebelumnya + + + + + + Masukkan Data > + + + + + + + + + + + + + + + + + + + + +`; + +exports[`edit investigation case succesful 1`] = ` + + + + + + + + + + + + + + + + + + + + + Beranda + + + + + + Masukkan Data Investigasi Kontak + + + + + + + + + + + + + + + + + + + + + + Identitas + + + + + + + + + Skrining + + + + + + + + + Rujukan + + + + + + + + + Langkah + 3 + /3 + + + + + + Nama Kasus Acuan + + + + - + + + + + + + + Apakah Perlu Rujukan? + + + + + + + + + Ya + + + + + Tidak + + + + + + + + + + + + Fasilitas Kesehatan Rujukan + + + + +