Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
4453f98
feat:[LAR-34] Add filament tags crud in cpanel with feature test
cybersoldattech Nov 8, 2024
ead8285
feat: (LAR-20) add xp to dashboard user (#202)
StevyMarlino Nov 8, 2024
43ce8d2
chore(deps): bump spatie/laravel-permission from 5.11.1 to 6.10.0 (#199)
dependabot[bot] Nov 8, 2024
9abcbe4
chore(deps-dev): bump laravel-vite-plugin from 0.7.8 to 1.0.5 (#194)
dependabot[bot] Nov 8, 2024
c11e019
chore(deps-dev): bump postcss-loader from 6.2.1 to 8.1.1 (#195)
dependabot[bot] Nov 8, 2024
7f02596
chore(deps-dev): bump @ryangjchandler/alpine-tooltip from 1.3.1 to 2.…
dependabot[bot] Nov 8, 2024
3950138
feat: (LAR-107) modification du formulaire de register (#206)
Stephen2304 Nov 8, 2024
73892a7
feat:[LAR-33] Add filament channel crud in cpanel with feature test (…
cybersoldattech Nov 8, 2024
2891914
chore(deps): bump symfony/mailgun-mailer from 6.4.13 to 7.1.6 (#198)
dependabot[bot] Nov 8, 2024
d993ba8
feat: [LAR-34] Remove blank space , add slive over and delete create …
cybersoldattech Nov 8, 2024
eddb78a
feat: [LAR-34] add unique condition to input name with message and re…
cybersoldattech Nov 8, 2024
f990652
chore :[LAR-34] remove space in TestFIle
cybersoldattech Nov 9, 2024
94b9b48
chore(deps): bump actions/checkout from 3 to 4 (#190)
dependabot[bot] Nov 8, 2024
edf0449
fix: (LAR-21) resolve sharing article into twitter (#208)
StevyMarlino Nov 9, 2024
89ac0e6
chore(deps): bump the php-dependencies group across 1 directory with …
dependabot[bot] Nov 9, 2024
d76617d
chore(deps-dev): bump prettier-plugin-tailwindcss
dependabot[bot] Nov 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
npm-debug.log
yarn-error.log
yarn.lock

package-lock.json
/vendor
composer.phar

Expand Down
89 changes: 89 additions & 0 deletions app/Filament/Resources/TagResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources;

use App\Filament\Resources\TagResource\Pages;
use App\Models\Tag;
use Filament\Forms;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Forms\Set;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\Str;

final class TagResource extends Resource
{
protected static ?string $model = Tag::class;

protected static ?string $navigationIcon = 'heroicon-o-tag';

public static function form(Form $form): Form
{
return $form
->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)) {

Check failure on line 33 in app/Filament/Resources/TagResource.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $title of static method Illuminate\Support\Str::slug() expects string, string|null given.
return;
}
$set('slug', Str::slug($state));

Check failure on line 36 in app/Filament/Resources/TagResource.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $title of static method Illuminate\Support\Str::slug() expects string, string|null given.
}),
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'),
];
}
}
13 changes: 13 additions & 0 deletions app/Filament/Resources/TagResource/Pages/CreateTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\TagResource\Pages;

use App\Filament\Resources\TagResource;
use Filament\Resources\Pages\CreateRecord;

final class CreateTag extends CreateRecord
{
protected static string $resource = TagResource::class;
}
21 changes: 21 additions & 0 deletions app/Filament/Resources/TagResource/Pages/EditTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\TagResource\Pages;

use App\Filament\Resources\TagResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

final class EditTag extends EditRecord
{
protected static string $resource = TagResource::class;

protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}
21 changes: 21 additions & 0 deletions app/Filament/Resources/TagResource/Pages/ListTags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\TagResource\Pages;

use App\Filament\Resources\TagResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

final class ListTags extends ListRecords
{
protected static string $resource = TagResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
105 changes: 105 additions & 0 deletions tests/Feature/Filament/TagTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

declare(strict_types=1);

use App\Filament\Resources\TagResource;
use App\Filament\Resources\TagResource\Pages\CreateTag;
use App\Filament\Resources\TagResource\Pages\ListTags;
use App\Models\Tag;
use Filament\Actions\EditAction;
use Illuminate\Database\Eloquent\Factories\Sequence;
use Livewire\Livewire;

beforeEach(function (): void {
$this->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');
Loading