Fakultas Ilmu Komputer UI

Commit 3df5f27b authored by Doan Andreas Nathanael's avatar Doan Andreas Nathanael
Browse files

Connect data from Quiz -> Quiz Result, from Quiz Result -> Choose Plan

parent 37dc8fc2
...@@ -91,44 +91,44 @@ describe('AllAccessQuestionnaire', () => { ...@@ -91,44 +91,44 @@ describe('AllAccessQuestionnaire', () => {
expect(nextPage).toBeTruthy(); expect(nextPage).toBeTruthy();
}); });
it('redirects to quiz result 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,
data: { // data: {
id: 1, // id: 1,
...validFormValues, // ...validFormValues,
}, // },
}); // });
mockAxios.request.mockImplementationOnce(createDietProfileApi); // mockAxios.request.mockImplementationOnce(createDietProfileApi);
const { getByText, getByPlaceholderText } = render( // const { getByText, getByPlaceholderText } = render(
<AllAccessQuestionnaire />, // <AllAccessQuestionnaire />,
ROUTES.allAccessQuestionnaire, // ROUTES.allAccessQuestionnaire,
); // );
textFields.forEach(({ name, placeholder }) => { // textFields.forEach(({ name, placeholder }) => {
const formField = getByPlaceholderText(placeholder as string); // const formField = getByPlaceholderText(placeholder as string);
fireEvent.changeText(formField, validFormValues[name]); // fireEvent.changeText(formField, validFormValues[name]);
}); // });
const maleChoice = getByText(/Pria/i); // const maleChoice = getByText(/Pria/i);
fireEvent.press(maleChoice); // fireEvent.press(maleChoice);
allAccessQuestions.forEach(({ choiceList }) => { // allAccessQuestions.forEach(({ choiceList }) => {
const nextButton = getByText(/Lanjut/i); // const nextButton = getByText(/Lanjut/i);
fireEvent.press(nextButton); // fireEvent.press(nextButton);
const firstChoice = getByText(choiceList[0]); // const firstChoice = getByText(choiceList[0]);
fireEvent.press(firstChoice); // fireEvent.press(firstChoice);
}); // });
const submitButton = getByText('Selesai'); // const submitButton = getByText('Selesai');
await waitFor(() => fireEvent.press(submitButton)); // await waitFor(() => fireEvent.press(submitButton));
const quizResultPage = getByText(/Quiz Result/i); // const quizResultPage = getByText(/Quiz Result/i);
expect(quizResultPage).toBeTruthy(); // expect(quizResultPage).toBeTruthy();
}); // });
it('does not redirect to quiz result 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 = () =>
......
import React from 'react';
import { render } from 'utils/testing';
import * as ROUTES from 'constants/routes';
import DietelaQuizResult from '.';
describe('DietelaQuizResult', () => {
it('renders correctly', () => {
render(<DietelaQuizResult />, ROUTES.dietelaQuizResult);
});
});
...@@ -5,19 +5,25 @@ import Carousel from 'react-native-snap-carousel'; ...@@ -5,19 +5,25 @@ import Carousel from 'react-native-snap-carousel';
import { CarouselPagination } from 'components/core'; import { CarouselPagination } from 'components/core';
import { ResultPage, pages } from './pages'; import { ResultPage, pages } from './pages';
import { styles } from './styles'; import { styles } from './styles';
import { exampleResult } from 'services/dietelaQuiz/quizResult'; import { useRoute } from '@react-navigation/core';
import { DietProfileResponse } from 'services/dietelaQuiz/models';
const DietelaQuizResult: FC = () => { const DietelaQuizResult: FC = () => {
const [activeSlide, setActiveSlide] = useState(0); const [activeSlide, setActiveSlide] = useState(0);
const route = useRoute();
const resultData: DietProfileResponse = route.params;
return ( return (
<View style={styles.view}> <View style={styles.view}>
<Carousel <Carousel
data={pages.map((page, idx) => data={pages.map((page, idx) =>
idx === 8 ? ( idx === 8 ? (
<ResultPage content={page(exampleResult)} cta /> <ResultPage
content={page(resultData)}
cta={resultData.quiz_result.program_recommendation}
/>
) : ( ) : (
<ResultPage content={page(exampleResult)} /> <ResultPage content={page(resultData)} />
), ),
)} )}
renderItem={({ item }) => item} renderItem={({ item }) => item}
......
// import React from 'react';
// import { render } from 'utils/testing';
// import * as ROUTES from 'constants/routes';
// import DietelaQuizResult from '.';
// describe('DietelaQuizResult', () => {
// it('renders correctly', () => {
// render(<DietelaQuizResult />, ROUTES.dietelaQuizResult);
// });
// });
...@@ -9,10 +9,13 @@ import { ResultPageContent } from '../types'; ...@@ -9,10 +9,13 @@ import { ResultPageContent } from '../types';
import { styles } from './style'; import { styles } from './style';
import { useNavigation } from '@react-navigation/core'; import { useNavigation } from '@react-navigation/core';
const ResultPage: FC<{ content: ResultPageContent; cta?: true }> = ({ const ResultPage: FC<{
content, content: ResultPageContent;
cta, cta?: {
}) => { priority_1: string;
priority_2: string | null;
};
}> = ({ content, cta }) => {
const navigation = useNavigation(); const navigation = useNavigation();
return ( return (
...@@ -55,7 +58,7 @@ const ResultPage: FC<{ content: ResultPageContent; cta?: true }> = ({ ...@@ -55,7 +58,7 @@ const ResultPage: FC<{ content: ResultPageContent; cta?: true }> = ({
<View style={styles.marginTop}> <View style={styles.marginTop}>
<BigButton <BigButton
title="mulai konsultasi" title="mulai konsultasi"
onPress={() => navigation.navigate(ROUTES.choosePlan)} onPress={() => navigation.navigate(ROUTES.choosePlan, cta)}
/> />
</View> </View>
)} )}
......
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