Skip to content

Commit 2d80eea

Browse files
committed
wip
1 parent e245ab7 commit 2d80eea

File tree

7 files changed

+150
-105
lines changed

7 files changed

+150
-105
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Livewire\Components\Slideovers;
6+
7+
use Illuminate\Contracts\View\View;
8+
use Livewire\Component;
9+
10+
final class DiscussionForm extends Component
11+
{
12+
public function render(): View
13+
{
14+
return view('livewire.components.slideovers.discussion-form');
15+
}
16+
}

lang/fr/pages/discussion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'empty' => 'Discussions sans commentaires',
1313
'empty_description' => 'Les discussions / sujets qui n’ont pas encore eu de commentaires. Soyez le premier à apporter votre contribution.',
1414
'total_answer' => 'total réponses',
15-
'new_discussion' => 'Nouveau discussion',
15+
'new_discussion' => 'Lancer',
1616
'filter' => [
1717
'recent' => 'Récent',
1818
'popular' => 'Populaire',
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
{{-- Close your eyes. Count to one. That is how long forever feels. --}}
3+
</div>

resources/views/livewire/pages/discussions/index.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="flex items-center justify-between gap-10">
55
<x-scrollable-content
66
class="w-2/3 bg-white rounded-xl ring-1 ring-gray-200/60 dark:bg-gray-800 dark:ring-white/10"
7-
tab-class="pb-0"
7+
tab-class="!pb-0"
88
>
99
<div class="border-b border-gray-200">
1010
<nav class="flex items-center space-x-3">
@@ -30,7 +30,7 @@ class="w-2/3 bg-white rounded-xl ring-1 ring-gray-200/60 dark:bg-gray-800 dark:r
3030
<div class="flex items-center gap-2">
3131
<x-filament::dropdown>
3232
<x-slot name="trigger">
33-
<button type="button" class="inline-flex items-center -mx-2 p-2 rounded-lg bg-white text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-700 dark:text-gray-400 dark:bg-gray-800 ring-1 ring-gray-200/80 dark:ring-white/20">
33+
<button type="button" class="inline-flex items-center p-2 rounded-lg bg-white text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-700 dark:text-gray-400 dark:bg-gray-800 ring-1 ring-gray-200/80 dark:ring-white/20">
3434
<x-untitledui-filter-funnel class="size-5" stroke-width="1.5" aria-hidden="true" />
3535
</button>
3636
</x-slot>

tests/CreatesUsers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
trait CreatesUsers
1010
{
11-
protected function login(array $attributes = []): User
11+
public function login(array $attributes = []): User
1212
{
1313
$user = $this->createUser($attributes);
1414

@@ -17,12 +17,12 @@ protected function login(array $attributes = []): User
1717
return $user;
1818
}
1919

20-
protected function loginAs(User $user): void
20+
public function loginAs(User $user): void
2121
{
2222
$this->be($user);
2323
}
2424

25-
protected function createUser(array $attributes = []): User
25+
public function createUser(array $attributes = []): User
2626
{
2727
return User::factory()->create(array_merge([
2828
'name' => 'John Doe',
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use App\Livewire\Components\Slideovers\DiscussionForm;
6+
use Livewire\Livewire;
7+
8+
/**
9+
* @var \Tests\TestCase $this
10+
*/
11+
describe(DiscussionForm::class, function (): void {
12+
it('return redirect to unauthenticated user', function (): void {
13+
Livewire::test(DiscussionForm::class)
14+
->assertMovedPermanently();
15+
});
16+
17+
it('render the component when authenticated user', function (): void {
18+
$this->login();
19+
20+
Livewire::test(DiscussionForm::class)
21+
->assertSuccessful();
22+
});
23+
})->group('discussion');

tests/Feature/Livewire/Components/Slideovers/ThreadFormTest.php

Lines changed: 102 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -14,103 +14,106 @@
1414
Notification::fake();
1515
});
1616

17-
it('return redirect to unauthenticated user', function (): void {
18-
Livewire::test(ThreadForm::class)
19-
->assertStatus(302);
20-
})->group('thread');
21-
22-
it('render the component when authenticated user', function (): void {
23-
$this->login();
24-
25-
Livewire::test(ThreadForm::class)
26-
->assertStatus(200);
27-
})->group('thread');
28-
29-
it('validate forms input', function (): void {
30-
$this->login();
31-
32-
Livewire::test(ThreadForm::class)
33-
->fillForm([
34-
'title' => '',
35-
'body' => '',
36-
'channels' => [],
37-
])
38-
->call('save')
39-
->assertHasFormErrors([
40-
'title' => ['required'],
41-
'body' => ['required'],
42-
]);
43-
})->group('thread');
44-
45-
it('validate channels can extends 3 when create a thread', function (): void {
46-
$this->login();
47-
48-
Livewire::test(ThreadForm::class)
49-
->fillForm([
50-
'title' => 'I have a question about laravel Cameroun',
51-
'body' => 'this is my kind body',
52-
'channels' => ['laravel', 'php', 'tailwind', 'gaming'],
53-
])
54-
->call('save')
55-
->assertHasFormErrors([
56-
'channels' => ['max'],
57-
]);
58-
})->group('thread');
59-
60-
it('user can create a new thread', function (): void {
61-
$user = $this->login();
62-
$channels = Channel::factory()->count(3)->create();
63-
64-
Livewire::test(ThreadForm::class)
65-
->fillForm([
66-
'title' => 'I have a question about laravel Cameroun',
67-
'body' => 'this is my kind body',
68-
'channels' => $channels->pluck('id')->toArray(),
69-
])
70-
->call('save')
71-
->assertHasNoFormErrors();
72-
73-
$thread = Thread::query()->first();
74-
75-
expect($thread?->user)->toBeInstanceOf(User::class)
76-
->and($thread?->user->is($user))
77-
->toBeTrue();
78-
})->group('thread');
79-
80-
it('user cannot create thread with and unverified email address', function (): void {
81-
$user = $this->createUser(['email_verified_at' => null]);
82-
$channels = Channel::factory()->count(2)->create();
83-
84-
$this->actingAs($user);
85-
86-
Livewire::test(ThreadForm::class)
87-
->fillForm([
88-
'title' => 'I have a question about laravel Cameroun',
89-
'body' => 'this is my kind body',
90-
'channels' => $channels->pluck('id')->toArray(),
91-
])
92-
->call('save');
93-
94-
expect(Thread::query()->first())
95-
->toBeNull();
96-
})
97-
->group('thread')
98-
->expectException(UnverifiedUserException::class);
99-
100-
it('user cannot updated a thread that is not author', function (): void {
101-
$this->login();
102-
103-
$author = User::factory()->create();
104-
$thread = Thread::factory()->create(['user_id' => $author->id]);
105-
$channels = Channel::factory()->count(3)->create();
106-
107-
$thread->channels()->attach($channels->modelKeys());
108-
109-
Livewire::test(ThreadForm::class, ['threadId' => $thread->id])
110-
->fillForm([
111-
'title' => 'Updated thread question',
112-
'body' => 'this is my kind body updated',
113-
])
114-
->call('save')
115-
->assertStatus(403);
17+
/**
18+
* @var \Tests\TestCase $this
19+
*/
20+
describe(ThreadForm::class, function (): void {
21+
it('return redirect to unauthenticated user', function (): void {
22+
Livewire::test(ThreadForm::class)
23+
->assertStatus(302);
24+
});
25+
26+
it('render the component when authenticated user', function (): void {
27+
$this->login();
28+
29+
Livewire::test(ThreadForm::class)
30+
->assertSuccessful();
31+
});
32+
33+
it('validate forms input', function (): void {
34+
$this->login();
35+
36+
Livewire::test(ThreadForm::class)
37+
->fillForm([
38+
'title' => '',
39+
'body' => '',
40+
'channels' => [],
41+
])
42+
->call('save')
43+
->assertHasFormErrors([
44+
'title' => ['required'],
45+
'body' => ['required'],
46+
]);
47+
});
48+
49+
it('validate channels can extends 3 when create a thread', function (): void {
50+
$this->login();
51+
52+
Livewire::test(ThreadForm::class)
53+
->fillForm([
54+
'title' => 'I have a question about laravel Cameroun',
55+
'body' => 'this is my kind body',
56+
'channels' => ['laravel', 'php', 'tailwind', 'gaming'],
57+
])
58+
->call('save')
59+
->assertHasFormErrors([
60+
'channels' => ['max'],
61+
]);
62+
});
63+
64+
it('user can create a new thread', function (): void {
65+
$user = $this->login();
66+
$channels = Channel::factory()->count(3)->create();
67+
68+
Livewire::test(ThreadForm::class)
69+
->fillForm([
70+
'title' => 'I have a question about laravel Cameroun',
71+
'body' => 'this is my kind body',
72+
'channels' => $channels->pluck('id')->toArray(),
73+
])
74+
->call('save')
75+
->assertHasNoFormErrors();
76+
77+
$thread = Thread::query()->first();
78+
79+
expect($thread?->user)->toBeInstanceOf(User::class)
80+
->and($thread?->user->is($user))
81+
->toBeTrue();
82+
});
83+
84+
it('user cannot create thread with and unverified email address', function (): void {
85+
$user = $this->createUser(['email_verified_at' => null]);
86+
$channels = Channel::factory()->count(2)->create();
87+
88+
$this->actingAs($user);
89+
90+
Livewire::test(ThreadForm::class)
91+
->fillForm([
92+
'title' => 'I have a question about laravel Cameroun',
93+
'body' => 'this is my kind body',
94+
'channels' => $channels->pluck('id')->toArray(),
95+
])
96+
->call('save');
97+
98+
expect(Thread::query()->first())
99+
->toBeNull();
100+
})->expectException(UnverifiedUserException::class);
101+
102+
it('user cannot updated a thread that is not author', function (): void {
103+
$this->login();
104+
105+
$author = User::factory()->create();
106+
$thread = Thread::factory()->create(['user_id' => $author->id]);
107+
$channels = Channel::factory()->count(3)->create();
108+
109+
$thread->channels()->attach($channels->modelKeys());
110+
111+
Livewire::test(ThreadForm::class, ['threadId' => $thread->id])
112+
->fillForm([
113+
'title' => 'Updated thread question',
114+
'body' => 'this is my kind body updated',
115+
])
116+
->call('save')
117+
->assertStatus(403);
118+
});
116119
})->group('thread');

0 commit comments

Comments
 (0)