diff --git a/App.tsx b/App.tsx index 9471f21..7e4b3f4 100644 --- a/App.tsx +++ b/App.tsx @@ -15,9 +15,10 @@ import MaterialIcon from "react-native-vector-icons/MaterialCommunityIcons"; import { AppDataSource } from "./data-source"; import { settingsRepo } from "./db"; import { emitter } from "./emitter"; -import Routes from "./Routes"; +import AppDrawer from "./AppDrawer"; import { TOAST } from "./toast"; import { ThemeContext } from "./use-theme"; +import AppStack from "./AppStack"; export const CombinedDefaultTheme = { ...NavigationDefaultTheme, @@ -105,7 +106,7 @@ const App = () => { setDarkColor, }} > - + )} diff --git a/Routes.tsx b/AppDrawer.tsx similarity index 77% rename from Routes.tsx rename to AppDrawer.tsx index a7522c2..399dc3a 100644 --- a/Routes.tsx +++ b/AppDrawer.tsx @@ -1,19 +1,19 @@ import { createDrawerNavigator } from "@react-navigation/drawer"; import { IconButton } from "react-native-paper"; -import GraphsPage from "./GraphsPage"; -import { DrawerParamList } from "./drawer-param-list"; -import HomePage from "./HomePage"; -import PlanPage from "./PlanPage"; +import GraphsList from "./GraphsList"; +import InsightsPage from "./InsightsPage"; +import PlanList from "./PlanList"; +import SetList from "./SetList"; import SettingsPage from "./SettingsPage"; import TimerPage from "./TimerPage"; +import WeightList from "./WeightList"; +import WorkoutList from "./WorkoutList"; +import { DrawerParams } from "./drawer-param-list"; import useDark from "./use-dark"; -import WorkoutsPage from "./WorkoutsPage"; -import WeightPage from "./WeightPage"; -import InsightsPage from "./InsightsPage"; -const Drawer = createDrawerNavigator(); +const Drawer = createDrawerNavigator(); -export default function Routes() { +export default function AppDrawer() { const dark = useDark(); return ( @@ -26,24 +26,24 @@ export default function Routes() { > }} /> }} /> , }} /> }} /> }} /> (); + +export default function AppStack() { + return ( + + + + + + + + + + + + + ); +} diff --git a/DrawerHeader.tsx b/DrawerHeader.tsx index 9acbe23..a979394 100644 --- a/DrawerHeader.tsx +++ b/DrawerHeader.tsx @@ -1,7 +1,7 @@ import { DrawerNavigationProp } from "@react-navigation/drawer"; import { useNavigation } from "@react-navigation/native"; import { Appbar, IconButton } from "react-native-paper"; -import { DrawerParamList } from "./drawer-param-list"; +import { DrawerParams } from "./drawer-param-list"; export default function DrawerHeader({ name, @@ -10,7 +10,7 @@ export default function DrawerHeader({ name: string; children?: JSX.Element | JSX.Element[]; }) { - const navigation = useNavigation>(); + const navigation = useNavigation>(); return ( diff --git a/EditPlan.tsx b/EditPlan.tsx index 468b653..1fa8d76 100644 --- a/EditPlan.tsx +++ b/EditPlan.tsx @@ -10,14 +10,15 @@ import { Button, IconButton, Text } from "react-native-paper"; import { MARGIN, PADDING } from "./constants"; import { planRepo, setRepo } from "./db"; import { defaultSet } from "./gym-set"; -import { PlanPageParams } from "./plan-page-params"; import StackHeader from "./StackHeader"; import Switch from "./Switch"; import { DAYS } from "./time"; import AppInput from "./AppInput"; +import { StackParams } from "./AppStack"; +import { DrawerParams } from "./drawer-param-list"; export default function EditPlan() { - const { params } = useRoute>(); + const { params } = useRoute>(); const { plan } = params; const [title, setTitle] = useState(plan?.title); const [days, setDays] = useState( @@ -27,7 +28,10 @@ export default function EditPlan() { plan.workouts ? plan.workouts.split(",") : [] ); const [names, setNames] = useState([]); - const navigation = useNavigation>(); + const { navigate: drawerNavigate } = + useNavigation>(); + const { navigate: stackNavigate } = + useNavigation>(); useEffect(() => { setRepo @@ -95,7 +99,7 @@ export default function EditPlan() { }); if (!first) first = { ...defaultSet, name: workouts[0] }; delete first.id; - navigation.navigate("StartPlan", { plan: newPlan, first }); + stackNavigate("StartPlan", { plan: newPlan, first }); }} icon="play" /> @@ -141,7 +145,7 @@ export default function EditPlan() { icon="content-save" onPress={async () => { await save(); - navigation.navigate("PlanList"); + drawerNavigate("Plans"); }} > Save diff --git a/EditSet.tsx b/EditSet.tsx index b5677eb..38d440f 100644 --- a/EditSet.tsx +++ b/EditSet.tsx @@ -28,15 +28,16 @@ import GymSet, { GYM_SET_DELETED, GYM_SET_UPDATED, } from "./gym-set"; -import { HomePageParams } from "./home-page-params"; import Settings from "./settings"; import StackHeader from "./StackHeader"; import { toast } from "./toast"; +import { DrawerParams } from "./drawer-param-list"; +import { StackParams } from "./AppStack"; export default function EditSet() { - const { params } = useRoute>(); + const { params } = useRoute>(); const { set } = params; - const { navigate } = useNavigation>(); + const { goBack } = useNavigation>(); const [settings, setSettings] = useState({} as Settings); const [name, setName] = useState(set.name); const [reps, setReps] = useState(set.reps?.toString()); @@ -79,7 +80,7 @@ export default function EditSet() { ); const notify = (value: Partial) => { - if (!settings.notify) return navigate("Sets"); + if (!settings.notify) return goBack(); if ( value.weight > set.weight || (value.reps > set.reps && value.weight === set.weight) @@ -121,9 +122,9 @@ export default function EditSet() { const saved = await setRepo.save(newSet); notify(newSet); - if (typeof set.id !== "number") return added(saved); + if (typeof set.id !== "number") added(saved); else emitter.emit(GYM_SET_UPDATED, saved); - navigate("Sets"); + goBack(); }; const changeImage = useCallback(async () => { @@ -160,7 +161,7 @@ export default function EditSet() { const remove = async () => { await setRepo.delete(set.id); emitter.emit(GYM_SET_DELETED); - navigate("Sets"); + goBack(); }; const openMenu = async () => { diff --git a/EditSets.tsx b/EditSets.tsx index cca6fc5..c451b95 100644 --- a/EditSets.tsx +++ b/EditSets.tsx @@ -16,14 +16,15 @@ import { MARGIN, PADDING } from "./constants"; import { setRepo, settingsRepo } from "./db"; import { emitter } from "./emitter"; import GymSet, { GYM_SET_CREATED } from "./gym-set"; -import { HomePageParams } from "./home-page-params"; import Settings from "./settings"; import StackHeader from "./StackHeader"; +import { StackParams } from "./AppStack"; +import { DrawerParams } from "./drawer-param-list"; export default function EditSets() { - const { params } = useRoute>(); + const { params } = useRoute>(); const { ids } = params; - const { navigate } = useNavigation>(); + const { navigate } = useNavigation>(); const [settings, setSettings] = useState({} as Settings); const [name, setName] = useState(""); const [reps, setReps] = useState(""); @@ -63,7 +64,7 @@ export default function EditSets() { if (newImage) update.image = newImage; if (Object.keys(update).length > 0) await setRepo.update(ids, update); emitter.emit(GYM_SET_CREATED); - navigate("Sets"); + navigate("Home"); }; const changeImage = useCallback(async () => { diff --git a/EditWeight.tsx b/EditWeight.tsx index a39aed0..27161e0 100644 --- a/EditWeight.tsx +++ b/EditWeight.tsx @@ -11,20 +11,21 @@ import { useCallback, useRef, useState } from "react"; import { TextInput, View } from "react-native"; import { Button, IconButton } from "react-native-paper"; import AppInput from "./AppInput"; +import { StackParams } from "./AppStack"; import ConfirmDialog from "./ConfirmDialog"; +import StackHeader from "./StackHeader"; import { MARGIN, PADDING } from "./constants"; import { AppDataSource } from "./data-source"; import { getNow, settingsRepo, weightRepo } from "./db"; +import { DrawerParams } from "./drawer-param-list"; import Settings from "./settings"; -import StackHeader from "./StackHeader"; import { toast } from "./toast"; import Weight from "./weight"; -import { WeightPageParams } from "./WeightPage"; export default function EditWeight() { - const { params } = useRoute>(); + const { params } = useRoute>(); const { weight } = params; - const { navigate } = useNavigation>(); + const { navigate } = useNavigation>(); const [settings, setSettings] = useState({} as Settings); const [value, setValue] = useState(weight.value?.toString()); const [unit, setUnit] = useState(weight.unit); @@ -55,7 +56,7 @@ export default function EditWeight() { await weightRepo.save(newWeight); if (settings.notify) await checkWeekly(); - navigate("Weights"); + navigate("Weight"); }; const checkWeekly = async () => { @@ -94,7 +95,7 @@ export default function EditWeight() { const remove = async () => { if (!weight.id) return; await weightRepo.delete(weight.id); - navigate("Weights"); + navigate("Weight"); }; return ( diff --git a/EditWorkout.tsx b/EditWorkout.tsx index da8d2f5..9f94a72 100644 --- a/EditWorkout.tsx +++ b/EditWorkout.tsx @@ -19,10 +19,11 @@ import GymSet, { defaultSet, GYM_SET_CREATED } from "./gym-set"; import Settings from "./settings"; import StackHeader from "./StackHeader"; import { toast } from "./toast"; -import { WorkoutsPageParams } from "./WorkoutsPage"; +import { DrawerParams } from "./drawer-param-list"; +import { StackParams } from "./AppStack"; export default function EditWorkout() { - const { params } = useRoute>(); + const { params } = useRoute>(); const [removeImage, setRemoveImage] = useState(false); const [showRemove, setShowRemove] = useState(false); const [name, setName] = useState(params.gymSet.name); @@ -35,7 +36,7 @@ export default function EditWorkout() { params.gymSet.seconds?.toString() ?? "30" ); const [sets, setSets] = useState(params.gymSet.sets?.toString() ?? "3"); - const { navigate } = useNavigation>(); + const { navigate } = useNavigation>(); const setsRef = useRef(null); const stepsRef = useRef(null); const minutesRef = useRef(null); @@ -64,7 +65,7 @@ export default function EditWorkout() { WHERE workouts LIKE $3`, [params.gymSet.name, name, `%${params.gymSet.name}%`] ); - navigate("WorkoutList", { update: newWorkout }); + navigate("Workouts", { update: newWorkout }); }; const add = async () => { @@ -81,7 +82,7 @@ export default function EditWorkout() { created: now, }); emitter.emit(GYM_SET_CREATED); - navigate("WorkoutList", { reset: new Date().getTime() }); + navigate("Workouts", { reset: new Date().getTime() }); }; const save = async () => { @@ -184,13 +185,18 @@ export default function EditWorkout() { )} - - ); } diff --git a/HomePage.tsx b/HomePage.tsx deleted file mode 100644 index 1732e14..0000000 --- a/HomePage.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import { createStackNavigator } from "@react-navigation/stack"; -import EditSet from "./EditSet"; -import EditSets from "./EditSets"; -import { HomePageParams } from "./home-page-params"; -import SetList from "./SetList"; - -const Stack = createStackNavigator(); - -export default function HomePage() { - return ( - - - - - - ); -} diff --git a/PlanItem.tsx b/PlanItem.tsx index f8790b8..4d69c9a 100644 --- a/PlanItem.tsx +++ b/PlanItem.tsx @@ -10,9 +10,9 @@ import { DARK_RIPPLE, LIGHT_RIPPLE } from "./constants"; import { setRepo } from "./db"; import { defaultSet } from "./gym-set"; import { Plan } from "./plan"; -import { PlanPageParams } from "./plan-page-params"; import { DAYS } from "./time"; import useDark from "./use-dark"; +import { StackParams } from "./AppStack"; export default function PlanItem({ item, @@ -26,7 +26,7 @@ export default function PlanItem({ const [today, setToday] = useState(); const dark = useDark(); const days = useMemo(() => item.days.split(","), [item.days]); - const navigation = useNavigation>(); + const navigation = useNavigation>(); useFocusEffect( useCallback(() => { diff --git a/PlanList.tsx b/PlanList.tsx index 327b81b..44ddda8 100644 --- a/PlanList.tsx +++ b/PlanList.tsx @@ -12,14 +12,14 @@ import DrawerHeader from "./DrawerHeader"; import ListMenu from "./ListMenu"; import Page from "./Page"; import { Plan } from "./plan"; -import { PlanPageParams } from "./plan-page-params"; import PlanItem from "./PlanItem"; +import { StackParams } from "./AppStack"; export default function PlanList() { const [term, setTerm] = useState(""); const [plans, setPlans] = useState(); const [ids, setIds] = useState([]); - const navigation = useNavigation>(); + const navigation = useNavigation>(); const refresh = useCallback(async (value: string) => { console.log(`${PlanList.name}.refresh:`, value); diff --git a/PlanPage.tsx b/PlanPage.tsx deleted file mode 100644 index c22e09d..0000000 --- a/PlanPage.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import { createStackNavigator } from "@react-navigation/stack"; -import EditPlan from "./EditPlan"; -import EditSet from "./EditSet"; -import { PlanPageParams } from "./plan-page-params"; -import PlanList from "./PlanList"; -import StartPlan from "./StartPlan"; -import ViewGraph from "./ViewGraph"; - -const Stack = createStackNavigator(); - -export default function PlanPage() { - return ( - - - - - - - - ); -} diff --git a/SetItem.tsx b/SetItem.tsx index 2999eca..b515508 100644 --- a/SetItem.tsx +++ b/SetItem.tsx @@ -5,9 +5,9 @@ import { Image } from "react-native"; import { List, Text } from "react-native-paper"; import { DARK_RIPPLE, LIGHT_RIPPLE } from "./constants"; import GymSet from "./gym-set"; -import { HomePageParams } from "./home-page-params"; import Settings from "./settings"; import useDark from "./use-dark"; +import { StackParams } from "./AppStack"; export default function SetItem({ item, @@ -21,7 +21,7 @@ export default function SetItem({ setIds: (value: number[]) => void; }) { const dark = useDark(); - const navigation = useNavigation>(); + const navigation = useNavigation>(); const longPress = useCallback(() => { if (ids.length > 0) return; diff --git a/SetList.tsx b/SetList.tsx index 347522c..0416787 100644 --- a/SetList.tsx +++ b/SetList.tsx @@ -18,11 +18,12 @@ import GymSet, { GYM_SET_DELETED, GYM_SET_UPDATED, } from "./gym-set"; -import { HomePageParams } from "./home-page-params"; import ListMenu from "./ListMenu"; import Page from "./Page"; import SetItem from "./SetItem"; import Settings, { SETTINGS } from "./settings"; +import { StackParams } from "./AppStack"; +import { DrawerParams } from "./drawer-param-list"; export default function SetList() { const [refreshing, setRefreshing] = useState(false); @@ -31,8 +32,8 @@ export default function SetList() { const [end, setEnd] = useState(false); const [settings, setSettings] = useState(); const [ids, setIds] = useState([]); - const navigation = useNavigation>(); - const { params } = useRoute>(); + const navigation = useNavigation>(); + const { params } = useRoute>(); const [term, setTerm] = useState(params?.search || ""); const reset = useCallback( diff --git a/SettingsPage.tsx b/SettingsPage.tsx index e4aa143..56865de 100644 --- a/SettingsPage.tsx +++ b/SettingsPage.tsx @@ -9,7 +9,7 @@ import ConfirmDialog from "./ConfirmDialog"; import { MARGIN } from "./constants"; import { AppDataSource } from "./data-source"; import { setRepo, settingsRepo } from "./db"; -import { DrawerParamList } from "./drawer-param-list"; +import { DrawerParams } from "./drawer-param-list"; import DrawerHeader from "./DrawerHeader"; import Input from "./input"; import { darkOptions, lightOptions, themeOptions } from "./options"; @@ -46,7 +46,7 @@ export default function SettingsPage() { const [formatOptions, setFormatOptions] = useState(twelveHours); const [importing, setImporting] = useState(false); const [deleting, setDeleting] = useState(false); - const { reset } = useNavigation>(); + const { reset } = useNavigation>(); const { watch, setValue } = useForm({ defaultValues: () => settingsRepo.findOne({ where: {} }), diff --git a/StartPlan.tsx b/StartPlan.tsx index 50be86b..f6c9f5d 100644 --- a/StartPlan.tsx +++ b/StartPlan.tsx @@ -17,14 +17,14 @@ import { getNow, setRepo, settingsRepo } from "./db"; import { emitter } from "./emitter"; import { fixNumeric } from "./fix-numeric"; import GymSet, { GYM_SET_CREATED } from "./gym-set"; -import { PlanPageParams } from "./plan-page-params"; import Settings from "./settings"; import StackHeader from "./StackHeader"; import StartPlanItem from "./StartPlanItem"; import { toast } from "./toast"; +import { StackParams } from "./AppStack"; export default function StartPlan() { - const { params } = useRoute>(); + const { params } = useRoute>(); const [reps, setReps] = useState(params.first?.reps.toString() || "0"); const [weight, setWeight] = useState(params.first?.weight.toString() || "0"); const [unit, setUnit] = useState(params.first?.unit || "kg"); @@ -35,7 +35,7 @@ export default function StartPlan() { const repsRef = useRef(null); const unitRef = useRef(null); const workouts = useMemo(() => params.plan.workouts.split(","), [params]); - const navigation = useNavigation>(); + const navigation = useNavigation>(); const [selection, setSelection] = useState({ start: 0, diff --git a/StartPlanItem.tsx b/StartPlanItem.tsx index 905b316..f2d1f75 100644 --- a/StartPlanItem.tsx +++ b/StartPlanItem.tsx @@ -3,13 +3,12 @@ import React, { useCallback, useState } from "react"; import { GestureResponderEvent, ListRenderItemInfo, View } from "react-native"; import { List, Menu, RadioButton, useTheme } from "react-native-paper"; import { Like } from "typeorm"; +import { StackParams } from "./AppStack"; import CountMany from "./count-many"; import { getNow, setRepo } from "./db"; +import { DrawerParams } from "./drawer-param-list"; import { emitter } from "./emitter"; -import { GraphsPageParams } from "./GraphsPage"; import { GYM_SET_DELETED } from "./gym-set"; -import { HomePageParams } from "./home-page-params"; -import { PlanPageParams } from "./plan-page-params"; import { toast } from "./toast"; interface Props extends ListRenderItemInfo { @@ -23,11 +22,10 @@ export default function StartPlanItem(props: Props) { const { colors } = useTheme(); const [anchor, setAnchor] = useState({ x: 0, y: 0 }); const [showMenu, setShowMenu] = useState(false); - const { navigate } = useNavigation>(); - const { navigate: navigateHome } = - useNavigation>(); - const { navigate: navigateGraph } = - useNavigation>(); + const { navigate: stackNavigate } = + useNavigation>(); + const { navigate: drawerNavigate } = + useNavigation>(); const undo = useCallback(async () => { const now = await getNow(); @@ -68,18 +66,18 @@ export default function StartPlanItem(props: Props) { }); setShowMenu(false); if (!first) return toast("Nothing to edit."); - navigate("EditSet", { set: first }); - }, [item.name, navigate]); + stackNavigate("EditSet", { set: first }); + }, [item.name, stackNavigate]); const view = useCallback(() => { setShowMenu(false); - navigateHome("Sets", { search: item.name }); - }, [item.name, navigateHome]); + drawerNavigate("Home", { search: item.name }); + }, [item.name, drawerNavigate]); const graph = useCallback(() => { setShowMenu(false); - navigateGraph("ViewGraph", { name: item.name }); - }, [item.name, navigateGraph]); + stackNavigate("ViewGraph", { name: item.name }); + }, [item.name, stackNavigate]); const left = useCallback( () => ( diff --git a/TimerPage.tsx b/TimerPage.tsx index 341c59b..a9629a6 100644 --- a/TimerPage.tsx +++ b/TimerPage.tsx @@ -1,13 +1,13 @@ import { useFocusEffect } from "@react-navigation/native"; import React, { useCallback, useMemo, useState } from "react"; import { Dimensions, NativeModules, View } from "react-native"; -import { Button, FAB, Text, useTheme } from "react-native-paper"; +import { FAB, Text, useTheme } from "react-native-paper"; import { ProgressCircle } from "react-native-svg-charts"; import AppFab from "./AppFab"; +import DrawerHeader from "./DrawerHeader"; import { darkenRgba } from "./colors"; import { MARGIN, PADDING } from "./constants"; import { settingsRepo } from "./db"; -import DrawerHeader from "./DrawerHeader"; import Settings from "./settings"; import useTimer from "./use-timer"; diff --git a/WeightPage.tsx b/WeightPage.tsx index 2a35c5f..ba7573d 100644 --- a/WeightPage.tsx +++ b/WeightPage.tsx @@ -20,8 +20,6 @@ export default function WeightPage() { screenOptions={{ headerShown: false, animationEnabled: false }} > - - ); } diff --git a/WorkoutList.tsx b/WorkoutList.tsx index 62299f3..c609634 100644 --- a/WorkoutList.tsx +++ b/WorkoutList.tsx @@ -18,7 +18,7 @@ import Page from "./Page"; import SetList from "./SetList"; import Settings, { SETTINGS } from "./settings"; import WorkoutItem from "./WorkoutItem"; -import { WorkoutsPageParams } from "./WorkoutsPage"; +import { DrawerParams } from "./drawer-param-list"; export default function WorkoutList() { const [workouts, setWorkouts] = useState(); @@ -28,8 +28,8 @@ export default function WorkoutList() { const [settings, setSettings] = useState(); const [names, setNames] = useState([]); const [refreshing, setRefreshing] = useState(false); - const navigation = useNavigation>(); - const { params } = useRoute>(); + const navigation = useNavigation>(); + const { params } = useRoute>(); const update = (newWorkout: GymSet) => { console.log(`${WorkoutList.name}.update:`, newWorkout); diff --git a/drawer-param-list.ts b/drawer-param-list.ts index d24c3a8..fa04171 100644 --- a/drawer-param-list.ts +++ b/drawer-param-list.ts @@ -1,9 +1,18 @@ -export type DrawerParamList = { - Home: {}; +import GymSet from "./gym-set"; + +export type DrawerParams = { + Home: { + search?: string; + }; Settings: {}; Graphs: {}; Plans: {}; - Workouts: {}; + Workouts: { + clearNames?: boolean; + search?: string; + update?: GymSet; + reset?: number; + }; Timer: {}; Weight: {}; Insights: {}; diff --git a/home-page-params.ts b/home-page-params.ts deleted file mode 100644 index fb521d9..0000000 --- a/home-page-params.ts +++ /dev/null @@ -1,13 +0,0 @@ -import GymSet from "./gym-set"; - -export type HomePageParams = { - Sets: { - search?: string; - }; - EditSet: { - set: GymSet; - }; - EditSets: { - ids: number[]; - }; -}; diff --git a/plan-page-params.ts b/plan-page-params.ts deleted file mode 100644 index c8273bc..0000000 --- a/plan-page-params.ts +++ /dev/null @@ -1,19 +0,0 @@ -import GymSet from "./gym-set"; -import { Plan } from "./plan"; - -export type PlanPageParams = { - PlanList: {}; - EditPlan: { - plan: Plan; - }; - StartPlan: { - plan: Plan; - first?: GymSet; - }; - EditSet: { - set: GymSet; - }; - ViewGraph: { - name: string; - }; -}; diff --git a/route.ts b/route.ts index 8cf58d4..20844dc 100644 --- a/route.ts +++ b/route.ts @@ -1,7 +1,7 @@ -import { DrawerParamList } from "./drawer-param-list"; +import { DrawerParams } from "./drawer-param-list"; export default interface Route { - name: keyof DrawerParamList; + name: keyof DrawerParams; component: React.ComponentType; icon: string; } diff --git a/tests/App.test.tsx b/tests/App.test.tsx deleted file mode 100644 index 31f4e2d..0000000 --- a/tests/App.test.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { render, waitFor } from '@testing-library/react-native' -import React from 'react' -import 'react-native' -import App from '../App' -import Settings from '../settings' - -jest.mock('../db.ts', () => ({ - settingsRepo: { - findOne: () => Promise.resolve({} as Settings), - }, -})) - -jest.mock('../data-source.ts', () => ({ - AppDataSource: { - isInitialized: false, - initialize: jest.fn(), - }, -})) - -test('renders correctly', async () => { - const { getAllByText } = render() - const title = await waitFor(() => getAllByText('Home')) - expect(title.length).toBeGreaterThan(0) -}) diff --git a/tests/EditPlan.test.tsx b/tests/EditPlan.test.tsx deleted file mode 100644 index 0c0ef0d..0000000 --- a/tests/EditPlan.test.tsx +++ /dev/null @@ -1,53 +0,0 @@ -import { createStackNavigator } from '@react-navigation/stack' -import React from 'react' -import 'react-native' -import { render, waitFor } from '@testing-library/react-native' -import EditPlan from '../EditPlan' -import { MockProviders } from '../mock-providers' -import { Plan } from '../plan' -import { PlanPageParams } from '../plan-page-params' - -jest.mock('../db.ts', () => ({ - setRepo: { - createQueryBuilder: () => ({ - select: jest.fn().mockReturnThis(), - distinct: jest.fn().mockReturnThis(), - orderBy: jest.fn().mockReturnThis(), - getRawMany: jest.fn(() => - Promise.resolve([ - { name: 'Bench press' }, - { name: 'Bicep curls' }, - { name: 'Rows' }, - ]) - ), - }), - }, -})) - -test('renders correctly', async () => { - const Stack = createStackNavigator() - const { getByText, getAllByText } = render( - - - - - , - ) - const title = await waitFor(() => getByText(/Edit plan/i)) - expect(title).toBeDefined() - expect(getAllByText('Days').length).toBeGreaterThan(0) - expect(getAllByText('Monday').length).toBeGreaterThan(0) - expect(getAllByText('Workouts').length).toBeGreaterThan(0) - expect(getAllByText('Bench press').length).toBeGreaterThan(0) - expect(getAllByText('Save').length).toBeGreaterThan(0) -}) diff --git a/tests/EditSet.test.tsx b/tests/EditSet.test.tsx deleted file mode 100644 index f0babef..0000000 --- a/tests/EditSet.test.tsx +++ /dev/null @@ -1,89 +0,0 @@ -import { createStackNavigator } from '@react-navigation/stack' -import React from 'react' -import 'react-native' -import { fireEvent, render, waitFor } from '@testing-library/react-native' -import EditSet from '../EditSet' -import GymSet from '../gym-set' -import { HomePageParams } from '../home-page-params' -import { MockProviders } from '../mock-providers' -import SetList from '../SetList' -import Settings from '../settings' - -jest.mock('../db.ts', () => ({ - getNow: () => Promise.resolve(new Date().toISOString()), - setRepo: { - findOne: () => Promise.resolve({}), - save: jest.fn(() => Promise.resolve({})), - }, - settingsRepo: { - findOne: () => - Promise.resolve({ - showUnit: true, - showDate: true, - images: true, - } as Settings), - }, -})) - -test('renders correctly', async () => { - const Stack = createStackNavigator() - const { getByText, getAllByText } = render( - - - - - , - ) - const title = await waitFor(() => getByText('Edit set')) - expect(title).toBeDefined() - expect(getAllByText('Name').length).toBeGreaterThan(0) - expect(getAllByText('Reps').length).toBeGreaterThan(0) - expect(getAllByText('Weight').length).toBeGreaterThan(0) - expect(getAllByText('Unit').length).toBeGreaterThan(0) - expect(getAllByText('Created').length).toBeGreaterThan(0) - expect(getAllByText('Image').length).toBeGreaterThan(0) -}) - -test('saves', async () => { - const Stack = createStackNavigator() - const { getByText, getAllByText, getByTestId } = render( - - - - - - , - ) - const add = await waitFor(() => getByTestId('add')) - fireEvent.press(add) - const names = await waitFor(() => getAllByText('Name')) - fireEvent.changeText(names[0], 'Bench Press') - const reps = await waitFor(() => getAllByText('Reps')) - fireEvent.changeText(reps[0], '10') - const weights = await waitFor(() => getAllByText('Weight')) - fireEvent.changeText(weights[0], '60') - const units = await waitFor(() => getAllByText('Unit')) - fireEvent.changeText(units[0], 'lb') - const save = getByText('Save') - fireEvent.press(save) - const home = await waitFor(() => getByText('Home')) - expect(home).toBeDefined() -}) diff --git a/tests/EditSets.test.tsx b/tests/EditSets.test.tsx deleted file mode 100644 index 9b6ec98..0000000 --- a/tests/EditSets.test.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import { createStackNavigator } from '@react-navigation/stack' -import React from 'react' -import 'react-native' -import { fireEvent, render, waitFor } from '@testing-library/react-native' -import EditSets from '../EditSets' -import { HomePageParams } from '../home-page-params' -import { MockProviders } from '../mock-providers' - -const mockGoBack = jest.fn() - -jest.mock('@react-navigation/native', () => ({ - ...jest.requireActual('@react-navigation/native'), - useNavigation: () => ({ - goBack: mockGoBack, - }), -})) - -jest.mock('../db.ts', () => ({ - getNow: () => Promise.resolve(new Date().toISOString()), - setRepo: { - find: () => - Promise.resolve([ - { name: 'Bench press', reps: 8, weight: 60, id: 1 }, - { name: 'Bench press', reps: 6, weight: 70, id: 2 }, - { name: 'Bench press', reps: 4, weight: 85, id: 3 }, - ]), - update: jest.fn(() => Promise.resolve()), - }, - settingsRepo: { - findOne: () => - Promise.resolve({ - showUnit: true, - showDate: true, - images: true, - }), - }, -})) - -test('renders correctly', async () => { - const Stack = createStackNavigator() - const { getByText, getAllByText } = render( - - - - - , - ) - const title = await waitFor(() => getByText('Edit 3 sets')) - expect(title).toBeDefined() - expect(getAllByText(/Names/i).length).toBeGreaterThan(0) - expect(getAllByText(/Reps/i).length).toBeGreaterThan(0) - expect(getAllByText(/Weights/i).length).toBeGreaterThan(0) - expect(getAllByText(/Units/i).length).toBeGreaterThan(0) - expect(getAllByText(/Image/i).length).toBeGreaterThan(0) -}) - -test('saves', async () => { - const Stack = createStackNavigator() - const { getByText, getAllByText } = render( - - - - - , - ) - const items = await waitFor(() => getAllByText(/Bench press/i)) - fireEvent.changeText(items[0], 'Shoulder press') - const reps = await waitFor(() => getAllByText(/Reps/i)) - fireEvent.changeText(reps[0], '10') - const weights = await waitFor(() => getAllByText(/Weights/i)) - fireEvent.changeText(weights[0], '60') - const units = await waitFor(() => getAllByText(/Units/i)) - fireEvent.changeText(units[0], 'lb') - const save = getByText('Save') - fireEvent.press(save) - await waitFor(() => getByText('Save')) - expect(mockGoBack).toHaveBeenCalled() -}) diff --git a/tests/EditWorkout.test.tsx b/tests/EditWorkout.test.tsx deleted file mode 100644 index 413248c..0000000 --- a/tests/EditWorkout.test.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import { createStackNavigator } from "@react-navigation/stack"; -import React from "react"; -import "react-native"; -import { render, waitFor } from "@testing-library/react-native"; -import EditWorkout from "../EditWorkout"; -import GymSet from "../gym-set"; -import { MockProviders } from "../mock-providers"; -import Settings from "../settings"; -import { WorkoutsPageParams } from "../WorkoutsPage"; - -jest.mock("../db.ts", () => ({ - settingsRepo: { - findOne: () => - Promise.resolve({ - showSets: true, - alarm: true, - } as Settings), - }, -})); - -test("renders correctly", async () => { - const Stack = createStackNavigator(); - const { getByText, getAllByText } = render( - - - - - - ); - const title = await waitFor(() => getByText(/Edit workout/i)); - expect(title).toBeDefined(); - expect(getAllByText(/Name/i).length).toBeGreaterThan(0); - expect(getAllByText(/Sets/i).length).toBeGreaterThan(0); - expect(getAllByText(/Minutes/i).length).toBeGreaterThan(0); - expect(getAllByText(/Seconds/i).length).toBeGreaterThan(0); - expect(getAllByText(/Save/i).length).toBeGreaterThan(0); -}); diff --git a/tests/GraphsPage.test.tsx b/tests/GraphsPage.test.tsx deleted file mode 100644 index 320630c..0000000 --- a/tests/GraphsPage.test.tsx +++ /dev/null @@ -1,67 +0,0 @@ -import React from 'react' -import 'react-native' -import { fireEvent, render, waitFor } from '@testing-library/react-native' -import GraphsPage from '../GraphsPage' -import { MockProviders } from '../mock-providers' -import Settings from '../settings' - -jest.mock('../db.ts', () => ({ - setRepo: { - createQueryBuilder: () => ({ - select: jest.fn().mockReturnThis(), - addSelect: jest.fn().mockReturnThis(), - where: jest.fn().mockReturnThis(), - andWhere: jest.fn().mockReturnThis(), - groupBy: jest.fn().mockReturnThis(), - distinct: jest.fn().mockReturnThis(), - getMany: jest.fn(() => - Promise.resolve([ - { - name: 'Bench press', - weight: 60, - reps: 8, - image: 'https://picsum.photos/id/10/1000/600', - }, - { - name: 'Bicep curls', - weight: 20, - reps: 10, - image: 'https://picsum.photos/id/0/1000/600', - }, - { - name: 'Rows', - weight: 100, - reps: 10, - image: 'https://picsum.photos/id/1/1000/600', - }, - ]) - ), - }), - }, - settingsRepo: { - findOne: () => Promise.resolve({ images: true } as Settings), - }, -})) - -test('renders correctly', async () => { - const { getByText } = render( - - - , - ) - const title = await waitFor(() => getByText('Graphs')) - expect(title).toBeDefined() -}) - -test('searches', async () => { - const { getByDisplayValue, getByPlaceholderText } = render( - - - , - ) - const search = await waitFor(() => getByPlaceholderText('Search')) - expect(search).toBeDefined() - fireEvent.changeText(search, 'SearchValue') - const value = await waitFor(() => getByDisplayValue('SearchValue')) - expect(value).toBeDefined() -}) diff --git a/tests/HomePage.test.tsx b/tests/HomePage.test.tsx deleted file mode 100644 index 560902f..0000000 --- a/tests/HomePage.test.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import React from 'react' -import 'react-native' -import { render, waitFor } from '@testing-library/react-native' -import { Repository } from 'typeorm' -import GymSet from '../gym-set' -import HomePage from '../HomePage' -import { MockProviders } from '../mock-providers' -import Settings from '../settings' - -jest.mock('../db.ts', () => ({ - setRepo: { find: () => Promise.resolve([]) } as Repository, - settingsRepo: { - findOne: () => Promise.resolve({} as Settings), - }, -})) - -test('renders correctly', async () => { - const { getByText } = render( - - - , - ) - const title = await waitFor(() => getByText('Home')) - expect(title).toBeDefined() -}) diff --git a/tests/PlanList.test.tsx b/tests/PlanList.test.tsx deleted file mode 100644 index 08bc32b..0000000 --- a/tests/PlanList.test.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import React from 'react' -import 'react-native' -import { fireEvent, render, waitFor } from '@testing-library/react-native' -import { MockProviders } from '../mock-providers' -import { Plan } from '../plan' -import PlanPage from '../PlanPage' - -jest.mock('../db.ts', () => ({ - setRepo: { - createQueryBuilder: () => ({ - select: jest.fn().mockReturnThis(), - addSelect: jest.fn().mockReturnThis(), - where: jest.fn().mockReturnThis(), - andWhere: jest.fn().mockReturnThis(), - orderBy: jest.fn().mockReturnThis(), - groupBy: jest.fn().mockReturnThis(), - distinct: jest.fn().mockReturnThis(), - getRawMany: jest.fn(() => - Promise.resolve([ - { - name: 'Bench press', - }, - { - name: 'Bicep curls', - }, - { - name: 'Rows', - }, - ]) - ), - }), - }, - planRepo: { - find: () => - Promise.resolve([ - { - days: 'Monday,Tuesday,Wednesday', - workouts: 'Bench press,Side raises, Bicep curls', - id: 1, - }, - { - days: 'Thursday,Friday,Saturday', - workouts: 'Deadlifts,Barbell rows,Pull ups', - id: 2, - }, - ] as Plan[]), - }, -})) - -test('renders correctly', async () => { - const { getByText } = render( - - - , - ) - const title = await waitFor(() => getByText('Plans')) - expect(title).toBeDefined() -}) - -test('adds', async () => { - const { getByTestId, getByText } = render( - - - , - ) - fireEvent.press(await waitFor(() => getByTestId('add'))) - expect(await waitFor(() => getByText('Add plan'))).toBeDefined() -}) diff --git a/tests/PlanPage.test.tsx b/tests/PlanPage.test.tsx deleted file mode 100644 index 7a47aac..0000000 --- a/tests/PlanPage.test.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import React from 'react' -import 'react-native' -import { render, waitFor } from '@testing-library/react-native' -import { Repository } from 'typeorm' -import GymSet from '../gym-set' -import { MockProviders } from '../mock-providers' -import PlanPage from '../PlanPage' -import Settings from '../settings' - -jest.mock('../db.ts', () => ({ - setRepo: { find: () => Promise.resolve([]) } as Repository, - settingsRepo: { - findOne: () => Promise.resolve({} as Settings), - }, -})) - -test('renders correctly', async () => { - const { getByText } = render( - - - , - ) - const title = await waitFor(() => getByText('Plans')) - expect(title).toBeDefined() -}) diff --git a/tests/SettingsPage.test.tsx b/tests/SettingsPage.test.tsx deleted file mode 100644 index 790d5ee..0000000 --- a/tests/SettingsPage.test.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import React from 'react' -import 'react-native' -import { render, waitFor } from '@testing-library/react-native' -import { Repository } from 'typeorm' -import GymSet from '../gym-set' -import { MockProviders } from '../mock-providers' -import Settings from '../settings' -import SettingsPage from '../SettingsPage' - -jest.mock('../db.ts', () => ({ - setRepo: { find: () => Promise.resolve([]) } as Repository, - settingsRepo: { - findOne: () => Promise.resolve({} as Settings), - }, -})) - -test('renders correctly', async () => { - const { getByText, getAllByText } = render( - - - , - ) - const title = await waitFor(() => getByText('Settings')) - expect(title).toBeDefined() - expect(getByText(/timers/i)).toBeDefined() - expect(getByText(/vibrate/i)).toBeDefined() - expect(getByText(/notifications/i)).toBeDefined() - expect(getByText(/images/i)).toBeDefined() - expect(getAllByText(/theme/i).length).toBeGreaterThan(0) -}) diff --git a/tests/StartPlan.test.tsx b/tests/StartPlan.test.tsx deleted file mode 100644 index c088630..0000000 --- a/tests/StartPlan.test.tsx +++ /dev/null @@ -1,100 +0,0 @@ -import { createStackNavigator } from '@react-navigation/stack' -import React from 'react' -import 'react-native' -import { fireEvent, render, waitFor } from '@testing-library/react-native' -import GymSet from '../gym-set' -import { MockProviders } from '../mock-providers' -import { Plan } from '../plan' -import { PlanPageParams } from '../plan-page-params' -import Settings from '../settings' -import StartPlan from '../StartPlan' - -jest.mock('../best.service.ts', () => ({ - getBestSet: () => Promise.resolve({}), -})) - -jest.mock('../db.ts', () => ({ - getNow: () => Promise.resolve(new Date().toISOString()), - setRepo: { - findOne: () => Promise.resolve({}), - save: () => Promise.resolve(), - }, - settingsRepo: { - findOne: () => - Promise.resolve({ - showUnit: true, - showDate: true, - images: true, - } as Settings), - }, -})) - -jest.mock('../data-source.ts', () => ({ - AppDataSource: { - manager: { - query: jest.fn(() => - Promise.resolve([ - { name: 'Bench', total: 0 }, - { name: 'Rows', total: 0 }, - { name: 'Curls', total: 0 }, - ]) - ), - }, - }, -})) - -test('renders correctly', async () => { - const Stack = createStackNavigator() - const { getByText, getAllByText } = render( - - - - - , - ) - const title = await waitFor(() => getByText(/Monday/i)) - expect(title).toBeDefined() - expect(getAllByText('Reps').length).toBeGreaterThan(0) - expect(getAllByText('Weight').length).toBeGreaterThan(0) - expect(getAllByText('Unit').length).toBeGreaterThan(0) - expect(getAllByText('Bench').length).toBeGreaterThan(0) - expect(getAllByText('Rows').length).toBeGreaterThan(0) - expect(getAllByText('Curls').length).toBeGreaterThan(0) - expect(getAllByText('Save').length).toBeGreaterThan(0) -}) - -test('saves', async () => { - const Stack = createStackNavigator() - const { getByText } = render( - - - - - , - ) - const save = await waitFor(() => getByText('Save')) - expect(save).toBeDefined() - fireEvent.press(save) - const save2 = await waitFor(() => getByText('Save')) - expect(save2).toBeDefined() -}) diff --git a/tests/TimerPage.test.tsx b/tests/TimerPage.test.tsx deleted file mode 100644 index 755b78f..0000000 --- a/tests/TimerPage.test.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import React from 'react' -import 'react-native' -import { render, waitFor } from '@testing-library/react-native' -import { Repository } from 'typeorm' -import GymSet from '../gym-set' -import { MockProviders } from '../mock-providers' -import Settings from '../settings' -import TimerPage from '../TimerPage' - -jest.mock('../db.ts', () => ({ - setRepo: { find: () => Promise.resolve([]) } as Repository, - settingsRepo: { - findOne: () => Promise.resolve({} as Settings), - }, -})) - -test('renders correctly', async () => { - const { getByText } = render( - - - , - ) - const title = await waitFor(() => getByText('Timer')) - expect(title).toBeDefined() -}) diff --git a/tests/ViewGraph.test.tsx b/tests/ViewGraph.test.tsx deleted file mode 100644 index 073b11c..0000000 --- a/tests/ViewGraph.test.tsx +++ /dev/null @@ -1,141 +0,0 @@ -import React from 'react' -import 'react-native' -import { fireEvent, render, waitFor } from '@testing-library/react-native' -import GraphsPage from '../GraphsPage' -import { MockProviders } from '../mock-providers' -import Settings from '../settings' - -jest.mock('../db.ts', () => ({ - setRepo: { - createQueryBuilder: () => ({ - select: jest.fn().mockReturnThis(), - addSelect: jest.fn().mockReturnThis(), - where: jest.fn().mockReturnThis(), - andWhere: jest.fn().mockReturnThis(), - groupBy: jest.fn().mockReturnThis(), - addGroupBy: jest.fn().mockReturnThis(), - distinct: jest.fn().mockReturnThis(), - getRawMany: jest.fn(() => - Promise.resolve([ - { - name: 'Bench press', - value: 16, - created: '2023-01-05T03:58:02.565Z', - weight: 18, - }, - { - name: 'Bench press', - value: 48, - created: '2022-01-05T03:58:02.565Z', - weight: 48, - }, - { - name: 'Bench press', - value: 30, - created: '2021-01-05T03:58:02.565Z', - weight: 28, - }, - ]) - ), - getMany: jest.fn(() => - Promise.resolve([ - { - name: 'Bench press', - weight: 60, - reps: 8, - image: 'https://picsum.photos/id/10/1000/600', - }, - { - name: 'Bicep curls', - weight: 20, - reps: 10, - image: 'https://picsum.photos/id/0/1000/600', - }, - { - name: 'Rows', - weight: 100, - reps: 10, - image: 'https://picsum.photos/id/1/1000/600', - }, - ]) - ), - }), - }, - settingsRepo: { - findOne: () => Promise.resolve({ images: true } as Settings), - }, -})) - -test('renders correctly', async () => { - const { getAllByText, getByText } = render( - - - , - ) - const benches = await waitFor(() => getAllByText('Bench press')) - expect(benches).toBeDefined() - fireEvent.press(benches[0]) - const bench = await waitFor(() => getByText('Metric')) - expect(bench).toBeDefined() - expect(getByText('Period')).toBeDefined() -}) - -test('volume', async () => { - const { getAllByText, getByText } = render( - - - , - ) - const benches = await waitFor(() => getAllByText('Bench press')) - expect(benches).toBeDefined() - fireEvent.press(benches[0]) - const bestWeight = await waitFor(() => getByText('Best weight')) - fireEvent.press(bestWeight) - const volume = await waitFor(() => getByText('Volume')) - fireEvent.press(volume) - expect(await waitFor(() => getByText('Volume'))).toBeDefined() -}) - -test('one rep max', async () => { - const { getAllByText, getByText } = render( - - - , - ) - const benches = await waitFor(() => getAllByText(/Bench press/i)) - expect(benches).toBeDefined() - fireEvent.press(benches[0]) - const bestWeight = await waitFor(() => getByText(/Best weight/i)) - fireEvent.press(bestWeight) - const volume = await waitFor(() => getByText(/One rep max/i)) - fireEvent.press(volume) - expect(await waitFor(() => getByText(/One rep max/i))).toBeDefined() -}) - -test('this week', async () => { - const { getAllByText, getByText } = render( - - - , - ) - const benches = await waitFor(() => getAllByText(/Bench press/i)) - expect(benches).toBeDefined() - fireEvent.press(benches[0]) - fireEvent.press(await waitFor(() => getByText(/This month/i))) - fireEvent.press(await waitFor(() => getByText(/This week/i))) - expect(await waitFor(() => getByText(/This week/i))).toBeDefined() -}) - -test('this year', async () => { - const { getAllByText, getByText } = render( - - - , - ) - const benches = await waitFor(() => getAllByText(/Bench press/i)) - expect(benches).toBeDefined() - fireEvent.press(benches[0]) - fireEvent.press(await waitFor(() => getByText(/This month/i))) - fireEvent.press(await waitFor(() => getByText(/This year/i))) - expect(await waitFor(() => getByText(/This year/i))).toBeDefined() -}) diff --git a/tests/WorkoutsPage.test.tsx b/tests/WorkoutsPage.test.tsx deleted file mode 100644 index 735bae4..0000000 --- a/tests/WorkoutsPage.test.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import React from 'react' -import 'react-native' -import { render, waitFor } from '@testing-library/react-native' -import { Repository } from 'typeorm' -import GymSet from '../gym-set' -import { MockProviders } from '../mock-providers' -import Settings from '../settings' -import WorkoutsPage from '../WorkoutsPage' - -jest.mock('../db.ts', () => ({ - setRepo: { find: () => Promise.resolve([]) } as Repository, - settingsRepo: { - findOne: () => Promise.resolve({} as Settings), - }, -})) - -test('renders correctly', async () => { - const { getByText } = render( - - - , - ) - const title = await waitFor(() => getByText('Workouts')) - expect(title).toBeDefined() -})