assertSet('from', '2026-07-15') ->assertSet('to', '2026-07-15'); } public function test_it_recomputes_stats_when_the_range_changes(): void { Article::factory()->count(3)->create(['created_at' => Carbon::parse('2026-07-10 12:00:00')]); Livewire::test(Dashboard::class) ->set('from', '2026-07-01') ->set('to', '2026-07-31') ->assertSee('3') ->set('from', '2026-08-01') ->set('to', '2026-08-31') ->assertSee('0'); } public function test_it_populates_the_range_when_a_preset_is_applied(): void { Carbon::setTestNow('2026-07-15 13:45:00'); Livewire::test(Dashboard::class) ->call('applyPreset', 'month') ->assertSet('from', '2026-07-01') ->assertSet('to', '2026-07-31'); } public function test_it_applies_the_all_preset_as_a_bounded_range(): void { Carbon::setTestNow('2026-07-15 13:45:00'); Livewire::test(Dashboard::class) ->call('applyPreset', 'all') ->assertSet('to', '2026-07-15'); } public function test_it_ignores_an_unknown_preset(): void { Carbon::setTestNow('2026-07-15 13:45:00'); Livewire::test(Dashboard::class) ->call('applyPreset', 'fortnight') ->assertSet('from', '2026-07-15') ->assertSet('to', '2026-07-15') ->assertHasNoErrors(); } public function test_it_reports_an_inverted_range_against_the_end_date(): void { Carbon::setTestNow('2026-07-15 13:45:00'); Livewire::test(Dashboard::class) ->set('from', '2026-07-31') ->set('to', '2026-07-01') ->assertHasErrors('to'); } public function test_it_blames_the_start_date_when_the_start_date_is_malformed(): void { Carbon::setTestNow('2026-07-15 13:45:00'); Livewire::test(Dashboard::class) ->set('from', 'not-a-date') ->assertHasErrors('from') ->assertHasNoErrors('to'); } public function test_it_blames_the_end_date_when_the_end_date_is_malformed(): void { Carbon::setTestNow('2026-07-15 13:45:00'); Livewire::test(Dashboard::class) ->set('to', 'not-a-date') ->assertHasErrors('to') ->assertHasNoErrors('from'); } public function test_it_reports_zero_stats_for_an_invalid_range(): void { Article::factory()->create(['created_at' => Carbon::parse('2026-07-10 12:00:00')]); Livewire::test(Dashboard::class) ->set('from', '2026-07-01') ->set('to', 'not-a-date') ->assertSet('rangeIsValid', false); } public function test_it_marks_a_well_formed_range_as_valid(): void { Livewire::test(Dashboard::class) ->set('from', '2026-07-01') ->set('to', '2026-07-31') ->assertSet('rangeIsValid', true); } public function test_it_renders_the_preset_buttons(): void { Livewire::test(Dashboard::class) ->assertSee('This Month') ->assertSee('All Time'); } public function test_it_renders_each_panel_in_its_own_island(): void { $html = Livewire::test(Dashboard::class)->html(); foreach (['system-overview', 'article-statistics'] as $island) { $this->assertSame( 1, substr_count($html, "[if FRAGMENT:type=island|name={$island}|"), "Expected exactly one [{$island}] island.", ); } } /** * @param Testable $component */ private function islandFragments(Testable $component): string { /** @var array $fragments */ $fragments = $component->effects['islandFragments'] ?? []; return implode("\n", $fragments); } public function test_it_re_renders_the_article_statistics_island_when_the_range_changes(): void { Article::factory()->count(3)->create(['created_at' => Carbon::parse('2026-07-10 12:00:00')]); $fragments = $this->islandFragments( Livewire::test(Dashboard::class)->call('applyRange', '2026-07-01', '2026-07-31') ); $this->assertMatchesRegularExpression('/Articles Fetched.*?>\s*3\s*count(3)->create(['created_at' => Carbon::parse('2026-07-10 12:00:00')]); $fragments = $this->islandFragments( Livewire::test(Dashboard::class)->call('applyRange', '2026-08-01', '2026-08-31') ); $this->assertMatchesRegularExpression('/Articles Fetched.*?>\s*0\s*islandFragments( Livewire::test(Dashboard::class)->call('applyRange', '2026-07-01', '2026-07-31') ); $this->assertStringContainsString('name=article-statistics|', $fragments); $this->assertStringNotContainsString('name=system-overview|', $fragments); $this->assertStringNotContainsString('Active Feeds', $fragments); } public function test_it_re_renders_the_article_statistics_island_when_a_preset_is_applied(): void { Carbon::setTestNow('2026-07-15 13:45:00'); Article::factory()->count(2)->create(['created_at' => Carbon::parse('2026-07-15 09:00:00')]); $fragments = $this->islandFragments( Livewire::test(Dashboard::class)->call('applyPreset', 'month') ); $this->assertMatchesRegularExpression('/Articles Fetched.*?>\s*2\s*