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', () => {
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 = () =>
Promise.resolve({
status: 201,
......@@ -126,11 +126,11 @@ describe('AllAccessQuestionnaire', () => {
const submitButton = getByText('Selesai');
await waitFor(() => fireEvent.press(submitButton));
const initialPage = getByText(/konsultasi sekarang/i);
expect(initialPage).toBeTruthy();
const quizResultPage = getByText(/Quiz Result/i);
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 = () =>
Promise.reject({
status: 400,
......@@ -162,7 +162,11 @@ describe('AllAccessQuestionnaire', () => {
const submitButton = getByText('Selesai');
await waitFor(() => fireEvent.press(submitButton));
const initialPage = queryByText(/konsultasi sekarang/i);
expect(initialPage).toBeFalsy();
const quizResultPage = queryByText(/Quiz Result/i);
expect(quizResultPage).toBeFalsy();
});
afterAll(() => {
jest.clearAllMocks();
});
});
......@@ -44,7 +44,7 @@ const AllAccessQuestionnaire: FC = () => {
CACHE_KEYS.dietProfileId,
`${response.data?.id}`,
);
navigation.navigate(ROUTES.initial);
navigation.navigate(ROUTES.dietelaQuizResult, response.data);
} else {
Toast.show({
type: 'error',
......
......@@ -7,16 +7,20 @@ export enum RequestMethod {
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,
url: string,
body: object = {},
headers: object = {},
): Promise<{
success: boolean;
data?: any;
error?: any;
}> {
): ApiResponse<T> {
const requestData: AxiosRequestConfig = {
url: `https://dietela-backend.herokuapp.com/${url}`,
method,
......
import { api, RequestMethod } from '../api';
import { api, RequestMethod, ApiResponse } from '../api';
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);
};
......@@ -20,3 +20,11 @@ export interface DietProfileRequest {
problem_to_solve: 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';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import * as ROUTES from 'constants/routes';
import { navigation } from 'constants/navigation';
const Stack = createStackNavigator();
......@@ -16,7 +15,7 @@ interface TestProvider {
const TestProvider: FC<TestProvider> = ({ route, children }) => {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName={ROUTES.allAccessQuestionnaire}>
<Stack.Navigator initialRouteName={route}>
{navigation.map((nav, i) => (
<Stack.Screen
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