<?php

use App\Filament\Resources\StationResource\Pages\ListStations;
use App\Models\Station;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);

beforeEach(function () {
    $this->admin = User::factory()->admin()->create();
    $this->actingAs($this->admin);
});

it('renders the station list', function () {
    $stations = Station::factory()->count(3)->create();

    Livewire::test(ListStations::class)
        ->assertOk()
        ->assertCanSeeTableRecords($stations);
});

it('filters to supermarkets only', function () {
    $regular = Station::factory()->create(['is_supermarket' => false]);
    $super = Station::factory()->supermarket()->create();

    Livewire::test(ListStations::class)
        ->filterTable('is_supermarket', true)
        ->assertCanSeeTableRecords([$super])
        ->assertCanNotSeeTableRecords([$regular]);
});

it('has a trigger full poll header action', function () {
    Livewire::test(ListStations::class)
        ->assertActionExists('triggerFullPoll');
});
