actingAs(User::factory()->create()) ->get('/host') ->assertOk() ->assertSee(__('host.title')) ->assertSee(__('host.services_title')); } public function test_dashboard_shows_rooms_and_device_state(): void { $room = Room::create(['name' => 'Testraum']); $device = Device::create([ 'name' => 'Testlampe', 'vendor' => 'Shelly', 'model' => 'Plug S', 'protocol' => 'mqtt', 'room_id' => $room->id, 'status' => 'active', 'last_seen_at' => now(), ]); $entity = Entity::create(['device_id' => $device->id, 'type' => 'switch', 'key' => 'switch:0', 'name' => 'Testlampe']); DeviceState::create(['entity_id' => $entity->id, 'state' => ['on' => true]]); $this->actingAs(User::factory()->create()) ->get('/dashboard') ->assertOk() ->assertSee('Testraum') ->assertSee('Testlampe'); } public function test_dashboard_surfaces_a_low_battery_warning(): void { $room = Room::create(['name' => 'Testraum']); $device = Device::create([ 'name' => 'Türsensor', 'room_id' => $room->id, 'status' => 'active', 'last_seen_at' => now(), ]); $battery = Entity::create(['device_id' => $device->id, 'type' => 'battery', 'key' => 'battery:0', 'name' => 'Batterie']); DeviceState::create(['entity_id' => $battery->id, 'state' => ['percent' => 5]]); $this->actingAs(User::factory()->create()) ->get('/dashboard') ->assertOk() ->assertSee(__('dashboard.warnings_title')) ->assertSee('Türsensor'); } public function test_room_less_device_appears_in_home_status(): void { $device = Device::create(['name' => 'Heimloser Sensor', 'status' => 'active', 'last_seen_at' => now(), 'room_id' => null]); $battery = Entity::create(['device_id' => $device->id, 'type' => 'battery', 'key' => 'battery:0', 'name' => 'Batterie']); DeviceState::create(['entity_id' => $battery->id, 'state' => ['percent' => 5]]); $this->actingAs(User::factory()->create()) ->get('/dashboard') ->assertOk() ->assertSee('Heimloser Sensor') ->assertSee(__('dashboard.no_room')); } public function test_device_room_update_rejects_invalid_room(): void { $device = Device::create(['name' => 'Lampe', 'status' => 'active', 'last_seen_at' => now()]); $this->actingAs(User::factory()->create()); Livewire::test(Show::class, ['device' => $device]) ->set('roomId', 999999) ->call('saveRoom') ->assertHasErrors('roomId'); $this->assertNull($device->fresh()->room_id); } }