Skip to content

Commit ca82fae

Browse files
committed
test: initial feature tests
1 parent 805164e commit ca82fae

25 files changed

+672
-42
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"pestphp/pest": "^2.1",
3636
"pestphp/pest-plugin-arch": "^2.0",
3737
"pestphp/pest-plugin-laravel": "^2.0",
38+
"pestphp/pest-plugin-livewire": "^2.1",
3839
"phpstan/extension-installer": "^1.1",
3940
"phpstan/phpstan-deprecation-rules": "^1.0",
4041
"phpstan/phpstan-phpunit": "^1.0",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Redberry\PageBuilderPlugin\Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Redberry\PageBuilderPlugin\Models\PageBuilderBlock;
7+
8+
class PageBuilderBlockFactory extends Factory
9+
{
10+
protected $model = PageBuilderBlock::class;
11+
12+
public function definition()
13+
{
14+
return [
15+
'block_type' => 'text',
16+
'order' => $this->faker->numberBetween(0, 300),
17+
'page_builder_blockable_id' => 1,
18+
'page_builder_blockable_type' => '',
19+
'data' => [],
20+
];
21+
}
22+
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
namespace Redberry\PageBuilderPlugin\Database\Factories;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Redberry\PageBuilderPlugin\Tests\Fixtures\Models\Page;
67

7-
/*
8-
class ModelFactory extends Factory
8+
class PageFactory extends Factory
99
{
10-
protected $model = YourModel::class;
10+
protected $model = Page::class;
1111

1212
public function definition()
1313
{
1414
return [
15-
15+
'name' => $this->faker->word(),
1616
];
1717
}
1818
}
19-
*/

resources/views/forms/page-builder-preview.blade.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@
66
$autoResizeIframe = $getAutoResizeIframe();
77
@endphp
88
<x-dynamic-component :component="$getFieldWrapperView()" :field="$field">
9-
@if (!$shouldRenderWithIframe)
10-
@if ($singleItemPreview)
11-
@component($getViewForBlock($pageBuilderData['block_type']), ['block' => $pageBuilderData])
12-
@endcomponent
13-
@else
14-
@foreach ($pageBuilderData as $block)
15-
@component($getViewForBlock($block['block_type']), ['block' => $block])
9+
@if (count($pageBuilderData))
10+
@if (!$shouldRenderWithIframe)
11+
@if ($singleItemPreview)
12+
@component($getViewForBlock($pageBuilderData['block_type']), ['block' => $pageBuilderData])
1613
@endcomponent
17-
@endforeach
14+
@else
15+
@foreach ($pageBuilderData as $block)
16+
@component($getViewForBlock($block['block_type']), ['block' => $block])
17+
@endcomponent
18+
@endforeach
19+
@endif
20+
@else
21+
<x-page-builder-plugin::iframe url="{{ $getIframeUrl() }}" :data=$pageBuilderData
22+
statePath="{{ $getStatePath() }}" autoResizeIframe="{{ $autoResizeIframe }}"
23+
:attributes=$iframeAttributes />
1824
@endif
19-
@else
20-
<x-page-builder-plugin::iframe
21-
url="{{ $getIframeUrl() }}"
22-
:data=$pageBuilderData
23-
statePath="{{ $getStatePath() }}"
24-
autoResizeIframe="{{ $autoResizeIframe }}"
25-
:attributes=$iframeAttributes
26-
/>
2725
@endif
2826
</x-dynamic-component>

src/Components/Forms/Actions/CreatePageBuilderBlockAction.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function setUp(): void
2626

2727
$this->successNotificationTitle(__('filament-panels::resources/pages/create-record.notifications.created.title'));
2828

29-
$this->form(function ($arguments, Form $form, PageBuilder $component, $livewire) {
29+
$this->form(function ($arguments, Form $form, PageBuilder $component) {
3030
$blockType = $arguments['block_type'];
3131

3232
$preview = PageBuilderPreview::make('preview')
@@ -62,7 +62,7 @@ protected function setUp(): void
6262

6363
$this->modalWidth(MaxWidth::Screen);
6464

65-
$this->action(function ($arguments, $data, $action, PageBuilder $component) {
65+
$this->action(function ($arguments, $data, PageBuilder $component) {
6666
$blockType = $arguments['block_type'];
6767
$state = $component->getState() ?? [];
6868

@@ -79,9 +79,11 @@ protected function setUp(): void
7979
$block->toArray(),
8080
]);
8181

82-
$action->sendSuccessNotification();
82+
$this->sendSuccessNotification();
8383

8484
$component->callAfterStateUpdated();
85+
86+
$this->success();
8587
});
8688
}
8789
}

src/Components/Forms/Actions/EditPageBuilderBlockAction.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Filament\Forms\Components\Grid;
77
use Filament\Forms\Components\Hidden;
88
use Filament\Forms\Form;
9-
use Filament\Pages\Page;
109
use Filament\Support\Enums\MaxWidth;
1110
use Redberry\PageBuilderPlugin\Components\Forms\PageBuilder;
1211
use Redberry\PageBuilderPlugin\Components\Forms\PageBuilderPreview;
@@ -27,7 +26,7 @@ protected function setUp(): void
2726

2827
$this->successNotificationTitle(__('filament-panels::resources/pages/edit-record.notifications.saved.title'));
2928

30-
$this->form(function ($arguments, Form $form, PageBuilder $component, Page $livewire) {
29+
$this->form(function ($arguments, Form $form, PageBuilder $component) {
3130
$block = $component->getState()[$arguments['index']];
3231

3332
$preview = PageBuilderPreview::make('preview')

src/Components/Forms/Actions/SelectBlockAction.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Filament\Forms\Components\Actions\Action;
66
use Filament\Forms\Components\Select;
7-
use Filament\Pages\Page;
87
use Redberry\PageBuilderPlugin\Components\Forms\PageBuilder;
98

109
class SelectBlockAction extends Action
@@ -29,18 +28,19 @@ protected function setUp(): void
2928
Select::make('block_type')
3029
->native(false)
3130
->translateLabel()
31+
->required()
3232
->translateLabel()
3333
->options($this->formatBlocksForSelect($component)),
3434
]);
3535
});
3636

37-
$this->action(function ($data, Page $livewire, Action $action, PageBuilder $component) {
37+
$this->action(function ($data, $livewire, Action $action, PageBuilder $component) {
3838
$livewire->mountFormComponentAction(
3939
$component->getStatePath(),
4040
$component->getCreateActionName(),
4141
$data
4242
);
43-
$action->halt();
43+
$this->halt();
4444
});
4545
}
4646

src/Components/Forms/PageBuilder.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Database\Eloquent\Collection;
1111
use Illuminate\Database\Eloquent\Model;
1212
use Illuminate\Support\Facades\DB;
13+
use Illuminate\View\ComponentAttributeBag;
1314
use Redberry\PageBuilderPlugin\Components\Forms\Actions\CreatePageBuilderBlockAction;
1415
use Redberry\PageBuilderPlugin\Components\Forms\Actions\DeletePageBuilderBlockAction;
1516
use Redberry\PageBuilderPlugin\Components\Forms\Actions\EditPageBuilderBlockAction;
@@ -144,7 +145,7 @@ public function renderDeleteActionButton(string $item, int $index)
144145
'icon' => 'heroicon-o-trash',
145146
'color' => 'danger',
146147
'disabled' => $deleteAction->isDisabled(),
147-
'attributes' => collect([
148+
'attributes' => new ComponentAttributeBag([
148149
'wire:click' => "mountFormComponentAction('$statePath', '{$this->getDeleteActionName()}', { item: '$item', index: '$index' } )",
149150
]),
150151
];
@@ -172,7 +173,7 @@ public function renderEditActionButton(string $item, $index)
172173
'icon' => 'heroicon-o-pencil-square',
173174
'disabled' => $editAction->isDisabled(),
174175
'color' => 'primary',
175-
'attributes' => collect([
176+
'attributes' => new ComponentAttributeBag([
176177
'wire:click' => "mountFormComponentAction('$statePath', '{$this->getEditActionName()}', { item: '$item', index: '$index' } )",
177178
]),
178179
];
@@ -197,7 +198,7 @@ public function renderReorderActionButton(string $item, $index)
197198
'icon' => 'heroicon-o-arrows-up-down',
198199
'disabled' => $reorderAction->isDisabled(),
199200
'color' => 'gray',
200-
'attributes' => collect([
201+
'attributes' => new ComponentAttributeBag([
201202
'x-sortable-handle' => 'x-sortable-handle',
202203
'x-on:click.stop' => 'x-on:click.stop',
203204
]),

src/Components/Forms/PageBuilderPreview.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function getPageBuilderData(): array
6565

6666
if ($this->singleItemPreview) {
6767
$blockType = $data['block_type'] ?? null;
68-
$id = $data['block_id'];
68+
$id = $data['block_id'] ?? null;
6969

7070
if ($blockType) {
7171
$closure = Closure::fromCallable([$blockType, 'formatForSingleView']);
@@ -76,6 +76,7 @@ public function getPageBuilderData(): array
7676
return [
7777
'id' => $id,
7878
'block_name' => $blockType::getBlockName(),
79+
'block_type' => $blockType,
7980
'data' => $formatted,
8081
];
8182
}
@@ -97,9 +98,11 @@ public function getPageBuilderData(): array
9798
return [
9899
...$item,
99100
'block_name' => $blockType::getBlockName(),
101+
'block_type' => $blockType,
100102
'data' => $formatted,
101103
];
102104
}
103105
}, $data);
106+
104107
}
105108
}

src/Models/PageBuilderBlock.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Database\Eloquent\Attributes\ScopedBy;
66
use Illuminate\Database\Eloquent\Concerns\HasUuids;
7+
use Illuminate\Database\Eloquent\Factories\HasFactory;
78
use Illuminate\Database\Eloquent\Model;
89
use Illuminate\Database\Eloquent\Relations\MorphTo;
910
use Redberry\PageBuilderPlugin\Abstracts\BaseBlock;
@@ -19,6 +20,7 @@
1920
#[ScopedBy(OrderScope::class)]
2021
class PageBuilderBlock extends Model
2122
{
23+
use HasFactory;
2224
use HasUuids;
2325

2426
protected $guarded = ['id'];

0 commit comments

Comments
 (0)