Files
LarsandClaude Opus 5.5 6f9aa46943 v0.11: Umsetzungsbericht, Abnahme-Drehbuch, Status; InboxTest wiederhergestellt
- Umsetzungsergebnis mit Rückverfolgung CH-01–18, S1–S6, E-032–038,
  M01–M12, Entscheidungen, Einschränkungen und Go-live-Bedingungen.
- Abnahme auf dem Testsystem: benötigte Dienste, Testkonfiguration,
  Drehbuch ohne manuelle Ersatzschritte.
- Der bestehende InboxTest (Postfach der Vermieterin) war versehentlich
  überschrieben worden; wiederhergestellt, die U5-Tests heißen jetzt
  GuestMailInboxTest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 14:03:17 +01:00

90 lines
3.5 KiB
PHP

<?php
namespace Tests\Feature;
use App\Enums\InboxMessageKind;
use App\Filament\Resources\InboxMessages\InboxMessageResource;
use App\Filament\Resources\InboxMessages\Pages\ListInboxMessages;
use App\Models\Channel;
use App\Models\InboxMessage;
use App\Models\Property;
use App\Models\User;
use App\Support\CurrentProperty;
use App\Support\Inbox;
use Filament\Actions\Testing\TestAction;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class InboxTest extends TestCase
{
use RefreshDatabase;
private Channel $channel;
protected function setUp(): void
{
parent::setUp();
$this->actingAs(User::factory()->create());
$this->channel = Channel::factory()->for(Property::factory())->create(['name' => 'FeWo-direkt']);
}
public function test_a_finding_is_posted_only_once(): void
{
$inbox = app(Inbox::class);
$first = $inbox->post(InboxMessageKind::ChannelConflict, 'x', 'Mögliche Doppelbuchung', 'Text', $this->channel);
$again = $inbox->post(InboxMessageKind::ChannelConflict, 'x', 'Mögliche Doppelbuchung', 'Text', $this->channel);
$this->assertNotNull($first);
$this->assertNull($again);
$this->assertSame($this->channel->property_id, $first->property_id);
$this->assertSame(1, InboxMessage::count());
}
public function test_menu_shows_the_number_of_unread_messages(): void
{
InboxMessage::factory()->for($this->channel)->count(2)->create();
InboxMessage::factory()->for($this->channel)->read()->create();
$this->assertSame('2', InboxMessageResource::getNavigationBadge());
$this->get(InboxMessageResource::getUrl('index'))->assertOk()->assertSee('Postfach');
}
public function test_messages_can_be_marked_as_read_and_opened(): void
{
$message = InboxMessage::factory()->for($this->channel)->create(['subject' => 'Mögliche Doppelbuchung über FeWo-direkt', 'action_url' => 'http://localhost/admin/belegung']);
$other = InboxMessage::factory()->for($this->channel)->create();
Livewire::test(ListInboxMessages::class)
->assertCanSeeTableRecords([$message, $other])
->assertSee('Mögliche Doppelbuchung über FeWo-direkt')
->callAction(TestAction::make('toggleRead')->table($other))
->callAction(TestAction::make('open')->table($message))
->assertRedirect('http://localhost/admin/belegung');
$this->assertTrue($message->fresh()->isRead());
$this->assertTrue($other->fresh()->isRead());
$this->assertNull(InboxMessageResource::getNavigationBadge());
}
public function test_read_all_marks_only_the_chosen_apartments_messages(): void
{
$otherChannel = Channel::factory()->for(Property::factory())->create();
$own = InboxMessage::factory()->for($this->channel)->create(['property_id' => $this->channel->property_id]);
$general = InboxMessage::factory()->create(['tenant_id' => $this->channel->tenant_id]);
$foreign = InboxMessage::factory()->for($otherChannel)->create(['property_id' => $otherChannel->property_id]);
app(CurrentProperty::class)->select($this->channel->property);
Livewire::test(ListInboxMessages::class)
->assertCanSeeTableRecords([$own, $general])
->assertCanNotSeeTableRecords([$foreign])
->callAction('readAll');
$this->assertTrue($own->fresh()->isRead());
$this->assertTrue($general->fresh()->isRead());
$this->assertFalse($foreign->fresh()->isRead());
}
}