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 { ...@@ -18,10 +18,10 @@ import {
} from 'scenes'; } from 'scenes';
import {Dimensions} from 'react-native'; import {Dimensions} from 'react-native';
import initialCacheState, { import initialCacheState, {
CacheType, CacheType
SetCacheType,
} from 'contexts/AppContext/cache'; } from 'contexts/AppContext/cache';
import { useMainService, LocalStorage } from 'services' import { useMainService, LocalStorage } from 'services'
import Log from 'components/Log';
const StyledApp = styled.SafeAreaView` const StyledApp = styled.SafeAreaView`
height: 100%; height: 100%;
...@@ -48,10 +48,6 @@ declare global { ...@@ -48,10 +48,6 @@ declare global {
type TokenType = string; type TokenType = string;
type SetTokenType = React.Dispatch<React.SetStateAction<TokenType>>; type SetTokenType = React.Dispatch<React.SetStateAction<TokenType>>;
type CacheType = {
string?: any;
};
type SetCacheType = React.Dispatch<React.SetStateAction<CacheType>>;
interface GlobalProps { interface GlobalProps {
vw: number; vw: number;
...@@ -61,7 +57,7 @@ declare global { ...@@ -61,7 +57,7 @@ declare global {
}; };
setToken: SetTokenType; setToken: SetTokenType;
cache: CacheType; cache: CacheType;
setCache: SetCacheType; setCache: (object) => void;
isAuthenticated: boolean; isAuthenticated: boolean;
} }
} }
...@@ -82,6 +78,28 @@ const theme: ThemeProps = { ...@@ -82,6 +78,28 @@ const theme: ThemeProps = {
vh: Dimensions.get('window').height, 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 App = () => {
const [cache, setCache] = useState<CacheType>(initialCacheState); const [cache, setCache] = useState<CacheType>(initialCacheState);
const [token, setToken] = useState(); const [token, setToken] = useState();
...@@ -104,7 +122,12 @@ const App = () => { ...@@ -104,7 +122,12 @@ const App = () => {
vh: Dimensions.get('window').height, vh: Dimensions.get('window').height,
// For caching // For caching
cache, cache,
setCache, setCache: (data) => {
cacheDispatch({
type: CacheActionType.Update,
data,
})
},
}; };
useEffect(() => { useEffect(() => {
...@@ -169,6 +192,7 @@ const App = () => { ...@@ -169,6 +192,7 @@ const App = () => {
name="officer-signup-finish" name="officer-signup-finish"
component={OfficerSignupFormFinishPage} component={OfficerSignupFormFinishPage}
/> />
<Stack.Screen name="log" component={Log} />
</Stack.Navigator> </Stack.Navigator>
</NavigationContainer> </NavigationContainer>
</StyledApp> </StyledApp>
......
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`renders correctly 1`] = ` exports[`CategoryButton tests Should change value after set value from outside 1`] = `
<View <View
axis={2} axis={2}
style={ style={
...@@ -68,6 +68,404 @@ exports[`renders correctly 1`] = ` ...@@ -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 <View
style={ style={
Array [ Array [
......
...@@ -10,7 +10,8 @@ import CategoryButton from '.'; ...@@ -10,7 +10,8 @@ import CategoryButton from '.';
import renderer, {act} from 'react-test-renderer'; import renderer, {act} from 'react-test-renderer';
import SwitchSelector from 'react-native-switch-selector'; import SwitchSelector from 'react-native-switch-selector';
it('renders correctly', () => { describe("CategoryButton tests", () => {
it('renders correctly', () => {
const options = [ const options = [
{label: 'Laki-laki', value: 1}, {label: 'Laki-laki', value: 1},
{label: 'Perempuan', value: 0}, {label: 'Perempuan', value: 0},
...@@ -23,7 +24,6 @@ it('renders correctly', () => { ...@@ -23,7 +24,6 @@ it('renders correctly', () => {
const inst = renderer.create( const inst = renderer.create(
<CategoryButton <CategoryButton
name="Jenis Kelamin" name="Jenis Kelamin"
label="Jenis Kelamin"
options={options} options={options}
onClick={() => addVal()} onClick={() => addVal()}
/>, />,
...@@ -38,4 +38,53 @@ it('renders correctly', () => { ...@@ -38,4 +38,53 @@ it('renders correctly', () => {
}); });
expect(val).toBe(1); 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(() => {