From 02b339227efa0b934035bcf8140828ad989a0c44 Mon Sep 17 00:00:00 2001 From: marcogermani87 Date: Thu, 29 Aug 2024 23:50:53 +0000 Subject: [PATCH] Fix styling --- src/Filament/Resources/EmailResource.php | 45 ++-- .../EmailResource/Pages/ListEmails.php | 54 ++--- tests/EmailModelTest.php | 122 +++++------ tests/Pest.php | 10 +- tests/TestCase.php | 194 +++++++++--------- 5 files changed, 211 insertions(+), 214 deletions(-) diff --git a/src/Filament/Resources/EmailResource.php b/src/Filament/Resources/EmailResource.php index bff8d5c..fa94a79 100644 --- a/src/Filament/Resources/EmailResource.php +++ b/src/Filament/Resources/EmailResource.php @@ -28,9 +28,6 @@ use Illuminate\Support\Facades\Mail; use Illuminate\Support\Str; use Malzariey\FilamentDaterangepickerFilter\Fields\DateRangePicker; - -; - use RickDBCN\FilamentEmail\Filament\Resources\EmailResource\Pages\ListEmails; use RickDBCN\FilamentEmail\Filament\Resources\EmailResource\Pages\ViewEmail; use RickDBCN\FilamentEmail\Mail\ResendMail; @@ -97,7 +94,7 @@ public static function form(Form $form): Form ->label(__('filament-email::filament-email.created_at')), ])->columns(4), Fieldset::make('attachments') - ->hidden(fn(): bool => !config('filament-email.store_attachments')) + ->hidden(fn (): bool => ! config('filament-email.store_attachments')) ->label(__('filament-email::filament-email.attachments')) ->schema([ View::make('filament-email::attachments') @@ -142,7 +139,7 @@ public static function table(Table $table): Table ->icon('heroicon-o-eye') ->iconSize(IconSize::Medium) ->modalFooterActions( - fn($action): array => [ + fn ($action): array => [ $action->getModalCancelAction(), ]) ->fillForm(function ($record) { @@ -199,7 +196,7 @@ public static function table(Table $table): Table ->nestedRecursiveRules([ 'email', ]) - ->default(fn($record): array => !empty($record->to) ? explode(',', $record->to) : []) + ->default(fn ($record): array => ! empty($record->to) ? explode(',', $record->to) : []) ->required(), TagsInput::make('cc') ->label(__('filament-email::filament-email.cc')) @@ -207,21 +204,21 @@ public static function table(Table $table): Table ->nestedRecursiveRules([ 'email', ]) - ->default(fn($record): array => !empty($record->cc) ? explode(',', $record->cc) : []), + ->default(fn ($record): array => ! empty($record->cc) ? explode(',', $record->cc) : []), TagsInput::make('bcc') ->label(__('filament-email::filament-email.bcc')) ->placeholder(__('filament-email::filament-email.insert_multiple_email_placelholder')) ->nestedRecursiveRules([ 'email', ]) - ->default(fn($record): array => !empty($record->bcc) ? explode(',', $record->bcc) : []), + ->default(fn ($record): array => ! empty($record->bcc) ? explode(',', $record->bcc) : []), Toggle::make('attachments') ->label(__('filament-email::filament-email.add_attachments')) ->onColor('success') ->offColor('danger') ->inline(false) - ->disabled(fn($record): bool => empty($record->attachments)) - ->default(fn($record): bool => !empty($record->attachments)) + ->disabled(fn ($record): bool => empty($record->attachments)) + ->default(fn ($record): bool => ! empty($record->attachments)) ->required(), ]) ->action(function (Email $record, array $data) { @@ -248,10 +245,10 @@ public static function table(Table $table): Table ]) ->columns([ TextColumn::make('from') - ->prefix(__('filament-email::filament-email.from') . ': ') - ->suffix(fn(Email $record): string => !empty($record->attachments) ? ' (' . trans_choice('filament-email::filament-email.attachments_number', count($record->attachments)) . ')' : '') + ->prefix(__('filament-email::filament-email.from').': ') + ->suffix(fn (Email $record): string => ! empty($record->attachments) ? ' ('.trans_choice('filament-email::filament-email.attachments_number', count($record->attachments)).')' : '') ->label(__('filament-email::filament-email.header')) - ->description(fn(Email $record): string => Str::limit(__('filament-email::filament-email.to') . ': ' . $record->to, 40)) + ->description(fn (Email $record): string => Str::limit(__('filament-email::filament-email.to').': '.$record->to, 40)) ->searchable(), TextColumn::make('subject') ->label(__('filament-email::filament-email.subject')) @@ -279,43 +276,45 @@ public static function table(Table $table): Table TextInput::make('bcc') ->label(__('filament-email::filament-email.bcc')) ->email(), -// DateRangePicker::make('created_at') -// ->label(__('filament-email::filament-email.sent_at')), + // DateRangePicker::make('created_at') + // ->label(__('filament-email::filament-email.sent_at')), ]) ->columns(2) ->indicateUsing(function (array $data): array { $indicators = []; foreach ($data as $field => $value) { if ($data[$field] ?? null) { - $indicators[$field] = __('filament-email::filament-email.' . $field) . ": $value"; + $indicators[$field] = __('filament-email::filament-email.'.$field).": $value"; } } + return $indicators; }) ->query(function (Builder $query, array $data): Builder { return $query ->when( $data['to'], - fn(Builder $query, $value): Builder => $query->where('to', 'like', "%$value%"), + fn (Builder $query, $value): Builder => $query->where('to', 'like', "%$value%"), ) ->when( $data['cc'], - fn(Builder $query, $value): Builder => $query->where('cc', 'like', "%$value%"), + fn (Builder $query, $value): Builder => $query->where('cc', 'like', "%$value%"), ) ->when( $data['bcc'], - fn(Builder $query, $value): Builder => $query->where('bcc', 'like', "%$value%"), + fn (Builder $query, $value): Builder => $query->where('bcc', 'like', "%$value%"), ) ->when( $data['created_at'], function (Builder $query, $value): Builder { $format = config('filament-email.resource.filters.created_at.date_format'); - list($start, $end) = explode(' - ', $value); + [$start, $end] = explode(' - ', $value); + return $query->whereBetween('created_at', [ Carbon::createFromFormat($format, $start) ->format('Y-m-d'), Carbon::createFromFormat($format, $end) - ->format('Y-m-d') + ->format('Y-m-d'), ]); } ); @@ -325,7 +324,7 @@ function (Builder $query, $value): Builder { ->paginationPageOptions(function (Table $table) { $options = config('filament-email.pagination_page_options'); - return !empty($options) && is_array($options) ? $options : $table->getPaginationPageOptions(); + return ! empty($options) && is_array($options) ? $options : $table->getPaginationPageOptions(); }); } @@ -341,7 +340,7 @@ public static function canAccess(): bool { $roles = config('filament-email.can_access.role', []); - if (method_exists(auth()->user(), 'hasRole') && !empty($roles)) { + if (method_exists(auth()->user(), 'hasRole') && ! empty($roles)) { return auth()->user()->hasRole($roles); } diff --git a/src/Filament/Resources/EmailResource/Pages/ListEmails.php b/src/Filament/Resources/EmailResource/Pages/ListEmails.php index 6ecaa3d..5b370c2 100644 --- a/src/Filament/Resources/EmailResource/Pages/ListEmails.php +++ b/src/Filament/Resources/EmailResource/Pages/ListEmails.php @@ -1,27 +1,27 @@ -getTableSearch())) { - return $query->filter(['search' => $searchQuery]); - } - - return $query; - } -} +getTableSearch())) { + return $query->filter(['search' => $searchQuery]); + } + + return $query; + } +} diff --git a/tests/EmailModelTest.php b/tests/EmailModelTest.php index 1ce95ad..f67e8c4 100644 --- a/tests/EmailModelTest.php +++ b/tests/EmailModelTest.php @@ -1,61 +1,61 @@ -model = config('filament-email.resource.model') ?? Email::class; - $this->actingAs(User::factory() - ->create()); -}); - -it('can create an Email model', function () { - $emailModel = Email::factory() - ->create(); - assertModelExists($emailModel); -}); - -it('can capture a sent email', function () { - $faker = Factory::create(); - $recipient = $faker->email(); - - Mail::raw('Test e-mail text', function ($message) use ($recipient) { - $message->to($recipient) - ->subject('the email subject'); - }); - - assertDatabaseCount('filament_email_log', 1); - - assertEquals($this->model::first()->to, $recipient); -}); - -it('can render table page', function () { - $this->model::factory() - ->create(); - livewire(ListEmails::class) - ->assertSuccessful(); -}); - -it('can render table records', function () { - $records = $this->model::factory() - ->count(10) - ->create(); - livewire(ListEmails::class) - ->assertCanSeeTableRecords($records); -}); - -it('can resend email', function () { - $email = $this->model::factory() - ->create(); - livewire(ListEmails::class) - ->callTableAction('resend', $email); - assertDatabaseCount((new $this->model)->getTable(), 2); -}); +model = config('filament-email.resource.model') ?? Email::class; + $this->actingAs(User::factory() + ->create()); +}); + +it('can create an Email model', function () { + $emailModel = Email::factory() + ->create(); + assertModelExists($emailModel); +}); + +it('can capture a sent email', function () { + $faker = Factory::create(); + $recipient = $faker->email(); + + Mail::raw('Test e-mail text', function ($message) use ($recipient) { + $message->to($recipient) + ->subject('the email subject'); + }); + + assertDatabaseCount('filament_email_log', 1); + + assertEquals($this->model::first()->to, $recipient); +}); + +it('can render table page', function () { + $this->model::factory() + ->create(); + livewire(ListEmails::class) + ->assertSuccessful(); +}); + +it('can render table records', function () { + $records = $this->model::factory() + ->count(10) + ->create(); + livewire(ListEmails::class) + ->assertCanSeeTableRecords($records); +}); + +it('can resend email', function () { + $email = $this->model::factory() + ->create(); + livewire(ListEmails::class) + ->callTableAction('resend', $email); + assertDatabaseCount((new $this->model)->getTable(), 2); +}); diff --git a/tests/Pest.php b/tests/Pest.php index 0d6910a..220dc97 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,5 +1,5 @@ -in(__DIR__); +in(__DIR__); diff --git a/tests/TestCase.php b/tests/TestCase.php index 7c73aad..d5fda2d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,98 +1,96 @@ -setUpDatabase($this->app); - - Factory::guessFactoryNamesUsing( - fn (string $modelName) => 'RickDBCN\\FilamentEmail\\Database\\Factories\\'.class_basename($modelName).'Factory' - ); - } - - protected function getPackageProviders($app) - { - $packageProviders = [ - BladeHeroiconsServiceProvider::class, - BladeIconsServiceProvider::class, - FilamentServiceProvider::class, - FormsServiceProvider::class, - LivewireServiceProvider::class, - SupportServiceProvider::class, - TablesServiceProvider::class, - ActionsServiceProvider::class, - WidgetsServiceProvider::class, - EmailMessageServiceProvider::class, - FilamentEmailServiceProvider::class, - FilamentDaterangepickerFilterServiceProvider::class, - TestPanelProvider::class, - ]; - - if (class_exists(NotificationsServiceProvider::class)) { - $packageProviders[] = NotificationsServiceProvider::class; - } - - return $packageProviders; - } - - public function getEnvironmentSetUp($app) - { - config()->set('database.default', 'testing'); - - $migration = include __DIR__.'/../database/migrations/create_filament_email_table.php.stub'; - $migration->up(); - - $migration = include __DIR__.'/../database/migrations/add_attachments_field_to_filament_email_log_table.php.stub'; - $migration->up(); - - $migration = include __DIR__.'/../database/migrations/add_team_id_field_to_filament_email_log_table.php.stub'; - $migration->up(); - } - - /** - * Set up the database. - * - * @param Application $app - */ - protected function setUpDatabase($app) - { - $app['db']->connection()->getSchemaBuilder()->create('users', function (Blueprint $table) { - $table->increments('id'); - $table->string('email'); - $table->string('name'); - }); - - $this->adminUser = User::create(['email' => 'admin@domain.com', 'name' => 'Admin']); - - //self::$migration->up(); - } -} +setUpDatabase($this->app); + + Factory::guessFactoryNamesUsing( + fn (string $modelName) => 'RickDBCN\\FilamentEmail\\Database\\Factories\\'.class_basename($modelName).'Factory' + ); + } + + protected function getPackageProviders($app) + { + $packageProviders = [ + BladeHeroiconsServiceProvider::class, + BladeIconsServiceProvider::class, + FilamentServiceProvider::class, + FormsServiceProvider::class, + LivewireServiceProvider::class, + SupportServiceProvider::class, + TablesServiceProvider::class, + ActionsServiceProvider::class, + WidgetsServiceProvider::class, + EmailMessageServiceProvider::class, + FilamentEmailServiceProvider::class, + FilamentDaterangepickerFilterServiceProvider::class, + TestPanelProvider::class, + ]; + + if (class_exists(NotificationsServiceProvider::class)) { + $packageProviders[] = NotificationsServiceProvider::class; + } + + return $packageProviders; + } + + public function getEnvironmentSetUp($app) + { + config()->set('database.default', 'testing'); + + $migration = include __DIR__.'/../database/migrations/create_filament_email_table.php.stub'; + $migration->up(); + + $migration = include __DIR__.'/../database/migrations/add_attachments_field_to_filament_email_log_table.php.stub'; + $migration->up(); + + $migration = include __DIR__.'/../database/migrations/add_team_id_field_to_filament_email_log_table.php.stub'; + $migration->up(); + } + + /** + * Set up the database. + * + * @param Application $app + */ + protected function setUpDatabase($app) + { + $app['db']->connection()->getSchemaBuilder()->create('users', function (Blueprint $table) { + $table->increments('id'); + $table->string('email'); + $table->string('name'); + }); + + $this->adminUser = User::create(['email' => 'admin@domain.com', 'name' => 'Admin']); + + //self::$migration->up(); + } +}