Skip to content

Commit 17f02aa

Browse files
cybersoldattechStevyMarlinodependabot[bot]
authored
feat:[LAR-33] Add filament channel crud in cpanel with feature test (#204)
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Stevy Endaman <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 7524c72 commit 17f02aa

File tree

3 files changed

+184
-0
lines changed

3 files changed

+184
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Filament\Resources;
6+
7+
use App\Filament\Resources\ChannelResource\Pages;
8+
use App\Models\Channel;
9+
use Filament\Forms;
10+
use Filament\Forms\Form;
11+
use Filament\Resources\Resource;
12+
use Filament\Support\Enums\MaxWidth;
13+
use Filament\Tables;
14+
use Filament\Tables\Actions\ActionGroup;
15+
use Filament\Tables\Table;
16+
use Illuminate\Database\Eloquent\Builder;
17+
use Illuminate\Support\Str;
18+
19+
final class ChannelResource extends Resource
20+
{
21+
protected static ?string $model = Channel::class;
22+
23+
protected static ?string $navigationIcon = 'heroicon-o-queue-list';
24+
25+
public static function getLabel(): string
26+
{
27+
return __('Channels');
28+
}
29+
30+
public static function form(Form $form): Form
31+
{
32+
return $form
33+
->schema([
34+
Forms\Components\Section::make()
35+
->schema([
36+
Forms\Components\TextInput::make('name')
37+
->required()
38+
->live(onBlur: true)
39+
->afterStateUpdated(function (string $operation, $state, Forms\Set $set): void {
40+
$set('slug', Str::slug($state));
41+
}),
42+
Forms\Components\TextInput::make('slug')
43+
->readOnly()
44+
->helperText(__('Cette valeur est générée dynamiquement en fonction du Name.')),
45+
Forms\Components\Select::make('parent_id')
46+
->relationship('parent', 'name', fn (Builder $query) => $query->whereNull('parent_id'))
47+
->default(null),
48+
Forms\Components\TextInput::make('color')
49+
->maxLength(255)
50+
->type('color'),
51+
Forms\Components\Textarea::make('description.fr')
52+
->label('Description')
53+
->columnSpanFull(),
54+
])
55+
->columnSpan(['lg' => 2]),
56+
]);
57+
}
58+
59+
public static function table(Table $table): Table
60+
{
61+
return $table
62+
->columns([
63+
Tables\Columns\TextColumn::make('name')
64+
->searchable(),
65+
Tables\Columns\TextColumn::make('slug')
66+
->searchable(),
67+
Tables\Columns\TextColumn::make('parent.name')
68+
->numeric()
69+
->sortable(),
70+
Tables\Columns\TextColumn::make('thread_number')
71+
->label('Nombre de thead')
72+
->getStateUsing(fn ($record) => $record->threads()->count()),
73+
Tables\Columns\TextColumn::make('color')
74+
->searchable(),
75+
Tables\Columns\TextColumn::make('created_at')
76+
->dateTime()
77+
->sortable()
78+
->toggleable(isToggledHiddenByDefault: true),
79+
])
80+
->filters([
81+
82+
])
83+
->actions([
84+
ActionGroup::make([
85+
Tables\Actions\DeleteAction::make(),
86+
Tables\Actions\EditAction::make()
87+
->slideOver()
88+
->modalWidth(MaxWidth::Large),
89+
]),
90+
])
91+
->bulkActions([
92+
Tables\Actions\BulkActionGroup::make([
93+
Tables\Actions\DeleteBulkAction::make(),
94+
]),
95+
]);
96+
}
97+
98+
public static function getPages(): array
99+
{
100+
return [
101+
'index' => Pages\ListChannels::route('/'),
102+
];
103+
}
104+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Filament\Resources\ChannelResource\Pages;
6+
7+
use App\Filament\Resources\ChannelResource;
8+
use Filament\Actions;
9+
use Filament\Resources\Pages\ListRecords;
10+
use Filament\Support\Enums\MaxWidth;
11+
12+
final class ListChannels extends ListRecords
13+
{
14+
protected static string $resource = ChannelResource::class;
15+
16+
protected function getHeaderActions(): array
17+
{
18+
return [
19+
Actions\CreateAction::make()
20+
->slideOver()
21+
->modalWidth(MaxWidth::Large),
22+
];
23+
}
24+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use App\Filament\Resources\ChannelResource;
6+
use App\Filament\Resources\ChannelResource\Pages\ListChannels;
7+
use App\Models\Channel;
8+
use Filament\Actions\CreateAction;
9+
use Filament\Actions\EditAction;
10+
use Livewire\Livewire;
11+
12+
beforeEach(function (): void {
13+
$this->user = $this->login();
14+
});
15+
16+
describe(ChannelResource::class, function (): void {
17+
it('page can display table with records', function (): void {
18+
$channels = Channel::factory()
19+
->count(10)
20+
->create();
21+
Livewire::test(ListChannels::class)
22+
->assertCanSeeTableRecords($channels);
23+
});
24+
25+
it('Admin user can create channel', function (): void {
26+
Livewire::test(ListChannels::class)
27+
->callAction(CreateAction::class, data: [
28+
'name' => $name = 'my channel',
29+
'color' => '#FFFFFF',
30+
])
31+
->assertHasNoActionErrors()
32+
->assertStatus(200);
33+
34+
$channel = Channel::first();
35+
36+
expect($channel)
37+
->toBeInstanceOf(Channel::class)
38+
->and($channel->name)->toBe($name);
39+
});
40+
41+
it('Admin user can edit channel', function (): void {
42+
$channel = Channel::factory()->create();
43+
44+
Livewire::test(ListChannels::class)
45+
->callTableAction(EditAction::class, $channel, data: [
46+
'name' => 'Edited channel',
47+
])
48+
->assertHasNoTableActionErrors();
49+
50+
$channel->refresh();
51+
52+
expect($channel->name)
53+
->toBe('Edited channel');
54+
});
55+
56+
})->group('channels');

0 commit comments

Comments
 (0)