homeos/tests/Feature/HomeTest.php

59 lines
2.0 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Device;
use App\Models\DeviceState;
use App\Models\Entity;
use App\Models\Room;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class HomeTest extends TestCase
{
use RefreshDatabase;
public function test_host_page_renders_for_authenticated_user(): void
{
$this->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');
}
}