Oben im Seitenmenue waehlt man die Wohnung; Listen, neue Eintraege, Belegungsplan und Preise & Angebote folgen ihr. Ein geoeffneter Eintrag einer anderen Wohnung schaltet auf diese um. Galerie und Ersatz-Titelbild der Website zeigen nur Fotos der Wohnung des Bausteins und Fotos ohne Wohnung. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
151 lines
6.8 KiB
PHP
151 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Enums\PhotoCategory;
|
|
use App\Filament\Pages\OccupancyCalendar;
|
|
use App\Filament\Pages\PricesAndOffers;
|
|
use App\Filament\Resources\Amenities\AmenityResource;
|
|
use App\Filament\Resources\Amenities\Pages\CreateAmenity;
|
|
use App\Filament\Resources\Amenities\Pages\ListAmenities;
|
|
use App\Filament\Resources\Photos\Pages\ListPhotos;
|
|
use App\Filament\Resources\Properties\PropertyResource;
|
|
use App\Models\Amenity;
|
|
use App\Models\Page;
|
|
use App\Models\Photo;
|
|
use App\Models\Property;
|
|
use App\Models\Site;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Support\CurrentProperty;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
class CurrentPropertyTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private Property $coast;
|
|
|
|
private Property $mountains;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->actingAs(User::factory()->create());
|
|
$this->coast = Property::factory()->create(['name' => 'Küstenwohnung']);
|
|
$this->mountains = Property::factory()->create(['name' => 'Bergwohnung']);
|
|
}
|
|
|
|
public function test_menu_shows_the_switcher_with_all_apartments_and_starts_with_the_first_active_one(): void
|
|
{
|
|
$this->get(OccupancyCalendar::getUrl())
|
|
->assertOk()
|
|
->assertSee('Wohnung wählen')
|
|
->assertSeeInOrder(['Bergwohnung', 'Küstenwohnung'])
|
|
->assertSee('Einstellungen der Wohnung')
|
|
->assertSee(PropertyResource::getUrl('edit', ['record' => $this->coast]), false);
|
|
}
|
|
|
|
public function test_a_single_apartment_is_named_without_a_choice(): void
|
|
{
|
|
$this->mountains->delete();
|
|
|
|
$this->get(OccupancyCalendar::getUrl())->assertOk()->assertSee('Küstenwohnung')->assertDontSee('Wohnung wählen');
|
|
}
|
|
|
|
public function test_switching_returns_to_the_page_and_lists_follow_the_chosen_apartment(): void
|
|
{
|
|
Amenity::factory()->for($this->coast)->create(['name' => 'Strandkorb']);
|
|
Amenity::factory()->for($this->mountains)->create(['name' => 'Kachelofen']);
|
|
$list = AmenityResource::getUrl('index');
|
|
|
|
Livewire::test(ListAmenities::class)->assertSee('Strandkorb')->assertDontSee('Kachelofen');
|
|
|
|
$this->post(route('filament.admin.switch-property'), ['property' => $this->mountains->id, 'return' => $list])->assertRedirect($list);
|
|
|
|
$this->assertSame($this->mountains->id, app(CurrentProperty::class)->id());
|
|
Livewire::test(ListAmenities::class)->assertSee('Kachelofen')->assertDontSee('Strandkorb');
|
|
}
|
|
|
|
public function test_switching_leaves_a_record_page_for_its_list_and_the_apartment_settings_for_the_chosen_ones(): void
|
|
{
|
|
$amenity = Amenity::factory()->for($this->coast)->create();
|
|
|
|
$this->post(route('filament.admin.switch-property'), ['property' => $this->mountains->id, 'return' => AmenityResource::getUrl('edit', ['record' => $amenity])])
|
|
->assertRedirect(AmenityResource::getUrl('index'));
|
|
$this->post(route('filament.admin.switch-property'), ['property' => $this->coast->id, 'return' => PropertyResource::getUrl('edit', ['record' => $this->mountains])])
|
|
->assertRedirect(PropertyResource::getUrl('edit', ['record' => $this->coast]));
|
|
$this->post(route('filament.admin.switch-property'), ['property' => $this->coast->id, 'return' => OccupancyCalendar::getUrl(['monat' => '2026-11', 'wohnung' => $this->mountains->id])])
|
|
->assertRedirect(OccupancyCalendar::getUrl(['monat' => '2026-11']));
|
|
$this->post(route('filament.admin.switch-property'), ['property' => $this->coast->id, 'return' => 'https://example.com/admin'])
|
|
->assertRedirect(route('filament.admin.pages.dashboard'));
|
|
}
|
|
|
|
public function test_another_landlords_apartment_cannot_be_chosen(): void
|
|
{
|
|
$foreign = Property::factory()->create(['tenant_id' => Tenant::factory()->create()->id]);
|
|
|
|
$this->post(route('filament.admin.switch-property'), ['property' => $foreign->id])->assertNotFound();
|
|
$this->assertSame($this->coast->id, app(CurrentProperty::class)->id());
|
|
}
|
|
|
|
public function test_opening_a_record_of_another_apartment_switches_to_it(): void
|
|
{
|
|
$amenity = Amenity::factory()->for($this->mountains)->create();
|
|
|
|
$this->get(AmenityResource::getUrl('edit', ['record' => $amenity]))->assertOk();
|
|
|
|
$this->assertSame($this->mountains->id, app(CurrentProperty::class)->id());
|
|
}
|
|
|
|
public function test_new_records_belong_to_the_chosen_apartment(): void
|
|
{
|
|
app(CurrentProperty::class)->select($this->mountains);
|
|
|
|
Livewire::test(CreateAmenity::class)->assertSchemaStateSet(['property_id' => $this->mountains->id]);
|
|
}
|
|
|
|
public function test_photo_list_shows_the_apartment_and_the_shared_area_photos(): void
|
|
{
|
|
app(CurrentProperty::class)->select($this->mountains);
|
|
$own = Photo::factory()->create(['property_id' => $this->mountains->id, 'alt_text' => 'Blick auf die Alpen']);
|
|
$area = Photo::factory()->create(['property_id' => null, 'category' => PhotoCategory::Area, 'alt_text' => 'Wanderweg']);
|
|
$other = Photo::factory()->create(['property_id' => $this->coast->id, 'alt_text' => 'Blick auf die Ostsee']);
|
|
|
|
Livewire::test(ListPhotos::class)->assertCanSeeTableRecords([$own, $area])->assertCanNotSeeTableRecords([$other]);
|
|
}
|
|
|
|
public function test_pages_for_one_apartment_follow_the_choice_and_name_it(): void
|
|
{
|
|
app(CurrentProperty::class)->select($this->mountains);
|
|
|
|
Livewire::test(PricesAndOffers::class)->assertSet('propertyId', $this->mountains->id)->assertSee('Bergwohnung');
|
|
$this->get(OccupancyCalendar::getUrl(['wohnung' => $this->coast->id]))->assertOk();
|
|
$this->assertSame($this->coast->id, app(CurrentProperty::class)->id());
|
|
}
|
|
|
|
public function test_website_gallery_shows_only_the_photos_of_the_sections_apartment(): void
|
|
{
|
|
$this->withoutVite();
|
|
$site = Site::factory()->create(['domain' => 'wohnungen.test', 'is_default' => true]);
|
|
$this->coast->update(['site_id' => $site->id]);
|
|
$this->mountains->update(['site_id' => $site->id]);
|
|
Photo::factory()->create(['property_id' => $this->coast->id, 'alt_text' => 'Blick auf die Ostsee']);
|
|
Photo::factory()->create(['property_id' => $this->mountains->id, 'alt_text' => 'Blick auf die Alpen']);
|
|
Photo::factory()->create(['property_id' => null, 'alt_text' => 'Gemeinsamer Ort']);
|
|
Page::factory()->for($site)->create([
|
|
'slug' => Page::HOME,
|
|
'sections' => [['type' => 'gallery', 'data' => ['heading' => 'Bilder', 'property_id' => $this->mountains->id]]],
|
|
]);
|
|
|
|
$this->get('http://wohnungen.test/')
|
|
->assertOk()
|
|
->assertSee('Blick auf die Alpen')
|
|
->assertSee('Gemeinsamer Ort')
|
|
->assertDontSee('Blick auf die Ostsee');
|
|
}
|
|
}
|