From 4453f9874ed1158a3a11c6689ccf62e288689693 Mon Sep 17 00:00:00 2001 From: Chri$ Date: Fri, 8 Nov 2024 02:59:59 +0100 Subject: [PATCH 01/16] feat:[LAR-34] Add filament tags crud in cpanel with feature test --- .gitignore | 2 +- app/Filament/Resources/TagResource.php | 89 +++++++++++++++ .../Resources/TagResource/Pages/CreateTag.php | 13 +++ .../Resources/TagResource/Pages/EditTag.php | 21 ++++ .../Resources/TagResource/Pages/ListTags.php | 21 ++++ tests/Feature/Filament/TagTest.php | 105 ++++++++++++++++++ 6 files changed, 250 insertions(+), 1 deletion(-) create mode 100644 app/Filament/Resources/TagResource.php create mode 100644 app/Filament/Resources/TagResource/Pages/CreateTag.php create mode 100644 app/Filament/Resources/TagResource/Pages/EditTag.php create mode 100644 app/Filament/Resources/TagResource/Pages/ListTags.php create mode 100644 tests/Feature/Filament/TagTest.php diff --git a/.gitignore b/.gitignore index b3f5acc2..f382d565 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ npm-debug.log yarn-error.log yarn.lock - +package-lock.json /vendor composer.phar diff --git a/app/Filament/Resources/TagResource.php b/app/Filament/Resources/TagResource.php new file mode 100644 index 00000000..e4ae7e5d --- /dev/null +++ b/app/Filament/Resources/TagResource.php @@ -0,0 +1,89 @@ +schema([ + Forms\Components\TextInput::make('name') + ->required() + ->live(onBlur: true) + ->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state): void { + if (($get('slug') ?? '') !== Str::slug($old)) { + return; + } + $set('slug', Str::slug($state)); + }), + Forms\Components\TextInput::make('slug') + ->required(), + Select::make('concerns') + ->multiple() + ->options([ + 'post' => 'Post', + 'tutorial' => 'Tutorial', + 'discussion' => 'Discussion', + ]) + ->required() + ->columnSpanFull(), + Forms\Components\Textarea::make('description') + ->columnSpanFull(), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('name') + ->searchable(), + Tables\Columns\TextColumn::make('slug') + ->searchable(), + Tables\Columns\TextColumn::make(name: 'concerns'), + ]) + ->filters([ + // + ]) + ->actions([ + \Filament\Tables\Actions\ActionGroup::make([ + Tables\Actions\DeleteAction::make(), + Tables\Actions\EditAction::make() + ->color('warning'), + ]), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + ]), + ]); + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListTags::route('/'), + 'create' => Pages\CreateTag::route('/create'), + 'edit' => Pages\EditTag::route('/{record}/edit'), + ]; + } +} diff --git a/app/Filament/Resources/TagResource/Pages/CreateTag.php b/app/Filament/Resources/TagResource/Pages/CreateTag.php new file mode 100644 index 00000000..b4ecf883 --- /dev/null +++ b/app/Filament/Resources/TagResource/Pages/CreateTag.php @@ -0,0 +1,13 @@ +user = $this->login(); + $this->tags = Tag::factory() + ->count(10) + ->state(new Sequence( + ['concerns' => ['post', 'tutorial']], + ['concerns' => ['post']], + )) + ->create(); +}); + +describe(TagResource::class, function (): void { + + it('page can display table with records', function (): void { + Livewire::test(ListTags::class) + ->assertCanSeeTableRecords($this->tags); + }); + + it('can automatically generate a slug from the title', function (): void { + $name = fake()->name(); + + Livewire::test(CreateTag::class) + ->fillForm([ + 'name' => $name, + ]) + ->assertFormSet([ + 'slug' => Str::slug($name), + ]); + }); + + it('can validate input is value is null or empty', function (): void { + $name = fake()->name(); + + Livewire::test(CreateTag::class) + ->fillForm([ + 'name' => null, + 'concerns' => [], + 'description' => 'Description du tag '.$name, + ]) + ->call('create') + ->assertHasFormErrors(['name' => 'required', 'concerns' => 'required']); + }); + + it('Admin user can create tag', function (): void { + $name = fake()->name(); + + Livewire::test(CreateTag::class) + ->fillForm([ + 'name' => $name, + 'concerns' => ['post', 'tutorial'], + 'description' => 'Description du tag '.$name, + ]) + ->call('create'); + }); + + it('Generate tag if tag already exist', function (): void { + + $name = fake()->name(); + Tag::factory()->create([ + 'name' => $name, + 'slug' => Str::slug($name), + 'concerns' => ['discussion'], + ]); + + Livewire::test(CreateTag::class) + ->fillForm([ + 'name' => $name, + 'concerns' => ['post', 'tutorial'], + 'description' => 'Description du tag '.$name, + ]) + ->call('create'); + + expect(Tag::orderByDesc('id')->first()->slug) + ->toBe(Str::slug($name).'-1'); + + }); + + it('Admin user can edit tag', function (): void { + $tag = Tag::factory()->create(); + + Livewire::test(ListTags::class) + ->callTableAction(EditAction::class, $tag, data: [ + 'name' => 'Edited tag', + ]) + ->assertHasNoTableActionErrors(); + + $tag->refresh(); + + expect($tag->name) + ->toBe('Edited tag'); + }); + +})->group('tags'); From ead8285ca2ec7aab2d9af52bee149bb12b6c6945 Mon Sep 17 00:00:00 2001 From: Stevy Endaman Date: Fri, 8 Nov 2024 08:37:04 +0100 Subject: [PATCH 02/16] feat: (LAR-20) add xp to dashboard user (#202) --- resources/views/components/user/stats.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/components/user/stats.blade.php b/resources/views/components/user/stats.blade.php index 898b784f..c963e792 100644 --- a/resources/views/components/user/stats.blade.php +++ b/resources/views/components/user/stats.blade.php @@ -44,7 +44,7 @@ {{ __('pages/account.dashboard.stats.experience') }}
- 0 + {{ $user->getPoints() }}