Fakultas Ilmu Komputer UI

Commit 85a8b133 authored by Josh Sudung's avatar Josh Sudung
Browse files

Merge branch 'pbi-9-investigasi-kontak' into 'staging'

Integrate log activity with investigation case edit form

See merge request !18
parents a5b84ae0 357a2e61
Pipeline #39558 passed with stages
in 11 minutes and 52 seconds
[0408/032353.859:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0408/032353.880:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0408/032353.880:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0408/032353.881:ERROR:crash_report_database_win.cc(469)] failed to stat report
......@@ -18,10 +18,10 @@ import {
} from 'scenes';
import {Dimensions} from 'react-native';
import initialCacheState, {
CacheType,
SetCacheType,
CacheType
} from 'contexts/AppContext/cache';
import { useMainService, LocalStorage } from 'services'
import Log from 'components/Log';
const StyledApp = styled.SafeAreaView`
height: 100%;
......@@ -48,10 +48,6 @@ declare global {
type TokenType = string;
type SetTokenType = React.Dispatch<React.SetStateAction<TokenType>>;
type CacheType = {
string?: any;
};
type SetCacheType = React.Dispatch<React.SetStateAction<CacheType>>;
interface GlobalProps {
vw: number;
......@@ -61,7 +57,7 @@ declare global {
};
setToken: SetTokenType;
cache: CacheType;
setCache: SetCacheType;
setCache: (object) => void;
isAuthenticated: boolean;
}
}
......@@ -82,6 +78,28 @@ const theme: ThemeProps = {
vh: Dimensions.get('window').height,
};
enum CacheActionType{
Update = "Update"
}
type CacheAction =
| {
type: CacheActionType.Update;
data: object;
}
function cacheReducer(oldCache: CacheType, action: CacheAction): CacheType {
switch(action.type) {
case CacheActionType.Update:
return {
...oldCache,
...action.data,
}
default:
return oldCache
}
}
const App = () => {
const [cache, setCache] = useState<CacheType>(initialCacheState);
const [token, setToken] = useState();
......@@ -104,7 +122,12 @@ const App = () => {
vh: Dimensions.get('window').height,
// For caching
cache,
setCache,
setCache: (data) => {
cacheDispatch({
type: CacheActionType.Update,
data,
})
},
};
useEffect(() => {
......@@ -169,6 +192,7 @@ const App = () => {
name="officer-signup-finish"
component={OfficerSignupFormFinishPage}
/>
<Stack.Screen name="log" component={Log} />
</Stack.Navigator>
</NavigationContainer>
</StyledApp>
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`renders correctly 1`] = `
exports[`CategoryButton tests Should change value after set value from outside 1`] = `
<View
axis={2}
style={
......@@ -68,6 +68,404 @@ exports[`renders correctly 1`] = `
]
}
/>
<View
style={
Array [
Object {
"flexDirection": "row",
},
Object {},
]
}
>
<View
onMoveShouldSetResponder={[Function]}
onMoveShouldSetResponderCapture={[Function]}
onResponderEnd={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderReject={[Function]}
onResponderRelease={[Function]}
onResponderStart={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
onStartShouldSetResponderCapture={[Function]}
style={
Object {
"flex": 1,
}
}
>
<View
onLayout={[Function]}
style={
Object {
"backgroundColor": "#FAFAFA",
"borderRadius": 4,
"height": 30,
}
}
>
<View
style={
Object {
"borderColor": "#C9C9C9",
"borderRadius": 4,
"borderWidth": 0,
"flex": 1,
"flexDirection": "row",
}
}
>
<View
accessible={true}
focusable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
"justifyContent": "center",
"opacity": 1,
}
}
>
<Text
style={
Array [
Object {
"backgroundColor": "transparent",
"color": "#5F5F5F",
"fontSize": 14,
"fontWeight": "bold",
"textAlign": "center",
},
Object {},
]
}
>
Laki-laki
</Text>
</View>
<View
accessible={true}
focusable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
"justifyContent": "center",
"opacity": 1,
}
}
>
<Text
style={
Array [
Object {
"backgroundColor": "transparent",
"color": "#FFFFFF",
"fontSize": 14,
"fontWeight": "bold",
"textAlign": "center",
},
Object {},
]
}
>
Perempuan
</Text>
</View>
</View>
</View>
</View>
</View>
</View>
`;
exports[`CategoryButton tests renders correctly 1`] = `
<View
axis={2}
style={
Array [
Object {
"alignItems": "flex-start",
"backgroundColor": "transparent",
"borderBottomColor": "black",
"borderBottomWidth": 0,
"borderLeftColor": "black",
"borderLeftWidth": 0,
"borderRadius": 0,
"borderRightColor": "black",
"borderRightWidth": 0,
"borderTopColor": "black",
"borderTopWidth": 0,
"flexDirection": "column",
"flexGrow": 0,
"flexShrink": 0,
"flexWrap": "nowrap",
"height": "auto",
"justifyContent": "flex-start",
"paddingBottom": 0,
"paddingLeft": 0,
"paddingRight": 0,
"paddingTop": 0,
"width": "auto",
},
]
}
>
<Text
fontSize="16px"
fontWeight="Bold"
style={
Array [
Object {
"color": "black",
"fontFamily": "Dosis-Bold",
"fontSize": 16,
"textAlign": "left",
"width": "auto",
},
]
}
>
Jenis Kelamin
</Text>
<View
paddingBottom={6}
paddingLeft={0}
paddingRight={0}
paddingTop={6}
style={
Array [
Object {
"flexBasis": "auto",
"flexGrow": 0,
"flexShrink": 0,
"paddingBottom": 6,
"paddingLeft": 0,
"paddingRight": 0,
"paddingTop": 6,
},
]
}
/>
<View
style={
Array [
Object {
"flexDirection": "row",
},
Object {},
]
}
>
<View
onMoveShouldSetResponder={[Function]}
onMoveShouldSetResponderCapture={[Function]}
onResponderEnd={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderReject={[Function]}
onResponderRelease={[Function]}
onResponderStart={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
onStartShouldSetResponderCapture={[Function]}
style={
Object {
"flex": 1,
}
}
>
<View
onLayout={[Function]}
style={
Object {
"backgroundColor": "#FAFAFA",
"borderRadius": 4,
"height": 30,
}
}
>
<View
style={
Object {
"borderColor": "#C9C9C9",
"borderRadius": 4,
"borderWidth": 0,
"flex": 1,
"flexDirection": "row",
}
}
>
<View
accessible={true}
focusable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
"justifyContent": "center",
"opacity": 1,
}
}
>
<Text
style={
Array [
Object {
"backgroundColor": "transparent",
"color": "#FFFFFF",
"fontSize": 14,
"fontWeight": "bold",
"textAlign": "center",
},
Object {},
]
}
>
Laki-laki
</Text>
</View>
<View
accessible={true}
focusable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
"justifyContent": "center",
"opacity": 1,
}
}
>
<Text
style={
Array [
Object {
"backgroundColor": "transparent",
"color": "#5F5F5F",
"fontSize": 14,
"fontWeight": "bold",
"textAlign": "center",
},
Object {},
]
}
>
Perempuan
</Text>
</View>
</View>
</View>
</View>
</View>
</View>
`;
exports[`CategoryButton tests should be okay if there is not onClick function 1`] = `
<View
axis={2}
style={
Array [
Object {
"alignItems": "flex-start",
"backgroundColor": "transparent",
"borderBottomColor": "black",
"borderBottomWidth": 0,
"borderLeftColor": "black",
"borderLeftWidth": 0,
"borderRadius": 0,
"borderRightColor": "black",
"borderRightWidth": 0,
"borderTopColor": "black",
"borderTopWidth": 0,
"flexDirection": "column",
"flexGrow": 0,
"flexShrink": 0,
"flexWrap": "nowrap",
"height": "auto",
"justifyContent": "flex-start",
"paddingBottom": 0,
"paddingLeft": 0,
"paddingRight": 0,
"paddingTop": 0,
"width": "auto",
},
]
}
>
<Text
fontSize="16px"
fontWeight="Bold"
style={
Array [
Object {
"color": "black",
"fontFamily": "Dosis-Bold",
"fontSize": 16,
"textAlign": "left",
"width": "auto",
},
]
}
>
Gender
</Text>
<View
paddingBottom={6}
paddingLeft={0}
paddingRight={0}
paddingTop={6}
style={
Array [
Object {
"flexBasis": "auto",
"flexGrow": 0,
"flexShrink": 0,
"paddingBottom": 6,
"paddingLeft": 0,
"paddingRight": 0,
"paddingTop": 6,
},
]
}
/>
<View
style={
Array [
......
......@@ -10,7 +10,8 @@ import CategoryButton from '.';
import renderer, {act} from 'react-test-renderer';
import SwitchSelector from 'react-native-switch-selector';
it('renders correctly', () => {
describe("CategoryButton tests", () => {
it('renders correctly', () => {
const options = [
{label: 'Laki-laki', value: 1},
{label: 'Perempuan', value: 0},
......@@ -23,7 +24,6 @@ it('renders correctly', () => {
const inst = renderer.create(
<CategoryButton
name="Jenis Kelamin"
label="Jenis Kelamin"
options={options}
onClick={() => addVal()}
/>,
......@@ -38,4 +38,53 @@ it('renders correctly', () => {
});
expect(val).toBe(1);
});
});
it('should be okay if there is not onClick function', () => {
const options = [
{label: 'Laki-laki', value: 1},
{label: 'Perempuan', value: 0},
];
const inst = renderer.create(
<CategoryButton
name="Gender"
options={options}
/>,
);
expect(inst.toJSON()).toMatchSnapshot();
});
it("Should change value after set value from outside", () => {
const options = [
{label: 'Laki-laki', value: 1},
{label: 'Perempuan', value: 0},
];
let val;
const inst = renderer.create(
<CategoryButton
name="Jenis Kelamin"
value={0}
options={options}
onClick={(newValue) => val = newValue}
/>,
);
expect(inst.toJSON()).toMatchSnapshot();
const button = inst.root.findByType(SwitchSelector);
let numberIteration = 1
const tolerance = 100
while(val !== 0 && numberIteration < tolerance) {
act(() => {
button.props.onPress();
});
numberIteration++
}
expect(val).toBe(0);
})
})
import React from 'react';
import React, { useState, useEffect } from 'react';
import SwitchSelector from 'react-native-switch-selector';
import { Text, Box, Gap } from 'components';
type Label = string;
type Value = any;
interface Option {
label: Label;
value: Value;
}
interface CategoryButtonProps {
name: string,
label: string,
options: {label: string, value: any}[]
onClick?: func,
value?: Value,
options: Array<Option>,
onClick?: (value: Value) => void,
}
function setIndex(options: Array<Option>, value: Value): number {
let index: number = 0
while (index < options.length) {
if (options[index].value === value) return index
index++
}
// Default position
return 0
}
const CategoryButton = (props: CategoryButtonProps) => {
const {options, label, onClick} = props;
const CategoryButton = ({