Skip to content

Commit

Permalink
#8 - fixes after merged main
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilpiech97 committed Sep 25, 2023
1 parent 2d69d40 commit 5f9cde6
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 75 deletions.
12 changes: 9 additions & 3 deletions app/Http/Controllers/Dashboard/SemesterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Http\Requests\SemesterRequest;
use App\Http\Resources\SemesterResource;
use App\Models\Semester;
use Exception;
use Illuminate\Http\RedirectResponse;
use Inertia\Response;

Expand Down Expand Up @@ -63,9 +64,14 @@ public function destroy(Semester $semester): RedirectResponse

public function toggleActive(Semester $semester, ActivateSemesterAction $activateSemesterAction): RedirectResponse
{
$activateSemesterAction->execute($semester);
try {
$activateSemesterAction->execute($semester);

return redirect()->back()
->with("success", "Semestr aktywny");
return redirect()->back()
->with("success", "Semestr aktywny");
} catch (Exception $e) {
return redirect()->back()
->with("error", "Wystąpił nieoczekiwany problem");
}
}
}
2 changes: 1 addition & 1 deletion database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ class DatabaseSeeder extends Seeder
{
public function run(): void
{
User::factory(1)->create();
User::factory()->create(["email" => "admin@example.com"]);
}
}
4 changes: 0 additions & 4 deletions resources/js/Layouts/DashboardLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { Dialog, DialogPanel, TransitionChild, TransitionRoot } from '@headlessui/vue'
import {
Bars3Icon,
ClockIcon,
BriefcaseIcon,
HomeIcon,
PowerIcon,
Expand All @@ -14,7 +13,6 @@ import {
BookmarkSquareIcon,
MagnifyingGlassIcon,
ClipboardIcon,
CodeBracketSquareIcon,
Cog6ToothIcon,
LockOpenIcon,
} from '@heroicons/vue/24/outline'
Expand Down Expand Up @@ -51,8 +49,6 @@ const navigation = [
{ name: 'Kursy', href: '#', icon: BriefcaseIcon, current: false },
{ name: 'Kierunki i specjalności', href: '#', icon: MagnifyingGlassIcon, current: false },
{ name: 'Semestry', href: '/dashboard/semesters', icon: ClipboardIcon, current: false },
{ name: 'Formy zajęć', href: '#', icon: CodeBracketSquareIcon, current: false },
{ name: 'Tryby studiów', href: '#', icon: ClockIcon, current: false },
],
},
]
Expand Down
50 changes: 28 additions & 22 deletions resources/js/Pages/Dashboard/Semester/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import EmptyState from '@/Shared/Components/EmptyState.vue'
import RemoveModal from '@/Shared/Modals/RemoveModal.vue'
import { ref } from 'vue'
import { Method } from '@inertiajs/inertia'
import ManagementHeader from '../../../Shared/Components/ManagementHeader.vue'
import { Cog6ToothIcon, XCircleIcon, CheckIcon } from '@heroicons/vue/24/outline'
defineProps({
semesters: Object,
Expand All @@ -19,43 +21,47 @@ const semesterToDeleteId = ref(0)

<template>
<DashboardLayout>
<div class="flex justify-between">
<h3 class="text-base font-semibold leading-6 text-gray-900">
Lista semestrów
</h3>
<Button :href="`/dashboard/semesters/create`">
Dodaj
</Button>
</div>
<div v-if="semesters.data.length">
<div v-if="semesters.data.length" class="flex flex-col gap-8">
<ManagementHeader>
<template #header>
Zarządzanie semestrami
</template>
<template #actions>
<span class="hidden sm:block">
<Button :href="`/dashboard/semesters/create`">
Dodaj
</Button>
</span>
</template>
</ManagementHeader>
<TableWrapper class="mt-2">
<template #header>
<TableHeader>
<TableHeader class="w-1/5">
Nazwa
</TableHeader>
<TableHeader>
<TableHeader class="w-1/5">
Status
</TableHeader>
<TableHeader class="sm:w-2/10 w-1/3" />
<TableHeader />
</template>
<template #body>
<TableRow v-for="semester in semesters.data" :key="semester.id">
<TableRow v-for="semester in semesters.data" :key="semester.id" :class="semester.status === 'active' ? 'bg-green-50' : ''">
<TableCell>
{{ semester.name }}
</TableCell>
<TableCell>
{{ semester.status_label }}
</TableCell>
<TableCell class="text-right">
<InertiaLink v-if="semester.status !== 'active'" as="button" :method="Method.POST" :href="`/dashboard/semesters/${semester.id}/activate`">
Aktywuj
</InertiaLink>
<InertiaLink class="ml-3" :href="`/dashboard/semesters/${semester.id}/edit`">
Edycja
</InertiaLink>
<button class="ml-3 text-red-600" @click="[showModal = true, semesterToDeleteId = semester.id]">
Usuń
</button>
<Button v-if="semester.status !== 'active'" :method="Method.POST" :href="`/dashboard/semesters/${semester.id}/activate`">
<CheckIcon class="w-6" />
</Button>
<Button :href="`/dashboard/semesters/${semester.id}/edit`">
<Cog6ToothIcon class="w-6" />
</Button>
<Button class="text-red-600" @click="[showModal = true, semesterToDeleteId = semester.id]">
<XCircleIcon class="w-6" />
</Button>
</TableCell>
</TableRow>
</template>
Expand Down
7 changes: 6 additions & 1 deletion resources/js/Pages/Dashboard/Student/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import TextInput from '@/Shared/Forms/TextInput.vue'
import { useForm } from '@inertiajs/inertia-vue3'
import { Cog6ToothIcon, XCircleIcon } from '@heroicons/vue/24/outline'
import ManagementHeader from '../../../Shared/Components/ManagementHeader.vue'
import SecondaryButton from '../../../Shared/Components/Buttons/SecondaryButton.vue'
const props = defineProps({
students: Object,
Expand Down Expand Up @@ -111,7 +112,11 @@ watch(form, debounce(() => {
<Pagination :pagination="students" />
</div>

<EmptyState v-else class="mt-3" />
<EmptyState v-else class="mt-3">
<SecondaryButton v-if="students.data.length" :href="`/dashboard/students/create`" class="mt-3">
Dodaj studenta
</SecondaryButton>
</EmptyState>
</DashboardLayout>
<RemoveModal :show="showModal" :href="`/dashboard/students/${studentToDeleteId}`" @close="showModal = false" />
</template>
2 changes: 1 addition & 1 deletion resources/js/Shared/Components/EmptyState.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ defineProps({

<template>
<div class="w-full bg-white py-16 text-center sm:rounded-lg">
<slot />
<div class="mt-2 text-gray-600">
<p>
{{ (customTitle ?? 'Brak danych') }}
</p>
</div>
<slot />
</div>
</template>
9 changes: 9 additions & 0 deletions tests/Feature/SemesterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Tests\Feature;

use App\Models\Semester;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Tests\TestCase;
Expand All @@ -13,6 +14,14 @@ class SemesterTest extends TestCase
{
use RefreshDatabase;

protected function setUp(): void
{
parent::setUp();

$this->user = User::factory()->create();
$this->actingAs($this->user);
}

public function testSemesterCanBeCreated(): void
{
$this->assertDatabaseCount("semesters", 0);
Expand Down
71 changes: 28 additions & 43 deletions tests/Feature/StudentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,35 @@

declare(strict_types=1);

namespace Tests\Feature;
namespace Tests\Feature\Frontend;

use App\Models\Student;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Tests\TestCase;

class StudentTest extends TestCase
{
use RefreshDatabase;

protected User $user;

protected function setUp(): void
{
parent::setUp();

$this->user = User::factory([
"email" => "test@example.com",
"password" => Hash::make("password"),
])->create();
$this->user = User::factory()->create();
$this->actingAs($this->user);
}

public function testStudentCanBeCreated(): void
{
$this->assertDatabaseCount("students", 0);

$this
->actingAs($this->user)
->post("/dashboard/students", [
"name" => "Name",
"surname" => "Surname",
"index_number" => "12345",
])->assertSessionHasNoErrors();
$this->post("/dashboard/students", [
"name" => "Name",
"surname" => "Surname",
"index_number" => "12345",
])->assertSessionHasNoErrors();

$this->assertDatabaseCount("students", 1);
}
Expand All @@ -52,13 +45,11 @@ public function testStudentCanBeUpdated(): void
"index_number" => "12345",
]);

$this
->actingAs($this->user)
->patch("/dashboard/students/{$student->id}", [
"name" => "Name",
"surname" => "Surname",
"index_number" => "12345",
])->assertSessionHasNoErrors();
$this->patch("/dashboard/students/{$student->id}", [
"name" => "Name",
"surname" => "Surname",
"index_number" => "12345",
])->assertSessionHasNoErrors();

$this->assertDatabaseHas("students", [
"name" => "Name",
Expand All @@ -72,30 +63,26 @@ public function testStudentCannotBeCreatedWithBusyIndex(): void
Student::factory()->create(["index_number" => "12345"]);
$this->assertDatabaseCount("students", 1);

$this
->actingAs($this->user)
->post("/dashboard/students", [
"name" => "Name",
"surname" => "Surname",
"index_number" => "12345",
])->assertSessionHasErrors("index_number");
$this->post("/dashboard/students", [
"name" => "Name",
"surname" => "Surname",
"index_number" => "12345",
])->assertSessionHasErrors("index_number");

$this->assertDatabaseCount("students", 1);
}

public function testStudentCannotBeCreatedWithInvalidData(): void
{
$this
->actingAs($this->user)
->post("/dashboard/students", [
"name" => Str::random(256),
"surname" => Str::random(256),
"index_number" => Str::random(256),
])->assertSessionHasErrors([
"name",
"surname",
"index_number",
]);
$this->post("/dashboard/students", [
"name" => Str::random(256),
"surname" => Str::random(256),
"index_number" => Str::random(256),
])->assertSessionHasErrors([
"name",
"surname",
"index_number",
]);

$this->assertDatabaseCount("students", 0);
}
Expand All @@ -105,9 +92,7 @@ public function testStudentCanBeDeleted(): void
$student = Student::factory()->create();
$this->assertDatabaseCount("students", 1);

$this
->actingAs($this->user)
->delete("/dashboard/students/{$student->id}");
$this->delete("/dashboard/students/{$student->id}");

$this->assertDatabaseCount("students", 0);
}
Expand Down

0 comments on commit 5f9cde6

Please sign in to comment.