Startseite frei gestalten, Neuigkeiten-Block mit Kategorien-Filter (0.26.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 5m21s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m55s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m40s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m42s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m25s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m16s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m34s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m14s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 5m21s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m55s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m40s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m42s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m25s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m16s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m34s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m14s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6290e09074
commit
2c96fcce1c
151 changed files with 1515 additions and 317 deletions
127
tests/Feature/HomepageBuilderTest.php
Normal file
127
tests/Feature/HomepageBuilderTest.php
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Dashboard\Homepage;
|
||||
use App\Filament\Pages\DashboardSettings;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Pagebuilder\Blocks;
|
||||
use App\Support\Settings;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Inhaus\Plugins\News\Models\NewsCategory;
|
||||
use Inhaus\Plugins\News\Models\NewsPost;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class HomepageBuilderTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private User $admin;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = User::factory()->admin()->create(['first_name' => 'Ada']);
|
||||
}
|
||||
|
||||
/** Zwei Neuigkeiten-Bereiche nebeneinander: links nur „Wichtig zu wissen“, rechts alle anderen */
|
||||
private function twoNewsColumns(): array
|
||||
{
|
||||
$news = fn (string $title, string $filter) => ['type' => 'news.latest', 'data' => ['title' => $title, 'filter' => $filter, 'categories' => ['wichtig'], 'count' => 3, 'layout' => 'large', 'more_label' => 'Alle Beiträge']];
|
||||
|
||||
return ['blocks' => [
|
||||
['type' => 'columns', 'data' => ['layout' => '1-1'], 'items' => [
|
||||
['blocks' => [$news('Wichtig zu wissen', 'include')]],
|
||||
['blocks' => [$news('Aktuelles', 'exclude')]],
|
||||
]],
|
||||
['type' => 'dashboard.widget', 'data' => ['widget' => 'core.greeting']],
|
||||
]];
|
||||
}
|
||||
|
||||
public function test_editor_starts_from_the_current_tiles(): void
|
||||
{
|
||||
$this->actingAs($this->admin)->get('/startseite/gestalten')->assertOk()->assertInertia(fn (Assert $page) => $page
|
||||
->component('HomepageEditor')
|
||||
->where('state.mode', 'widgets')
|
||||
->where('blockTypes', fn ($types) => collect($types)->contains('key', 'dashboard.widget'))
|
||||
->where('content.blocks', fn ($blocks) => collect($blocks)->contains('type', 'columns')
|
||||
&& collect(collect($blocks)->firstWhere('type', 'columns')['items'][1]['blocks'])->contains(fn ($b) => $b['data']['widget'] === 'core.greeting')));
|
||||
|
||||
// Kachel-Blöcke gibt es nur auf der Startseite, nicht im Seiteneditor
|
||||
$this->assertFalse(collect(app(Blocks::class)->forEditor())->contains('key', 'dashboard.widget'));
|
||||
|
||||
$this->actingAs(User::factory()->create())->get('/startseite/gestalten')->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_draft_preview_publish_and_news_filters(): void
|
||||
{
|
||||
$important = NewsCategory::factory()->create(['name' => 'Wichtig zu wissen', 'slug' => 'wichtig']);
|
||||
$company = NewsCategory::factory()->create(['name' => 'Unternehmen', 'slug' => 'unternehmen']);
|
||||
NewsPost::factory()->create(['title' => 'Brandschutzübung', 'category_id' => $important->id, 'published_at' => now()->subHour()]);
|
||||
NewsPost::factory()->create(['title' => 'Sommerfest', 'category_id' => $company->id, 'published_at' => now()->subHours(2)]);
|
||||
$employee = User::factory()->create();
|
||||
|
||||
$this->actingAs($this->admin)->putJson('/startseite/gestalten/entwurf', ['content' => $this->twoNewsColumns()])->assertOk()->assertJsonPath('state.has_draft', true);
|
||||
|
||||
// Entwurf: nur in der Vorschau, die Startseite zeigt weiter Kacheln
|
||||
$this->actingAs($employee)->get('/')->assertInertia(fn (Assert $page) => $page->has('widgets')->missing('content'));
|
||||
$this->actingAs($employee)->get('/?entwurf=1')->assertInertia(fn (Assert $page) => $page->missing('content'));
|
||||
$this->actingAs($this->admin)->get('/?entwurf=1')->assertInertia(fn (Assert $page) => $page->where('preview', true)->has('content.blocks'));
|
||||
|
||||
$this->postJson('/startseite/gestalten/veroeffentlichen', ['activate' => true])->assertOk()->assertJsonPath('state.mode', 'builder');
|
||||
|
||||
$this->actingAs($employee)->get('/')->assertInertia(fn (Assert $page) => $page
|
||||
->where('content.blocks.0.items.0.blocks.0.props.posts.0.title', 'Brandschutzübung')
|
||||
->where('content.blocks.0.items.0.blocks.0.props.more_url', '/neuigkeiten?kategorie=wichtig')
|
||||
->where('content.blocks.0.items.1.blocks.0.props.posts', fn ($posts) => collect($posts)->pluck('title')->all() === ['Sommerfest'])
|
||||
->where('content.blocks.0.items.1.blocks.0.props.more_url', '/neuigkeiten?ohne=wichtig')
|
||||
->where('content.blocks.1.props.component', 'core::Greeting'));
|
||||
|
||||
// „Alle Beiträge“ rechts: alles außer „Wichtig zu wissen“
|
||||
$this->get('/neuigkeiten?ohne=wichtig')->assertInertia(fn (Assert $page) => $page
|
||||
->where('filter', 'Ohne: Wichtig zu wissen')
|
||||
->where('posts.data', fn ($posts) => collect($posts)->pluck('title')->all() === ['Sommerfest']));
|
||||
}
|
||||
|
||||
public function test_blocks_can_target_roles_and_versions_can_be_restored(): void
|
||||
{
|
||||
$pflege = Role::query()->create(['name' => 'Pflege']);
|
||||
$homepage = app(Homepage::class);
|
||||
$homepage->saveDraft(['blocks' => [
|
||||
['type' => 'heading', 'data' => ['text' => 'Für alle']],
|
||||
['type' => 'heading', 'data' => ['text' => 'Nur Pflege'], 'visibility' => ['role' => [(string) $pflege->id]]],
|
||||
]], $this->admin);
|
||||
$homepage->publish($this->admin);
|
||||
$homepage->setMode('builder');
|
||||
|
||||
$this->actingAs(User::factory()->create())->get('/')->assertInertia(fn (Assert $page) => $page->where('content.blocks', fn ($b) => count($b) === 1));
|
||||
$this->actingAs(User::factory()->withRoles([$pflege])->create())->get('/')->assertInertia(fn (Assert $page) => $page->where('content.blocks', fn ($b) => count($b) === 2));
|
||||
|
||||
$homepage->saveDraft(['blocks' => []], $this->admin);
|
||||
$homepage->publish($this->admin);
|
||||
$first = $homepage->revisions()[1]['id'];
|
||||
|
||||
$this->actingAs($this->admin)->postJson("/startseite/gestalten/versionen/{$first}/wiederherstellen")->assertOk()->assertJsonCount(2, 'content.blocks');
|
||||
}
|
||||
|
||||
public function test_admin_switches_mode_without_losing_the_tile_layout(): void
|
||||
{
|
||||
app(Settings::class)->set('dashboard.layout', ['core.greeting' => ['sort' => 0, 'visible' => false]]);
|
||||
app(Homepage::class)->saveDraft(['blocks' => [['type' => 'heading', 'data' => ['text' => 'Hallo']]]], $this->admin);
|
||||
app(Homepage::class)->publish($this->admin);
|
||||
|
||||
$this->actingAs($this->admin);
|
||||
Livewire::test(DashboardSettings::class)->set('data.mode', 'builder')->call('save');
|
||||
|
||||
$this->assertSame('builder', app(Homepage::class)->mode());
|
||||
$this->assertFalse(app(Settings::class)->get('dashboard.layout')['core.greeting']['visible']);
|
||||
$this->get('/')->assertInertia(fn (Assert $page) => $page->where('content.blocks.0.data.text', 'Hallo'));
|
||||
|
||||
Livewire::test(DashboardSettings::class)->set('data.mode', 'widgets')->call('save');
|
||||
$this->get('/')->assertInertia(fn (Assert $page) => $page->has('widgets')->missing('content'));
|
||||
}
|
||||
}
|
||||
|
|
@ -8,12 +8,14 @@ use App\Notifications\PortalNotification;
|
|||
use App\Pagebuilder\Content;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Inhaus\Plugins\Forms\Models\Form;
|
||||
use Inhaus\Plugins\News\Models\NewsCategory;
|
||||
use Inhaus\Plugins\News\Models\NewsPost;
|
||||
use Inhaus\Plugins\Pages\Models\Page;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
|
|
@ -169,7 +171,7 @@ class NewsWorkflowTest extends TestCase
|
|||
NewsPost::factory()->draft()->create(['category_id' => $this->mavInfo->id, 'title' => 'Entwurf']);
|
||||
|
||||
$content = app(Content::class);
|
||||
$rendered = $content->render($content->sanitize(['blocks' => [['type' => 'news.latest', 'data' => ['category' => 'mav-info', 'count' => 5]]]]), User::factory()->create());
|
||||
$rendered = $content->render($content->sanitize(['blocks' => [['type' => 'news.latest', 'data' => ['filter' => 'include', 'categories' => ['mav-info'], 'count' => 5]]]]), User::factory()->create());
|
||||
|
||||
$this->assertSame(['Aus der MAV'], array_column($rendered['blocks'][0]['props']['posts'], 'title'));
|
||||
$this->assertSame('/neuigkeiten?kategorie=mav-info', $rendered['blocks'][0]['props']['more_url']);
|
||||
|
|
@ -204,4 +206,21 @@ class NewsWorkflowTest extends TestCase
|
|||
|
||||
$this->actingAs($this->editor)->put('/redaktion/neuigkeiten/'.$post->id, $this->payload(['action' => 'publish', 'form_id' => 99999]))->assertSessionHasErrors('form_id');
|
||||
}
|
||||
|
||||
public function test_old_single_category_news_blocks_are_converted(): void
|
||||
{
|
||||
$page = Page::query()->create(['title' => 'Alt']);
|
||||
DB::table('pages')->where('id', $page->id)->update(['content' => json_encode(['blocks' => [
|
||||
['id' => 'blkcols1', 'type' => 'columns', 'data' => ['layout' => '1-1'], 'items' => [
|
||||
['id' => 'itm1', 'blocks' => [['id' => 'blknews1', 'type' => 'news.latest', 'data' => ['title' => 'MAV', 'category' => 'mav-info', 'count' => 3, 'layout' => 'cards']]]],
|
||||
['id' => 'itm2', 'blocks' => [['id' => 'blknews2', 'type' => 'news.latest', 'data' => ['title' => 'Alle', 'category' => '', 'count' => 3, 'layout' => 'list']]]],
|
||||
]],
|
||||
]])]);
|
||||
|
||||
(require base_path('plugins-core/news/database/migrations/2026_10_11_000002_convert_news_block_category_filter.php'))->up();
|
||||
|
||||
$items = $page->fresh()->content['blocks'][0]['items'];
|
||||
$this->assertSame(['title' => 'MAV', 'count' => 3, 'layout' => 'cards', 'filter' => 'include', 'categories' => ['mav-info']], $items[0]['blocks'][0]['data']);
|
||||
$this->assertSame('all', $items[1]['blocks'][0]['data']['filter']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue