Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Paths are relative to `modules/roadmap/` unless they say otherwise. Commands run

## Overview

Public roadmap board with feature requests, upvotes, comments, team replies, and duplicate merging. Filament admin at `/admin` → Roadmap.
Public roadmap board with feature requests, upvotes, comments, team replies, and duplicate merging. Filament admin at `/admin` → Roadmap. `Modules\Roadmap\Filament\Widgets\RoadmapAttentionWidget` puts "Suggestions to review" (status Under Review) on the dashboard, sort 21, only while there are any.

---

Expand Down
45 changes: 45 additions & 0 deletions src/Filament/Widgets/RoadmapAttentionWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Modules\Roadmap\Filament\Widgets;

use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Modules\Roadmap\Enums\RoadmapStatus;
use Modules\Roadmap\Filament\Resources\Roadmap\RoadmapItemResource;
use Modules\Roadmap\Models\RoadmapItem;

/** Attention band (20–29): only while suggestions wait for review. */
class RoadmapAttentionWidget extends StatsOverviewWidget
{
protected static ?int $sort = 21;

protected static bool $isLazy = false;

protected ?string $pollingInterval = null;

/** Half the dashboard: pairs with its neighbour in the band. */
protected int|string|array $columnSpan = 1;

protected int|array|null $columns = 1;

public static function canView(): bool
{
return (auth()->user()?->can('manage roadmap') ?? false) && self::underReview() > 0;
}

protected function getStats(): array
{
return [
Stat::make(__('Suggestions to review'), self::underReview())
->description(__('Waiting for a status'))
->descriptionIcon('heroicon-m-light-bulb')
->color('warning')
->url(RoadmapItemResource::getUrl('index')),
];
}

private static function underReview(): int
{
return RoadmapItem::where('status', RoadmapStatus::UnderReview)->count();
}
}
45 changes: 45 additions & 0 deletions tests/Feature/RoadmapAttentionWidgetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Modules\Roadmap\Tests\Feature;

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Modules\Roadmap\Enums\RoadmapStatus;
use Modules\Roadmap\Filament\Widgets\RoadmapAttentionWidget;
use Modules\Roadmap\Models\RoadmapItem;
use Spatie\Permission\Models\Permission;
use Tests\TestCase;

class RoadmapAttentionWidgetTest extends TestCase
{
use RefreshDatabase;

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

Permission::findOrCreate('manage roadmap');
$this->actingAs(User::factory()->create()->givePermissionTo('manage roadmap'));
}

/** Attention band (20–29): roadmap is 21, after billing. */
public function test_shown_only_with_suggestions_to_review(): void
{
$this->assertSame(21, RoadmapAttentionWidget::getSort());
RoadmapItem::factory()->create(['status' => RoadmapStatus::Planned]);
$this->assertFalse(RoadmapAttentionWidget::canView());

RoadmapItem::factory()->count(2)->create(['status' => RoadmapStatus::UnderReview]);
$this->assertTrue(RoadmapAttentionWidget::canView());
Livewire::test(RoadmapAttentionWidget::class)->assertSee(['Suggestions to review', '2']);
}

public function test_needs_the_roadmap_permission(): void
{
RoadmapItem::factory()->create(['status' => RoadmapStatus::UnderReview]);
$this->actingAs(User::factory()->create());

$this->assertFalse(RoadmapAttentionWidget::canView());
}
}
13 changes: 7 additions & 6 deletions tests/e2e/tests/roadmap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,19 @@ test.describe('Roadmap', () => {
await expect(panel.getByTestId(`vote-count-${item.id}`)).toHaveText(
'1',
);
await expect(page.locator('[data-sonner-toast]')).toContainText(
'Upvoted!',
);
// Toasts stack (sign-in, then each vote): look a toast up by its text.
await expect(
page.locator('[data-sonner-toast]', { hasText: 'Upvoted!' }),
).toBeVisible();
await expect(panel).toBeVisible();
await expect(page).toHaveURL(new RegExp(`/roadmap/${item.slug}$`));
const card = page.getByTestId(`roadmap-item-${item.id}`);
await expect(card.getByTestId(`vote-count-${item.id}`)).toHaveText('1');

await panel.getByTestId(`vote-btn-${item.id}`).click();
await expect(page.locator('[data-sonner-toast]').last()).toContainText(
'Vote removed',
);
await expect(
page.locator('[data-sonner-toast]', { hasText: 'Vote removed' }),
).toBeVisible();
await expect(panel).toBeVisible();
await expect(page).toHaveURL(new RegExp(`/roadmap/${item.slug}$`));
await expect(panel.getByTestId(`vote-count-${item.id}`)).toHaveText(
Expand Down
Loading