Adjusted crud tests + added auth tests

This commit is contained in:
Teodor
2026-04-30 22:21:56 +02:00
parent 545027a766
commit 3dcd392cd3
19 changed files with 578 additions and 313 deletions

View File

@@ -6,13 +6,14 @@ import type { Task } from '@/lib/types';
import { Session } from '@supabase/supabase-js';
import { router, Stack, useFocusEffect, useLocalSearchParams } from 'expo-router';
import { useCallback, useEffect, useState } from 'react';
import { Alert, Pressable, Text, View } from 'react-native';
import { ActivityIndicator, Alert, Pressable, Text, View } from 'react-native';
export default function ViewDetailsTask() {
const { tId } = useLocalSearchParams<{ tId: string }>();
const [task, SetTask] = useState<Task | null>(null);
const [session, SetSession] = useState<Session | null>(null);
const [isLoading, SetIsLoading] = useState(false);
const [contextMeta, setContextMeta] = useState({
subjectTitle: 'No Subject',
assignmentTitle: 'No Assignment',
@@ -30,11 +31,15 @@ export default function ViewDetailsTask() {
}, []);
const GetTask = async (taskId: string) => {
SetIsLoading(true);
const { data, error } = await supabase
.from('tasks')
.select('*')
.eq('tId', taskId)
.single();
SetIsLoading(false);
if (error || !data) {
Alert.alert('Task could not be fetched, please try again');
@@ -44,12 +49,16 @@ export default function ViewDetailsTask() {
SetTask(data);
if (data.aId) {
SetIsLoading(true);
const { data: assignmentData, error: assignmentError } = await supabase
.from('assignments')
.select('title, sId')
.eq('aId', data.aId)
.single();
SetIsLoading(false);
if (assignmentError || !assignmentData) {
setContextMeta({
subjectTitle: 'Unknown Subject',
@@ -60,12 +69,16 @@ export default function ViewDetailsTask() {
}
if (assignmentData.sId) {
SetIsLoading(true);
const { data: subjectData, error: subjectError } = await supabase
.from('subjects')
.select('title, color')
.eq('sId', assignmentData.sId)
.single();
SetIsLoading(false);
if (subjectError || !subjectData) {
setContextMeta({
subjectTitle: 'Unknown Subject',
@@ -135,6 +148,14 @@ export default function ViewDetailsTask() {
const colorSet = getSubjectColorSet(contextMeta.subjectColor);
if (isLoading) {
return (
<View className="flex-1 items-center justify-center bg-app-bg">
<ActivityIndicator size="large" />
</View>
);
}
if (!task) {
return (
<View className="flex-1 bg-app-bg px-5 pt-6">
@@ -272,7 +293,7 @@ export default function ViewDetailsTask() {
className="mr-3 flex-1 items-center justify-center rounded-2xl border border-app-border bg-app-subtle py-3"
onPress={() =>
router.push({
pathname: '/task/upsertTask',
pathname: '../task/upsertTask',
params: { tId: task.tId },
})
}
@@ -283,6 +304,7 @@ export default function ViewDetailsTask() {
</Pressable>
<Pressable
testID="delete-task-button"
className="flex-1 items-center justify-center rounded-2xl border border-app-border bg-app-surface py-3"
onPress={() => DeleteTask(task.tId)}
>