Fakultas Ilmu Komputer UI

Commit 64396e54 authored by Wulan Mantiri's avatar Wulan Mantiri
Browse files

Merge branch 'fix-test-bugs' into 'staging'

Fix test bugs

See merge request !62
parents 133c5b9e e9f4d153
Pipeline #80238 canceled with stages
in 26 seconds
......@@ -6,7 +6,7 @@
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest --maxWorkers=7 --coverage --watchAll=false --verbose --collectCoverageFrom=\"src/**/*.tsx\"",
"test": "jest --runInBand --coverage --watchAll=false --verbose --collectCoverageFrom=\"src/**/*.tsx\"",
"test-only": "jest --verbose -t",
"lint": "eslint . --ext .ts,.tsx --fix",
"prettify": "prettier --write src",
......
......@@ -4,6 +4,8 @@ import {
clientNavigation,
nutritionistNavigation,
adminNavigation,
onboardingClientNavigation,
unpaidClientNavigation,
} from 'constants/navigation';
import { UserRole, AuthUserResponse } from 'services/auth/models';
import { TransactionStatus } from 'services/payment/models';
......@@ -14,16 +16,19 @@ export const getNavigation = (
) => {
if (isAuthenticated) {
if (user.role === UserRole.CLIENT) {
let initialRoute = ROUTES.clientProfile;
if ([TransactionStatus.UNPAID, null].includes(user.transaction_status)) {
initialRoute = ROUTES.checkout;
} else if (user.transaction_status === TransactionStatus.PENDING) {
initialRoute = ROUTES.paymentResult;
return {
initialRoute: ROUTES.checkout,
navigation: unpaidClientNavigation,
};
} else if (!user.is_finished_onboarding) {
initialRoute = ROUTES.extendedQuestionnaire;
return {
initialRoute: ROUTES.extendedQuestionnaire,
navigation: onboardingClientNavigation,
};
}
return {
initialRoute,
initialRoute: ROUTES.clientProfile,
navigation: clientNavigation,
};
}
......@@ -34,6 +39,7 @@ export const getNavigation = (
navigation: nutritionistNavigation,
};
}
if (user.role === UserRole.ADMIN) {
return {
initialRoute: ROUTES.clientListForAdmin,
......
......@@ -46,6 +46,7 @@ export const styles = StyleSheet.create({
},
button: {
padding: 10,
paddingHorizontal: 0,
backgroundColor: colors.primaryYellow,
},
finishButton: {
......
......@@ -97,22 +97,7 @@ export const publicNavigation: NavRoute[] = [
},
];
export const clientNavigation: NavRoute[] = [
{
name: ROUTES.checkout,
component: Checkout,
header: 'Checkout',
},
{
name: ROUTES.payment,
component: PaymentWebView,
header: 'Pembayaran',
},
{
name: ROUTES.paymentResult,
component: PaymentResult,
},
...navigation,
const defaultClientNavigation: NavRoute[] = [
{
name: ROUTES.extendedQuestionnaire,
component: ExtendedQuestionnaire,
......@@ -147,18 +132,55 @@ export const clientNavigation: NavRoute[] = [
...nav,
name: ROUTES.extendedQuestionnaireById(id),
})),
];
export const onboardingClientNavigation: NavRoute[] = [
...defaultClientNavigation,
{
name: ROUTES.clientProfile,
component: ClientProfile,
header: 'Profil Saya',
},
];
export const unpaidClientNavigation: NavRoute[] = [
{
name: ROUTES.checkout,
component: Checkout,
header: 'Checkout',
},
{
name: ROUTES.payment,
component: PaymentWebView,
header: 'Pembayaran',
},
{
name: ROUTES.paymentResult,
component: PaymentResult,
},
...navigation,
{
name: ROUTES.clientProfile,
component: ClientProfile,
header: 'Profil Saya',
},
...defaultClientNavigation,
];
export const clientNavigation: NavRoute[] = [
{
name: ROUTES.clientProfile,
component: ClientProfile,
header: 'Profil Saya',
},
...defaultClientNavigation,
];
export const nutritionistNavigation: NavRoute[] = [
{
name: ROUTES.clientListForNutritionist,
component: ClientListNutritionist,
header: 'List Klien',
header: 'Daftar Klien',
},
{
name: ROUTES.clientChatNutritionist,
......@@ -186,7 +208,7 @@ export const adminNavigation: NavRoute[] = [
{
name: ROUTES.clientListForAdmin,
component: ClientListAdmin,
header: 'List Klien',
header: 'Daftar Klien',
},
{
name: ROUTES.clientProfileAdmin,
......@@ -211,7 +233,7 @@ export const adminNavigation: NavRoute[] = [
];
export const testNavigation: NavRoute[] = [
...clientNavigation,
...unpaidClientNavigation,
...nutritionistNavigation,
...adminNavigation,
{
......
export { default as useApi } from './useApi';
export { default as useDownloadFiles } from './useDownloadFiles';
export { default as useForm } from './useForm';
export { default as useLinkingEffect } from './useLinkingEffect';
export { default as useSignupEffect } from './useSignupEffect';
import { useEffect } from 'react';
import { Linking } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import * as ROUTES from 'constants/routes';
const useLinkingEffect = () => {
const navigation = useNavigation();
const getQueryParams = (path: string | null) => {
return path
? JSON.parse(
'{"' +
decodeURI(path.replace(/&/g, '","').replace(/[=]/g, '":"')) +
'"}',
)
: {};
};
useEffect(() => {
const navigate = (url: string | null) => {
if (url) {
const splitUrl = url.split('?');
const path = splitUrl[0].split('/').slice(3).join('/');
const queryParams = getQueryParams(splitUrl[1]);
if (path === 'payment') {
navigation.reset({
index: 0,
routes: [{ name: ROUTES.paymentResult, params: queryParams }],
});
}
}
};
const handleOpenURL = (event: { url: string }) => {
navigate(event.url);
};
Linking.addEventListener('url', handleOpenURL);
return () => {
Linking.removeEventListener('url', handleOpenURL);
};
}, [navigation]);
};
export default useLinkingEffect;
import { LoginResponse, UserRole } from 'services/auth/models';
import { TransactionStatus } from 'services/payment/models';
export const validRegistrationValues: { [_: string]: any } = {
name: 'Doan Didinding',
......@@ -32,5 +33,8 @@ export const authResponse: LoginResponse = {
email: validRegistrationValues.email,
name: validRegistrationValues.name,
role: UserRole.CLIENT,
transaction_status: TransactionStatus.UNPAID,
is_finished_onboarding: false,
cart_id: 1,
},
};
......@@ -29,6 +29,7 @@ export const initialUser = {
role: null,
transaction_status: null,
is_finished_onboarding: false,
cart_id: null,
};
export const UserContext = createContext<iUserContext>({
......
......@@ -4,7 +4,7 @@ import * as ROUTES from 'constants/routes';
import axios from 'axios';
import ClientListAdmin from '.';
import { mockClientList } from '__mocks__/clientList';
import { mockClientList } from 'mocks/clientList';
jest.mock('axios');
const mockAxios = axios as jest.Mocked<typeof axios>;
......@@ -18,6 +18,7 @@ describe('ClientListAdmin', () => {
}),
);
render(<ClientListAdmin />, ROUTES.clientListForAdmin);
await waitFor(() => expect(mockAxios.request).toBeCalled());
});
it('shows correct client list', async () => {
......@@ -28,12 +29,11 @@ describe('ClientListAdmin', () => {
}),
);
const { queryByText, queryAllByText } = render(
const { queryByText } = render(
<ClientListAdmin />,
ROUTES.clientListForAdmin,
);
await waitFor(() => expect(queryAllByText(/List Klien/i)).toBeTruthy());
await waitFor(() => expect(mockAxios.request).toBeCalled());
expect(queryByText(mockClientList[0].user.name)).toBeTruthy();
expect(queryByText(/Download Csv/i)).toBeTruthy();
......
......@@ -4,7 +4,7 @@ import * as ROUTES from 'constants/routes';
import axios from 'axios';
import Login from '.';
import { authResponse, validLoginValues } from '__mocks__/auth';
import { authResponse, validLoginValues } from 'mocks/auth';
import { textField } from './schema';
jest.mock('react-native-toast-message');
......
......@@ -11,7 +11,7 @@ import { generateValidationSchema } from 'utils/form';
import { layoutStyles } from 'styles';
import { TextField } from 'components/form';
import { Section } from 'components/layout';
import { useNavigation } from '@react-navigation/core';
import { useNavigation } from '@react-navigation/native';
import * as ROUTES from 'constants/routes';
const isPasswordField = (name: string) => name === 'password';
......
import { useNavigation } from '@react-navigation/core';
import { useNavigation } from '@react-navigation/native';
import { Link } from 'components/core';
import React, { FC } from 'react';
import Login from '../Login';
......
......@@ -11,7 +11,7 @@ import {
authResponse,
validRegistrationValues,
invalidRegistrationValues,
} from '__mocks__/auth';
} from 'mocks/auth';
jest.mock('react-native-toast-message');
jest.mock('axios');
......
import React, { FC, useContext } from 'react';
import { useForm, useSignupEffect } from 'hooks';
import { ScrollView } from 'react-native-gesture-handler';
import { useNavigation, useRoute } from '@react-navigation/core';
import { useNavigation, useRoute } from '@react-navigation/native';
import { BigButton, Link, Toast } from 'components/core';
import { Section } from 'components/layout';
......
......@@ -4,7 +4,7 @@ import * as ROUTES from 'constants/routes';
import axios from 'axios';
import NutritionistAdminLogin from '.';
import { authResponse, validLoginValues } from '__mocks__/auth';
import { authResponse, validLoginValues } from 'mocks/auth';
import { textField } from './schema';
jest.mock('react-native-toast-message');
......
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