Fakultas Ilmu Komputer UI

Commit 9a65c012 authored by Josh Sudung's avatar Josh Sudung
Browse files

Resolve merge conflicts on test files

parents 848fa9f5 2172a38c
Pipeline #44269 passed with stage
in 5 minutes and 21 seconds
......@@ -163,7 +163,7 @@ exports[`DatePicker tests renders correctly 1`] = `
]
}
>
4/29/2020
5/2/2020
</Text>
</View>
<View
......
......@@ -159,4 +159,51 @@ it('press signup button', async () => {
act(() => {
signup.props.onPress();
})
});
it('inserts invalid (length<8) password', async () => {
LocalStorage.setSecretKey('sssttt');
const instance = ReactTestRenderer.create(
<AppContext.Provider value={testProps}>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
header: () => <></>,
}}>
<Stack.Screen name="login" component={LoginPage} />
</Stack.Navigator>
</NavigationContainer>
</AppContext.Provider>,
);
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('user4x1d');
passwordField.props.updateValue('len3');
}
});
const submit = instance.root.find(elem => elem.props.id === 'submit');
await act(async () => {
submit.props.onPress();
});
const errorModal = instance.root.find(
elem => elem.props.id === 'error-modal',
);
expect(errorModal.props.visible).toBe(true);
});
\ No newline at end of file
......@@ -50,6 +50,7 @@ const LoginPage = () => {
</ModalContainer>
</Modal>
<Modal
id="error-modal"
animationType="fade"
transparent={true}
visible={errorModalVisible}
......
......@@ -880,7 +880,7 @@ exports[`can press previous button 1`] = `
]
}
>
4/29/2020
5/2/2020
</Text>
</View>
<View
......@@ -2307,7 +2307,7 @@ exports[`renders correctly 1`] = `
]
}
>
4/29/2020
5/2/2020
</Text>
</View>
<View
......@@ -3734,7 +3734,7 @@ exports[`renders form with correct fields 1`] = `
]
}
>
4/29/2020
5/2/2020
</Text>
</View>
<View
......@@ -5161,7 +5161,7 @@ exports[`submit data succesfully 1`] = `
]
}
>
4/29/2020
5/2/2020
</Text>
</View>
<View
......
......@@ -634,7 +634,7 @@ exports[`can press previous button 1`] = `
]
}
>
4/29/2020
5/2/2020
</Text>
</View>
<View
......@@ -852,7 +852,7 @@ exports[`can press previous button 1`] = `
]
}
>
4/29/2020
5/2/2020
</Text>
</View>
<View
......@@ -2012,7 +2012,7 @@ exports[`renders correctly 1`] = `
]
}
>
4/29/2020
5/2/2020
</Text>
</View>
<View
......@@ -2230,7 +2230,7 @@ exports[`renders correctly 1`] = `
]
}
>
4/29/2020
5/2/2020
</Text>
</View>
<View
......@@ -3390,7 +3390,7 @@ exports[`renders form with correct fields 1`] = `
]
}
>
4/29/2020
5/2/2020
</Text>
</View>
<View
......@@ -3608,7 +3608,7 @@ exports[`renders form with correct fields 1`] = `
]
}
>
4/29/2020
5/2/2020
</Text>
</View>
<View
......@@ -4768,7 +4768,7 @@ exports[`submit data succesfully 1`] = `
]
}
>
4/29/2020
5/2/2020
</Text>
</View>
<View
......@@ -4986,7 +4986,7 @@ exports[`submit data succesfully 1`] = `
]
}
>
4/29/2020
5/2/2020
</Text>
</View>
<View
......
......@@ -6,9 +6,10 @@ import MonitoringSelection from '.';
import {MonitoringCase} from 'contexts/AppContext/types';
// Note: test renderer must be required after react-native.
import ReactTestRenderer, { act } from 'react-test-renderer';
import ReactTestRenderer, {act} from 'react-test-renderer';
import {useMainService} from 'services';
import {AppContext} from 'contexts';
import axios from 'axios';
const Stack = createStackNavigator();
const testProps = {
......@@ -19,6 +20,39 @@ const testProps = {
setCache: jest.fn(),
};
jest.mock('axios');
const mock = axios as jest.Mocked<typeof axios>;
const monitoringFetchData = {
count: 1,
next: true,
previous: true,
results: [
{
id: 'id',
investigation_case: {
id: 'bb6f0e2c-59a4-40d3-942f-db884c64728b',
case_subject: {
id: '198idd8b4b-01dd-448b-8e3d-a52162d657cb',
name: 'case-name',
age: 75,
is_male: true,
address: 'Jl. Adi',
district: 'Beji',
sub_district: 'Beji',
created_at: '2020-04-23T13:13:31.942672+07:00',
},
},
is_referred: true,
is_checked: true,
is_medicated: false,
regular_medicine_intake: [],
treatment_start_date: null,
treatment_end_date: null,
},
],
};
const monitoringCase: MonitoringCase = {
id: '12345',
state: 'Belum Dirujuk',
......@@ -53,7 +87,17 @@ it('renders correctly', () => {
expect(instance.toJSON()).toMatchSnapshot();
});
it('can do search', () => {
it('successfully fetches monitoring cases', async () => {
mock.request.mockImplementationOnce(
() =>
new Promise(resolve => {
resolve({
status: 200,
data: monitoringFetchData,
});
}),
);
const instance = ReactTestRenderer.create(
<AppContext.Provider value={testProps}>
<NavigationContainer>
......@@ -70,20 +114,58 @@ it('can do search', () => {
</NavigationContainer>
</AppContext.Provider>,
);
expect(instance.toJSON()).toMatchSnapshot();
expect(mock.request).toBeCalled();
});
const searchbar = instance.root.find(elem => elem.props.name === "Cari Nama");
act(() => {
searchbar.props.updateValue('Coba');
})
it('succesfully searches monitoring case', async () => {
mock.request.mockResolvedValue({
status: 200,
data: monitoringFetchData,
});
const instance = ReactTestRenderer.create(
<AppContext.Provider value={testProps}>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
header: () => <></>,
}}>
<Stack.Screen
name="monitoring-select"
component={MonitoringSelection}
/>
</Stack.Navigator>
</NavigationContainer>
</AppContext.Provider>,
);
expect(instance.toJSON()).toMatchSnapshot();
expect(mock.request).toBeCalled();
const searchField = instance.root.find(
elem => elem.props.name === 'Cari Nama',
);
await act(() => {
searchField.props.updateValue('case-name');
setTimeout(() => {}, 500);
});
expect(searchField.props.value).toBe('case-name');
expect(mock.request).toBeCalled();
});
it('can change choices page', () => {
it('determines state_1 correctly', async () => {
mock.request.mockResolvedValue({
status: 200,
data: monitoringFetchData,
});
const instance = ReactTestRenderer.create(
<AppContext.Provider value={testProps}>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
// Empty header
header: () => <></>,
}}>
<Stack.Screen
......@@ -94,71 +176,265 @@ it('can change choices page', () => {
</NavigationContainer>
</AppContext.Provider>,
);
expect(instance.toJSON()).toMatchSnapshot();
const prev = instance.root.find(elem => elem.props.id === "prev");
act(() => {
prev.props.onPress();
})
await act(async () => {
expect(mock.request).toBeCalled();
});
const selectedCase = instance.root.find(elem => elem.props.id === 'case-0');
const nextButton = instance.root.find(
elem => elem.props.id === 'navigate-button',
);
await act(() => {
selectedCase.props.onPress();
});
const next = instance.root.find(elem => elem.props.id === "next");
act(() => {
next.props.onPress();
})
nextButton.props.onPress();
});
});
it('determine state and navigation correctly', () => {
it('determines state_2 correctly', async () => {
mock.request.mockResolvedValue({
status: 200,
data: {
count: 1,
next: true,
previous: true,
results: [
{
id: 'id',
investigation_case: {
id: 'bb6f0e2c-59a4-40d3-942f-db884c64728b',
case_subject: {
id: '198idd8b4b-01dd-448b-8e3d-a52162d657cb',
name: 'case-name',
age: 75,
is_male: true,
address: 'Jl. Adi',
district: 'Beji',
sub_district: 'Beji',
created_at: '2020-04-23T13:13:31.942672+07:00',
},
},
is_referred: true,
is_checked: false,
is_medicated: false,
regular_medicine_intake: [],
treatment_start_date: null,
treatment_end_date: null,
},
],
},
});
const instance = ReactTestRenderer.create(
<AppContext.Provider value={testProps}>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
screenOptions={{
header: () => <></>,
}}>
<Stack.Screen
}}>
<Stack.Screen
name="monitoring-select"
component={MonitoringSelection}
/>
/>
</Stack.Navigator>
</NavigationContainer>
</AppContext.Provider>,
);
expect(instance.toJSON()).toMatchSnapshot();
const choices = instance.root.find(elem => elem.props.id === "choices");
act(() => {
choices.props.onChange(monitoringCase);
await act(async () => {
expect(mock.request).toBeCalled();
});
const submit = instance.root.find(elem => elem.props.id === "submit");
expect(submit).toBeTruthy();
const selectedCase = instance.root.find(elem => elem.props.id === 'case-0');
const nextButton = instance.root.find(
elem => elem.props.id === 'navigate-button',
);
act(() => {
submit.props.onPress();
await act(() => {
selectedCase.props.onPress();
});
monitoringCase.is_referred = true;
act(() => {
choices.props.onChange(monitoringCase);
nextButton.props.onPress();
});
act(() => {
submit.props.onPress();
});
it('determines state_3 correctly', async () => {
mock.request.mockResolvedValue({
status: 200,
data: {
count: 1,
next: true,
previous: true,
results: [
{
id: 'id',
investigation_case: {
id: 'bb6f0e2c-59a4-40d3-942f-db884c64728b',
case_subject: {
id: '198idd8b4b-01dd-448b-8e3d-a52162d657cb',
name: 'case-name',
age: 75,
is_male: true,
address: 'Jl. Adi',
district: 'Beji',
sub_district: 'Beji',
created_at: '2020-04-23T13:13:31.942672+07:00',
},
},
is_referred: false,
is_checked: false,
is_medicated: false,
regular_medicine_intake: [],
treatment_start_date: null,
treatment_end_date: null,
},
],
},
});
monitoringCase.is_checked = true;
act(() => {
choices.props.onChange(monitoringCase);
const instance = ReactTestRenderer.create(
<AppContext.Provider value={testProps}>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
header: () => <></>,
}}>
<Stack.Screen
name="monitoring-select"
component={MonitoringSelection}
/>
</Stack.Navigator>
</NavigationContainer>
</AppContext.Provider>,
);
expect(instance.toJSON()).toMatchSnapshot();
await act(async () => {
expect(mock.request).toBeCalled();
});
act(() => {
submit.props.onPress();
const selectedCase = instance.root.find(elem => elem.props.id === 'radio-0');
const nextButton = instance.root.find(
elem => elem.props.id === 'navigate-button',
);
await act(() => {
selectedCase.props.onPress();
});
monitoringCase.is_medicated = true;
act(() => {
choices.props.onChange(monitoringCase);
nextButton.props.onPress();
});
});
it('determines state_4 correctly', async () => {
mock.request.mockResolvedValue({
status: 200,
data: {
count: 1,
next: true,
previous: true,
results: [
{
id: 'id',
investigation_case: {
id: 'bb6f0e2c-59a4-40d3-942f-db884c64728b',
case_subject: {
id: '198idd8b4b-01dd-448b-8e3d-a52162d657cb',
name: 'case-name',
age: 75,
is_male: true,
address: 'Jl. Adi',
district: 'Beji',
sub_district: 'Beji',
created_at: '2020-04-23T13:13:31.942672+07:00',
},
},
is_referred: true,
is_checked: true,
is_medicated: true,
regular_medicine_intake: [],
treatment_start_date: null,
treatment_end_date: null,
},
],
},
});
const instance = ReactTestRenderer.create(
<AppContext.Provider value={testProps}>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
header: () => <></>,
}}>
<Stack.Screen
name="monitoring-select"
component={MonitoringSelection}
/>
</Stack.Navigator>
</NavigationContainer>
</AppContext.Provider>,
);
expect(instance.toJSON()).toMatchSnapshot();
await act(async () => {
expect(mock.request).toBeCalled();
});
const selectedCase = instance.root.find(elem => elem.props.id === 'case-0');
const nextButton = instance.root.find(
elem => elem.props.id === 'navigate-button',
);
await act(() => {
selectedCase.props.onPress();
});
act(() => {
submit.props.onPress();
nextButton.props.onPress();
});
});
it('changes pages correctly', async () => {
mock.request.mockResolvedValue({
status: 200,
data: monitoringFetchData,
});
const instance = ReactTestRenderer.create(
<AppContext.Provider value={testProps}>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
header: () => <></>,
}}>
<Stack.Screen
name="monitoring-select"
component={MonitoringSelection}
/>