Fakultas Ilmu Komputer UI

Commit a372f3fa authored by Wulan Mantiri's avatar Wulan Mantiri
Browse files

Merge branch 'PBI-1-dietela-quiz-integration-with-result' into 'staging'

Integrate Dietela Quiz response to Quiz Result page

See merge request !15
parents 96decd10 45fda602
Pipeline #67947 passed with stages
in 27 minutes and 51 seconds
...@@ -91,7 +91,7 @@ describe('AllAccessQuestionnaire', () => { ...@@ -91,7 +91,7 @@ describe('AllAccessQuestionnaire', () => {
expect(nextPage).toBeTruthy(); expect(nextPage).toBeTruthy();
}); });
it('redirects to initial page if all form values are valid and submit success', async () => { it('redirects to quiz result page if all form values are valid and submit success', async () => {
const createDietProfileApi = () => const createDietProfileApi = () =>
Promise.resolve({ Promise.resolve({
status: 201, status: 201,
...@@ -126,11 +126,11 @@ describe('AllAccessQuestionnaire', () => { ...@@ -126,11 +126,11 @@ describe('AllAccessQuestionnaire', () => {
const submitButton = getByText('Selesai'); const submitButton = getByText('Selesai');
await waitFor(() => fireEvent.press(submitButton)); await waitFor(() => fireEvent.press(submitButton));
const initialPage = getByText(/konsultasi sekarang/i); const quizResultPage = getByText(/Quiz Result/i);
expect(initialPage).toBeTruthy(); expect(quizResultPage).toBeTruthy();
}); });
it('does not redirect to initial page if all form values are valid but submit fails', async () => { it('does not redirect to quiz result page if all form values are valid but submit fails', async () => {
const createDietProfileApi = () => const createDietProfileApi = () =>
Promise.reject({ Promise.reject({
status: 400, status: 400,
...@@ -162,7 +162,11 @@ describe('AllAccessQuestionnaire', () => { ...@@ -162,7 +162,11 @@ describe('AllAccessQuestionnaire', () => {
const submitButton = getByText('Selesai'); const submitButton = getByText('Selesai');
await waitFor(() => fireEvent.press(submitButton)); await waitFor(() => fireEvent.press(submitButton));
const initialPage = queryByText(/konsultasi sekarang/i); const quizResultPage = queryByText(/Quiz Result/i);
expect(initialPage).toBeFalsy(); expect(quizResultPage).toBeFalsy();
});
afterAll(() => {
jest.clearAllMocks();
}); });
}); });
...@@ -44,7 +44,7 @@ const AllAccessQuestionnaire: FC = () => { ...@@ -44,7 +44,7 @@ const AllAccessQuestionnaire: FC = () => {
CACHE_KEYS.dietProfileId, CACHE_KEYS.dietProfileId,
`${response.data?.id}`, `${response.data?.id}`,
); );
navigation.navigate(ROUTES.initial); navigation.navigate(ROUTES.dietelaQuizResult, response.data);
} else { } else {
Toast.show({ Toast.show({
type: 'error', type: 'error',
......
...@@ -7,16 +7,20 @@ export enum RequestMethod { ...@@ -7,16 +7,20 @@ export enum RequestMethod {
DELETE = 'DELETE', DELETE = 'DELETE',
} }
export async function api( export interface Response<T> {
success: boolean;
data?: T;
error?: any;
}
export type ApiResponse<T> = Promise<Response<T>>;
export async function api<T>(
method: RequestMethod = RequestMethod.GET, method: RequestMethod = RequestMethod.GET,
url: string, url: string,
body: object = {}, body: object = {},
headers: object = {}, headers: object = {},
): Promise<{ ): ApiResponse<T> {
success: boolean;
data?: any;
error?: any;
}> {
const requestData: AxiosRequestConfig = { const requestData: AxiosRequestConfig = {
url: `https://dietela-backend.herokuapp.com/${url}`, url: `https://dietela-backend.herokuapp.com/${url}`,
method, method,
......
import { api, RequestMethod } from '../api'; import { api, RequestMethod, ApiResponse } from '../api';
import * as apiUrls from './urls'; import * as apiUrls from './urls';
import { DietProfileRequest } from './models'; import { DietProfileRequest, DietProfileResponse } from './models';
export const createDietProfileApi = (body: DietProfileRequest) => { export const createDietProfileApi = (
body: DietProfileRequest,
): ApiResponse<DietProfileResponse> => {
return api(RequestMethod.POST, apiUrls.dietProfile, body); return api(RequestMethod.POST, apiUrls.dietProfile, body);
}; };
...@@ -20,3 +20,11 @@ export interface DietProfileRequest { ...@@ -20,3 +20,11 @@ export interface DietProfileRequest {
problem_to_solve: number; problem_to_solve: number;
health_problem: number[]; health_problem: number[];
} }
// TODO: Doan
export interface DietelaQuizResult {}
export interface DietProfileResponse extends DietProfileRequest {
id: number;
quiz_result: DietelaQuizResult;
}
...@@ -3,7 +3,6 @@ import { render, RenderOptions } from '@testing-library/react-native'; ...@@ -3,7 +3,6 @@ import { render, RenderOptions } from '@testing-library/react-native';
import { NavigationContainer } from '@react-navigation/native'; import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack'; import { createStackNavigator } from '@react-navigation/stack';
import * as ROUTES from 'constants/routes';
import { navigation } from 'constants/navigation'; import { navigation } from 'constants/navigation';
const Stack = createStackNavigator(); const Stack = createStackNavigator();
...@@ -16,7 +15,7 @@ interface TestProvider { ...@@ -16,7 +15,7 @@ interface TestProvider {
const TestProvider: FC<TestProvider> = ({ route, children }) => { const TestProvider: FC<TestProvider> = ({ route, children }) => {
return ( return (
<NavigationContainer> <NavigationContainer>
<Stack.Navigator initialRouteName={ROUTES.allAccessQuestionnaire}> <Stack.Navigator initialRouteName={route}>
{navigation.map((nav, i) => ( {navigation.map((nav, i) => (
<Stack.Screen <Stack.Screen
key={`nav${i}`} key={`nav${i}`}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment