Skip to content

Commit

Permalink
Fixed commented field
Browse files Browse the repository at this point in the history
  • Loading branch information
marcogermani87 committed Aug 30, 2024
2 parents 8c8577a + 02b3392 commit e5e99bd
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 191 deletions.
54 changes: 27 additions & 27 deletions src/Filament/Resources/EmailResource/Pages/ListEmails.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?php

namespace RickDBCN\FilamentEmail\Filament\Resources\EmailResource\Pages;

use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Database\Eloquent\Builder;
use RickDBCN\FilamentEmail\Filament\Resources\EmailResource;

class ListEmails extends ListRecords
{
use InteractsWithActions;

public static function getResource(): string
{
return config('filament-email.resource.class', EmailResource::class);
}

protected function applySearchToTableQuery(Builder $query): Builder
{
if (filled($searchQuery = $this->getTableSearch())) {
return $query->filter(['search' => $searchQuery]);
}

return $query;
}
}
<?php

namespace RickDBCN\FilamentEmail\Filament\Resources\EmailResource\Pages;

use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Database\Eloquent\Builder;
use RickDBCN\FilamentEmail\Filament\Resources\EmailResource;

class ListEmails extends ListRecords
{
use InteractsWithActions;

public static function getResource(): string
{
return config('filament-email.resource.class', EmailResource::class);
}

protected function applySearchToTableQuery(Builder $query): Builder
{
if (filled($searchQuery = $this->getTableSearch())) {
return $query->filter(['search' => $searchQuery]);
}

return $query;
}
}
122 changes: 61 additions & 61 deletions tests/EmailModelTest.php
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
<?php

use Faker\Factory;
use Illuminate\Support\Facades\Mail;
use RickDBCN\FilamentEmail\Filament\Resources\EmailResource\Pages\ListEmails;
use RickDBCN\FilamentEmail\Models\Email;
use RickDBCN\FilamentEmail\Tests\Models\User;

use function Pest\Laravel\assertDatabaseCount;
use function Pest\Laravel\assertModelExists;
use function Pest\Livewire\livewire;
use function PHPUnit\Framework\assertEquals;

beforeEach(function () {
$this->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);
});
<?php

use Faker\Factory;
use Illuminate\Support\Facades\Mail;
use RickDBCN\FilamentEmail\Filament\Resources\EmailResource\Pages\ListEmails;
use RickDBCN\FilamentEmail\Models\Email;
use RickDBCN\FilamentEmail\Tests\Models\User;

use function Pest\Laravel\assertDatabaseCount;
use function Pest\Laravel\assertModelExists;
use function Pest\Livewire\livewire;
use function PHPUnit\Framework\assertEquals;

beforeEach(function () {
$this->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);
});
10 changes: 5 additions & 5 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

use RickDBCN\FilamentEmail\Tests\TestCase;

uses(TestCase::class)->in(__DIR__);
<?php

use RickDBCN\FilamentEmail\Tests\TestCase;

uses(TestCase::class)->in(__DIR__);
194 changes: 96 additions & 98 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,98 +1,96 @@
<?php

namespace RickDBCN\FilamentEmail\Tests;

use BladeUI\Heroicons\BladeHeroiconsServiceProvider;
use BladeUI\Icons\BladeIconsServiceProvider;
use Filament\Actions\ActionsServiceProvider;
use Filament\FilamentServiceProvider;
use Filament\Forms\FormsServiceProvider;
use Filament\Notifications\NotificationsServiceProvider;
use Filament\Support\SupportServiceProvider;
use Filament\Tables\TablesServiceProvider;
use Filament\Widgets\WidgetsServiceProvider;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Foundation\Application;
use Livewire\LivewireServiceProvider;
use Malzariey\FilamentDaterangepickerFilter\Fields\DateRangePicker;
use Malzariey\FilamentDaterangepickerFilter\FilamentDaterangepickerFilterServiceProvider;
use Malzariey\FilamentDaterangepickerFilter\Filters\DateRangeFilter;
use Orchestra\Testbench\TestCase as Orchestra;
use RickDBCN\FilamentEmail\FilamentEmailServiceProvider;
use RickDBCN\FilamentEmail\Providers\EmailMessageServiceProvider;
use RickDBCN\FilamentEmail\Tests\Models\User;
use RickDBCN\FilamentEmail\Tests\Panels\TestPanelProvider;

class TestCase extends Orchestra
{
protected User $adminUser;

protected function setUp(): void
{
parent::setUp();

$this->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' => '[email protected]', 'name' => 'Admin']);

//self::$migration->up();
}
}
<?php

namespace RickDBCN\FilamentEmail\Tests;

use BladeUI\Heroicons\BladeHeroiconsServiceProvider;
use BladeUI\Icons\BladeIconsServiceProvider;
use Filament\Actions\ActionsServiceProvider;
use Filament\FilamentServiceProvider;
use Filament\Forms\FormsServiceProvider;
use Filament\Notifications\NotificationsServiceProvider;
use Filament\Support\SupportServiceProvider;
use Filament\Tables\TablesServiceProvider;
use Filament\Widgets\WidgetsServiceProvider;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Foundation\Application;
use Livewire\LivewireServiceProvider;
use Malzariey\FilamentDaterangepickerFilter\FilamentDaterangepickerFilterServiceProvider;
use Orchestra\Testbench\TestCase as Orchestra;
use RickDBCN\FilamentEmail\FilamentEmailServiceProvider;
use RickDBCN\FilamentEmail\Providers\EmailMessageServiceProvider;
use RickDBCN\FilamentEmail\Tests\Models\User;
use RickDBCN\FilamentEmail\Tests\Panels\TestPanelProvider;

class TestCase extends Orchestra
{
protected User $adminUser;

protected function setUp(): void
{
parent::setUp();

$this->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' => '[email protected]', 'name' => 'Admin']);

//self::$migration->up();
}
}

0 comments on commit e5e99bd

Please sign in to comment.