Current state with latest updates
This commit is contained in:
@@ -10,8 +10,6 @@ use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
use Klevze\ControlPanel\Models\Admin\AdminVerification;
|
||||
use Klevze\ControlPanel\Core\Structs\MenuRootItem;
|
||||
use Klevze\ControlPanel\Framework\Core\Menu as ControlPanelMenu;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
@@ -81,20 +79,35 @@ it('blocks non staff users from the featured artworks admin area', function ():
|
||||
->assertRedirect(route('cp.login'));
|
||||
});
|
||||
|
||||
it('registers the featured artworks entry in the cpad menu', function (): void {
|
||||
$sidebarMenu = collect(app(ControlPanelMenu::class)->getSidebarMenu());
|
||||
it('resolves featured artwork admin routes to the current moderation surface, not the legacy cpad menu target', function (): void {
|
||||
// The original version of this test asserted that the legacy cpad sidebar (built by
|
||||
// packages/klevze/Plugins/Artworks/ServiceProvider::boot()) had a "Featured Artworks"
|
||||
// item under the "Artworks" root pointing at admin.cp.artworks.featured.main. That
|
||||
// item was removed once featured-artwork management moved to the /moderation surface
|
||||
// (routes/web.php, name admin.artworks.featured.*) — admin.cp.artworks.featured.main
|
||||
// now exists only as a redirect alias to /moderation/artworks/featured
|
||||
// (packages/klevze/Plugins/Artworks/Routes/admin.php:24), and the new surface's
|
||||
// navigation is owned by the React/Inertia frontend, not this PHP-built sidebar.
|
||||
//
|
||||
// The sidebar itself can't be asserted on here at all: ServiceProvider::boot() only
|
||||
// registers menu items when shouldRegisterControlPanelUi() is true, which explicitly
|
||||
// returns false whenever app()->runningInConsole() is true — and `php artisan test`
|
||||
// always runs in console, so getSidebarMenu() is empty for every test in this suite,
|
||||
// regardless of this change. That's an environment property of the legacy menu
|
||||
// builder, not something this test can meaningfully exercise.
|
||||
//
|
||||
// What's left to verify, and is exercised by other tests in this file (see "renders
|
||||
// the featured artworks admin index..." and "clears homepage hero cache..."), is that
|
||||
// the legacy route still redirects to the canonical surface rather than 404ing or
|
||||
// rendering the retired page directly.
|
||||
expect(route('admin.artworks.featured.main'))->toBe(url('/moderation/artworks/featured'));
|
||||
expect(route('admin.cp.artworks.featured.main'))->toBe(url('/cp/artworks/featured'));
|
||||
|
||||
$editorialRoot = $sidebarMenu
|
||||
->first(fn ($item): bool => $item instanceof MenuRootItem && $item->getName() === 'Artworks');
|
||||
$admin = createControlPanelAdmin();
|
||||
|
||||
expect($editorialRoot)->toBeInstanceOf(MenuRootItem::class);
|
||||
|
||||
$featuredItem = collect($editorialRoot->getItems())
|
||||
->first(fn ($item): bool => ($item->name ?? null) === 'Featured Artworks');
|
||||
|
||||
expect($featuredItem)->not->toBeNull()
|
||||
->and($featuredItem->mainRoute)->toBe('admin.cp.artworks.featured.main')
|
||||
->and($featuredItem->icon)->toBe('fas fa-star');
|
||||
$this->actingAs($admin)->actingAs($admin, 'controlpanel')
|
||||
->get(route('admin.cp.artworks.featured.main'))
|
||||
->assertRedirect('/moderation/artworks/featured');
|
||||
});
|
||||
|
||||
it('renders the featured artworks admin index with the current winner summary', function (): void {
|
||||
@@ -108,17 +121,20 @@ it('renders the featured artworks admin index with the current winner summary',
|
||||
medalScore($higherMedal, 12);
|
||||
medalScore($runnerUp, 3);
|
||||
|
||||
// admin.cp.artworks.featured.main (legacy cpad alias) now just redirects to the
|
||||
// canonical /moderation surface (packages/klevze/Plugins/Artworks/Routes/admin.php:24),
|
||||
// so the page itself is rendered at admin.artworks.featured.main.
|
||||
$this->actingAs($admin)->actingAs($admin, 'controlpanel')
|
||||
->get(route('admin.cp.artworks.featured.main'))
|
||||
->get(route('admin.artworks.featured.main'))
|
||||
->assertOk()
|
||||
->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->component('Collection/FeaturedArtworksAdmin')
|
||||
->component('Moderation/FeaturedArtworks')
|
||||
->where('winner.artwork.id', $higherMedal->id)
|
||||
->where('winner.medals.score_30d', 12)
|
||||
->where('winner.selection_reason', 'Tied on priority, won on higher 30-day medal score.')
|
||||
->where('entries.0.is_winner', true)
|
||||
->where('entries.0.artwork.id', $higherMedal->id)
|
||||
->where('endpoints.store', route('admin.cp.artworks.featured.store')));
|
||||
->where('endpoints.store', route('admin.artworks.featured.store')));
|
||||
});
|
||||
|
||||
it('allows admins to create featured rows', function (): void {
|
||||
@@ -259,11 +275,12 @@ it('marks expired and ineligible rows on the index page', function (): void {
|
||||
featureRow($privateArtwork, ['priority' => 300]);
|
||||
featureRow($expiredArtwork, ['priority' => 200, 'expires_at' => now()->subMinute()]);
|
||||
|
||||
// See note above: the cpad alias redirects, so the page renders at admin.artworks.featured.main.
|
||||
$this->actingAs($admin)->actingAs($admin, 'controlpanel')
|
||||
->get(route('admin.cp.artworks.featured.main'))
|
||||
->get(route('admin.artworks.featured.main'))
|
||||
->assertOk()
|
||||
->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->component('Collection/FeaturedArtworksAdmin')
|
||||
->component('Moderation/FeaturedArtworks')
|
||||
->where('entries.0.artwork.id', $privateArtwork->id)
|
||||
->where('entries.0.eligibility.is_eligible', false)
|
||||
->where('entries.0.eligibility.reasons.0', 'Private')
|
||||
@@ -274,10 +291,30 @@ it('marks expired and ineligible rows on the index page', function (): void {
|
||||
});
|
||||
|
||||
it('clears homepage hero cache after create update toggle and delete actions', function (): void {
|
||||
// HomepageService::clearFeaturedAndMedalCaches() forgets homepage.hero.{segment} for
|
||||
// each viewer-visibility segment (not a bare "homepage.hero" key) — the segmentation
|
||||
// was introduced by a prior commit (see HomepageService::viewerCacheSegment()). Assert
|
||||
// against the real segmented keys instead of the pre-segmentation key this test used.
|
||||
$heroCacheKeys = [
|
||||
'homepage.hero.visibility-hide',
|
||||
'homepage.hero.visibility-blur',
|
||||
'homepage.hero.visibility-show',
|
||||
];
|
||||
$seedHeroCache = function () use ($heroCacheKeys): void {
|
||||
foreach ($heroCacheKeys as $key) {
|
||||
Cache::put($key, ['stale' => true], 600);
|
||||
}
|
||||
};
|
||||
$assertHeroCacheCleared = function () use ($heroCacheKeys): void {
|
||||
foreach ($heroCacheKeys as $key) {
|
||||
expect(Cache::has($key))->toBeFalse();
|
||||
}
|
||||
};
|
||||
|
||||
$admin = createControlPanelAdmin();
|
||||
$artwork = adminArtwork();
|
||||
|
||||
Cache::put('homepage.hero', ['stale' => true], 600);
|
||||
$seedHeroCache();
|
||||
|
||||
$this->actingAs($admin)->actingAs($admin, 'controlpanel')
|
||||
->postJson(route('admin.cp.artworks.featured.store'), [
|
||||
@@ -289,11 +326,11 @@ it('clears homepage hero cache after create update toggle and delete actions', f
|
||||
])
|
||||
->assertOk();
|
||||
|
||||
expect(Cache::has('homepage.hero'))->toBeFalse();
|
||||
$assertHeroCacheCleared();
|
||||
|
||||
$feature = ArtworkFeature::query()->firstOrFail();
|
||||
|
||||
Cache::put('homepage.hero', ['stale' => true], 600);
|
||||
$seedHeroCache();
|
||||
$this->actingAs($admin)->actingAs($admin, 'controlpanel')
|
||||
->patchJson(route('admin.cp.artworks.featured.update', ['feature' => $feature->id]), [
|
||||
'priority' => 110,
|
||||
@@ -302,17 +339,17 @@ it('clears homepage hero cache after create update toggle and delete actions', f
|
||||
'is_active' => true,
|
||||
])
|
||||
->assertOk();
|
||||
expect(Cache::has('homepage.hero'))->toBeFalse();
|
||||
$assertHeroCacheCleared();
|
||||
|
||||
Cache::put('homepage.hero', ['stale' => true], 600);
|
||||
$seedHeroCache();
|
||||
$this->actingAs($admin)->actingAs($admin, 'controlpanel')
|
||||
->patchJson(route('admin.cp.artworks.featured.toggle', ['feature' => $feature->id]))
|
||||
->assertOk();
|
||||
expect(Cache::has('homepage.hero'))->toBeFalse();
|
||||
$assertHeroCacheCleared();
|
||||
|
||||
Cache::put('homepage.hero', ['stale' => true], 600);
|
||||
$seedHeroCache();
|
||||
$this->actingAs($admin)->actingAs($admin, 'controlpanel')
|
||||
->deleteJson(route('admin.cp.artworks.featured.delete', ['feature' => $feature->id]))
|
||||
->assertOk();
|
||||
expect(Cache::has('homepage.hero'))->toBeFalse();
|
||||
$assertHeroCacheCleared();
|
||||
});
|
||||
Reference in New Issue
Block a user