Skip to content

Commit 4824a7b

Browse files
author
Tony Lea
committed
Adding updates to all the tests
1 parent 692de47 commit 4824a7b

File tree

13 files changed

+351
-37
lines changed

13 files changed

+351
-37
lines changed

app/login/page.tsx

Lines changed: 0 additions & 32 deletions
This file was deleted.

resources/js/Components/AppSidebar.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
Github,
66
BookOpenText,
77
AppWindowMac,
8-
Rocket,
8+
Rocket
99
} from "lucide-react"
1010

1111
import { NavMain } from "@/Components/NavMain"
@@ -20,6 +20,9 @@ import {
2020
SidebarMenu,
2121
SidebarMenuButton,
2222
SidebarMenuItem,
23+
SidebarGroup,
24+
SidebarGroupLabel,
25+
SidebarGroupContent
2326
} from "@/components/ui/sidebar"
2427
import ApplicationLogo from "./ApplicationLogo"
2528

@@ -85,7 +88,7 @@ const data = {
8588
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
8689
return (
8790
// Sidebar variant can be "sidebar", "floating" or "inset"
88-
<Sidebar variant="inset" {...props}>
91+
<Sidebar variant="inset" {...props} collapsible="icon">
8992
<SidebarHeader>
9093
<SidebarMenu>
9194
<SidebarMenuItem>
@@ -105,9 +108,9 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
105108
</SidebarHeader>
106109
<SidebarContent>
107110
<NavMain items={data.navMain} />
108-
<NavSecondary items={data.navSecondary} className="mt-auto" />
109111
</SidebarContent>
110112
<SidebarFooter>
113+
<NavSecondary items={data.navSecondary} className="mt-auto" />
111114
<NavUser user={data.user} />
112115
</SidebarFooter>
113116
</Sidebar>

resources/js/Pages/Settings/Layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default function Layout({
6868
<Separator className="my-6" />
6969
<div className="flex flex-col space-y-8 lg:flex-row lg:space-x-12 lg:space-y-0">
7070
<aside className="lg:w-1/5">
71-
<nav className="hidden space-x-2 flex-col space-x-0 space-y-1 lg:flex">
71+
<nav className="hidden flex-col space-x-0 space-y-1 lg:flex">
7272
{sidebarNavItems.map((item) => (
7373
<Button size="sm" key={item.href} variant="ghost"
7474
asChild
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
use App\Models\User;
4+
5+
test('login screen can be rendered', function () {
6+
$response = $this->get('/login');
7+
8+
$response->assertStatus(200);
9+
});
10+
11+
test('users can authenticate using the login screen', function () {
12+
$user = User::factory()->create();
13+
14+
$response = $this->post('/login', [
15+
'email' => $user->email,
16+
'password' => 'password',
17+
]);
18+
19+
$this->assertAuthenticated();
20+
$response->assertRedirect(route('dashboard', absolute: false));
21+
});
22+
23+
test('users can not authenticate with invalid password', function () {
24+
$user = User::factory()->create();
25+
26+
$this->post('/login', [
27+
'email' => $user->email,
28+
'password' => 'wrong-password',
29+
]);
30+
31+
$this->assertGuest();
32+
});
33+
34+
test('users can logout', function () {
35+
$user = User::factory()->create();
36+
37+
$response = $this->actingAs($user)->post('/logout');
38+
39+
$this->assertGuest();
40+
$response->assertRedirect('/');
41+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
use App\Models\User;
4+
use Illuminate\Auth\Events\Verified;
5+
use Illuminate\Support\Facades\Event;
6+
use Illuminate\Support\Facades\URL;
7+
8+
test('email verification screen can be rendered', function () {
9+
$user = User::factory()->unverified()->create();
10+
11+
$response = $this->actingAs($user)->get('/verify-email');
12+
13+
$response->assertStatus(200);
14+
});
15+
16+
test('email can be verified', function () {
17+
$user = User::factory()->unverified()->create();
18+
19+
Event::fake();
20+
21+
$verificationUrl = URL::temporarySignedRoute(
22+
'verification.verify',
23+
now()->addMinutes(60),
24+
['id' => $user->id, 'hash' => sha1($user->email)]
25+
);
26+
27+
$response = $this->actingAs($user)->get($verificationUrl);
28+
29+
Event::assertDispatched(Verified::class);
30+
expect($user->fresh()->hasVerifiedEmail())->toBeTrue();
31+
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
32+
});
33+
34+
test('email is not verified with invalid hash', function () {
35+
$user = User::factory()->unverified()->create();
36+
37+
$verificationUrl = URL::temporarySignedRoute(
38+
'verification.verify',
39+
now()->addMinutes(60),
40+
['id' => $user->id, 'hash' => sha1('wrong-email')]
41+
);
42+
43+
$this->actingAs($user)->get($verificationUrl);
44+
45+
expect($user->fresh()->hasVerifiedEmail())->toBeFalse();
46+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use App\Models\User;
4+
5+
test('confirm password screen can be rendered', function () {
6+
$user = User::factory()->create();
7+
8+
$response = $this->actingAs($user)->get('/confirm-password');
9+
10+
$response->assertStatus(200);
11+
});
12+
13+
test('password can be confirmed', function () {
14+
$user = User::factory()->create();
15+
16+
$response = $this->actingAs($user)->post('/confirm-password', [
17+
'password' => 'password',
18+
]);
19+
20+
$response->assertRedirect();
21+
$response->assertSessionHasNoErrors();
22+
});
23+
24+
test('password is not confirmed with invalid password', function () {
25+
$user = User::factory()->create();
26+
27+
$response = $this->actingAs($user)->post('/confirm-password', [
28+
'password' => 'wrong-password',
29+
]);
30+
31+
$response->assertSessionHasErrors();
32+
});
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
use App\Models\User;
4+
use Illuminate\Auth\Notifications\ResetPassword;
5+
use Illuminate\Support\Facades\Notification;
6+
7+
test('reset password link screen can be rendered', function () {
8+
$response = $this->get('/forgot-password');
9+
10+
$response->assertStatus(200);
11+
});
12+
13+
test('reset password link can be requested', function () {
14+
Notification::fake();
15+
16+
$user = User::factory()->create();
17+
18+
$this->post('/forgot-password', ['email' => $user->email]);
19+
20+
Notification::assertSentTo($user, ResetPassword::class);
21+
});
22+
23+
test('reset password screen can be rendered', function () {
24+
Notification::fake();
25+
26+
$user = User::factory()->create();
27+
28+
$this->post('/forgot-password', ['email' => $user->email]);
29+
30+
Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
31+
$response = $this->get('/reset-password/'.$notification->token);
32+
33+
$response->assertStatus(200);
34+
35+
return true;
36+
});
37+
});
38+
39+
test('password can be reset with valid token', function () {
40+
Notification::fake();
41+
42+
$user = User::factory()->create();
43+
44+
$this->post('/forgot-password', ['email' => $user->email]);
45+
46+
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
47+
$response = $this->post('/reset-password', [
48+
'token' => $notification->token,
49+
'email' => $user->email,
50+
'password' => 'password',
51+
'password_confirmation' => 'password',
52+
]);
53+
54+
$response
55+
->assertSessionHasNoErrors()
56+
->assertRedirect(route('login'));
57+
58+
return true;
59+
});
60+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
test('registration screen can be rendered', function () {
4+
$response = $this->get('/register');
5+
6+
$response->assertStatus(200);
7+
});
8+
9+
test('new users can register', function () {
10+
$response = $this->post('/register', [
11+
'name' => 'Test User',
12+
'email' => '[email protected]',
13+
'password' => 'password',
14+
'password_confirmation' => 'password',
15+
]);
16+
17+
$this->assertAuthenticated();
18+
$response->assertRedirect(route('dashboard', absolute: false));
19+
});

tests/Feature/DashboardTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
use App\Models\User;
4+
5+
test('guests are redirected to the login page', function () {
6+
$response = $this->get('/dashboard');
7+
$response->assertRedirect('/login');
8+
});
9+
10+
11+
test('authenticated users can visit the dashboard', function () {
12+
$user = User::factory()->create();
13+
$this->actingAs($user);
14+
15+
$response = $this->get('/dashboard');
16+
$response->assertStatus(200);
17+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use App\Models\User;
4+
5+
test('user can delete their account', function () {
6+
$user = User::factory()->create();
7+
8+
$response = $this
9+
->actingAs($user)
10+
->delete('/settings/delete', [
11+
'password' => 'password',
12+
]);
13+
14+
$response
15+
->assertSessionHasNoErrors()
16+
->assertRedirect('/');
17+
18+
$this->assertGuest();
19+
$this->assertNull($user->fresh());
20+
});
21+
22+
test('correct password must be provided to delete account', function () {
23+
$user = User::factory()->create();
24+
25+
$response = $this
26+
->actingAs($user)
27+
->from('/settings/delete')
28+
->delete('/settings/delete', [
29+
'password' => 'wrong-password',
30+
]);
31+
32+
$response
33+
->assertSessionHasErrors('password')
34+
->assertRedirect('/settings/delete');
35+
36+
$this->assertNotNull($user->fresh());
37+
});

0 commit comments

Comments
 (0)