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()); } }