generated from filamentphp/plugin-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3666e47
commit 951fbdc
Showing
16 changed files
with
250 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"pest_2.36.0","defects":{"P\\Tests\\ArchTest::__pest_evaluable_it_will_not_use_debugging_functions":8},"times":{"P\\Tests\\PublishedStatusTableColumnTest::__pest_evaluable_it_can_render_page":0.197}} | ||
{"version":"pest_2.36.0","defects":{"P\\Tests\\ArchTest::__pest_evaluable_it_will_not_use_debugging_functions":8},"times":{"P\\Tests\\PublishedStatusTableColumnTest::__pest_evaluable_it_can_render_page":0.372,"P\\Tests\\PublishedStatusTableColumnTest::__pest_evaluable_it_can_renders_correct_published_statuses":0.188,"P\\Tests\\PublishTableActionTest::__pest_evaluable_it_can_publish_pages":0.2,"P\\Tests\\PublishTableActionTest::__pest_evaluable_it_only_shows_on_unpublishedOrRevised_pages":0.087,"P\\Tests\\UnpublishTableActionTest::__pest_evaluable_it_can_unpublish_pages":0.211,"P\\Tests\\UnpublishTableActionTest::__pest_evaluable_it_only_shows_on_published_pages":0.068}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Indra\RevisorFilament; | ||
|
||
use Filament\Support\Enums\Alignment; | ||
use Filament\Support\Enums\MaxWidth; | ||
use Filament\Support\Facades\FilamentIcon; | ||
use Filament\Tables\Actions\Action; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Indra\Revisor\Contracts\HasRevisor; | ||
|
||
class PublishTableAction extends Action | ||
{ | ||
public static function getDefaultName(): ?string | ||
{ | ||
return 'publish'; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this | ||
->label(fn (HasRevisor $record) => $record->isPublished() ? 'Publish Changes' : 'Publish') | ||
->icon(FilamentIcon::resolve('heroicon-o-arrow-up-tray') ?? 'heroicon-o-arrow-up-tray') | ||
->color('success') | ||
->deselectRecordsAfterCompletion() | ||
->modalHeading(fn (Model $record) => "Publish '$record->title'") | ||
->modalIcon(FilamentIcon::resolve('heroicon-o-arrow-up-tray') ?? 'heroicon-o-arrow-up-tray') | ||
->modalIconColor('success') | ||
->modalDescription('Are you sure you want to publish this page?') | ||
->modalAlignment(Alignment::Center) | ||
->modalFooterActionsAlignment(Alignment::Center) | ||
->modalSubmitActionLabel(__('filament-actions::modal.actions.confirm.label')) | ||
->modalWidth(MaxWidth::Medium) | ||
->hidden(fn (HasRevisor $record) => ! $record->isUnpublishedOrRevised()) | ||
->action(function (HasRevisor $record, array $data) { | ||
$record->publish(); | ||
$this->success(); | ||
}) | ||
->successNotificationTitle(fn () => $this->getModelLabel() . ' published successfully'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Indra\RevisorFilament; | ||
|
||
use Filament\Support\Enums\Alignment; | ||
use Filament\Support\Enums\MaxWidth; | ||
use Filament\Support\Facades\FilamentIcon; | ||
use Filament\Tables\Actions\Action; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Indra\Revisor\Contracts\HasRevisor; | ||
|
||
class UnpublishTableAction extends Action | ||
{ | ||
public static function getDefaultName(): ?string | ||
{ | ||
return 'unpublish'; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this | ||
->label('Unpublish') | ||
->icon(FilamentIcon::resolve('heroicon-o-arrow-down-tray') ?? 'heroicon-o-arrow-down-tray') | ||
->color('warning') | ||
->deselectRecordsAfterCompletion() | ||
->modalHeading(fn (Model $record) => "Unpublish '$record->title'") | ||
->modalIcon(FilamentIcon::resolve('heroicon-o-arrow-down-tray') ?? 'heroicon-o-arrow-down-tray') | ||
->modalIconColor('warning') | ||
->modalDescription('Are you sure you want to unpublish this page?') | ||
->modalAlignment(Alignment::Center) | ||
->modalFooterActionsAlignment(Alignment::Center) | ||
->modalSubmitActionLabel(__('filament-actions::modal.actions.confirm.label')) | ||
->modalWidth(MaxWidth::Medium) | ||
->hidden(fn (HasRevisor $record) => ! $record->isPublished()) | ||
->action(function (HasRevisor $record, array $data) { | ||
$record->unpublish(); | ||
$this->success(); | ||
}) | ||
->successNotificationTitle(fn (array $data) => $this->getModelLabel() . ' unpublished successfully'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Indra\RevisorFilament\PublishTableAction; | ||
use Indra\RevisorFilament\Tests\Models\Page; | ||
use Indra\RevisorFilament\Tests\Resources\PageResource\Pages\ListPages; | ||
|
||
use function Pest\Livewire\livewire; | ||
|
||
it('only shows on unpublishedOrRevised pages', function () { | ||
$page = Page::create(['title' => 'page']); | ||
|
||
livewire(ListPages::class) | ||
->assertTableActionExists(PublishTableAction::class, record: $page); | ||
|
||
$page->publish(); | ||
|
||
livewire(ListPages::class) | ||
->assertTableActionDoesNotExist(PublishTableAction::class, record: $page); | ||
|
||
$page->update(['title' => 'updated page']); | ||
|
||
livewire(ListPages::class) | ||
->assertTableActionExists(PublishTableAction::class, record: $page); | ||
}); | ||
|
||
it('can publish pages', function () { | ||
$page = Page::create(['title' => 'draft']); | ||
|
||
livewire(ListPages::class) | ||
->callTableAction(PublishTableAction::class, $page) | ||
->assertHasNoTableActionErrors(); | ||
|
||
expect($page->refresh()->isPublished())->toBeTrue(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
<?php | ||
|
||
use Indra\Revisor\Facades\Revisor; | ||
use Indra\RevisorFilament\Tests\Models\Page; | ||
use Indra\RevisorFilament\Tests\Resources\PageResource; | ||
use Indra\RevisorFilament\Tests\Resources\PageResource\Pages\ListPages; | ||
|
||
use function Pest\Livewire\livewire; | ||
|
||
it('can renders correct published statuses', function () { | ||
Revisor::draftContext(); | ||
|
||
it('can render page', function () { | ||
$this->get(PageResource::getUrl('index'))->assertSuccessful(); | ||
|
||
$draft = Page::create(['title' => 'draft']); | ||
$published = Page::create(['title' => 'published'])->publish(); | ||
$revised = Page::create(['title' => 'revise'])->publish(); | ||
|
||
$this->travel(5)->seconds(); | ||
$revised->update(['title' => 'revised']); | ||
|
||
livewire(ListPages::class) | ||
->assertTableColumnStateSet('published_status', '["draft"]', $draft) | ||
->assertTableColumnStateSet('published_status', '["published"]', $published) | ||
->assertTableColumnStateSet('published_status', '["published","revised"]', $revised); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/Pages/ListPages.php → ...esources/PageResource/Pages/ListPages.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
use Filament\Tables\TablesServiceProvider; | ||
use Filament\Widgets\WidgetsServiceProvider; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Indra\Revisor\Enums\RevisorContext; | ||
use Indra\Revisor\RevisorServiceProvider; | ||
use Indra\RevisorFilament\RevisorFilamentServiceProvider; | ||
use Indra\RevisorFilament\Tests\Models\User; | ||
|
@@ -34,11 +35,7 @@ protected function setUp(): void | |
fn (string $modelName) => 'Indra\\RevisorFilament\\Database\\Factories\\' . class_basename($modelName) . 'Factory' | ||
); | ||
|
||
$this->actingAs(User::create([ | ||
'name' => 'test', | ||
'email' => '[email protected]', | ||
'password' => bcrypt('password'), | ||
])); | ||
$this->actingAs(User::factory()->create()); | ||
} | ||
|
||
protected function getPackageProviders($app) | ||
|
@@ -65,7 +62,8 @@ protected function getPackageProviders($app) | |
public function getEnvironmentSetUp($app) | ||
{ | ||
config()->set('database.default', 'testing'); | ||
$app['config']->set('auth.providers.users.model', User::class); | ||
config()->set('revisor.default_context', RevisorContext::Draft); | ||
config()->set('auth.providers.users.model', User::class); | ||
|
||
$migration = include __DIR__ . '/database/create_test_tables.php'; | ||
$migration->up(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
use Indra\Revisor\Facades\Revisor; | ||
use Indra\RevisorFilament\Tests\Models\Page; | ||
use Indra\RevisorFilament\Tests\Resources\PageResource\Pages\ListPages; | ||
use Indra\RevisorFilament\UnpublishTableAction; | ||
|
||
use function Pest\Livewire\livewire; | ||
|
||
it('only shows on published pages', function () { | ||
Revisor::draftContext(); | ||
$page = Page::create(['title' => 'page']); | ||
|
||
livewire(ListPages::class) | ||
->assertTableActionDoesNotExist(UnpublishTableAction::class, record: $page); | ||
|
||
$page->publish(); | ||
|
||
livewire(ListPages::class) | ||
->assertTableActionExists(UnpublishTableAction::class, record: $page); | ||
}); | ||
|
||
it('can unpublish pages', function () { | ||
$page = Page::create(['title' => 'draft'])->publish(); | ||
|
||
livewire(ListPages::class) | ||
->callTableAction(UnpublishTableAction::class, record: $page) | ||
->assertHasNoTableActionErrors(); | ||
|
||
expect($page->refresh()->isPublished())->toBeFalse(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Indra\RevisorFilament\Tests\Database\Factories; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Indra\RevisorFilament\Tests\Models\Page; | ||
|
||
class PageFactory extends Factory | ||
{ | ||
protected $model = Page::class; | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'title' => $this->faker->sentence(), | ||
]; | ||
} | ||
} |
Oops, something went wrong.