10-04-2026
This commit is contained in:
parent
4d6b4930b2
commit
4bb89aad8c
836 changed files with 52961 additions and 5950 deletions
154
tests/Feature/CabinetInfoTabletTest.php
Normal file
154
tests/Feature/CabinetInfoTabletTest.php
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
<?php
|
||||
|
||||
use App\Livewire\Admin\Cms\CabinetInfoTablet;
|
||||
use App\Models\CabinetTabletSetting;
|
||||
use App\Models\User;
|
||||
use Livewire\Livewire;
|
||||
|
||||
beforeEach(function () {
|
||||
// Set the portal domain so route() resolves domain-scoped routes
|
||||
$portalDomain = config('domains.domain_portal');
|
||||
Livewire::withoutLazyLoading();
|
||||
url()->forceRootUrl('https://'.$portalDomain);
|
||||
});
|
||||
|
||||
test('cabinet info tablet page requires authentication', function () {
|
||||
$response = $this->get(route('admin.cms.cabinet-tablet'));
|
||||
|
||||
$response->assertRedirect('/login');
|
||||
});
|
||||
|
||||
test('cabinet info tablet page renders for authenticated users', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = $this->get(route('admin.cms.cabinet-tablet'));
|
||||
|
||||
$response->assertSuccessful();
|
||||
$response->assertSeeLivewire(CabinetInfoTablet::class);
|
||||
});
|
||||
|
||||
test('component mounts with existing settings', function () {
|
||||
CabinetTabletSetting::factory()->create([
|
||||
'store_status' => 'notice',
|
||||
'notice_headline' => 'Sonderverkauf',
|
||||
'contact_phone' => '0521 12345',
|
||||
'hours_monday_open' => '10:00',
|
||||
'hours_monday_close' => '18:00',
|
||||
]);
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(CabinetInfoTablet::class)
|
||||
->assertSet('storeStatus', 'notice')
|
||||
->assertSet('noticeHeadline', 'Sonderverkauf')
|
||||
->assertSet('contactPhone', '0521 12345');
|
||||
});
|
||||
|
||||
test('save persists settings to database', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(CabinetInfoTablet::class)
|
||||
->set('storeStatus', 'notice')
|
||||
->set('noticeHeadline', 'Winterpause')
|
||||
->set('noticeSubtext', 'Bis 02.01. geschlossen')
|
||||
->set('contactPhone', '0521 99999')
|
||||
->set('contactEmail', 'test@example.com')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$settings = CabinetTabletSetting::current();
|
||||
expect($settings->store_status)->toBe('notice');
|
||||
expect($settings->notice_headline)->toBe('Winterpause');
|
||||
expect($settings->contact_phone)->toBe('0521 99999');
|
||||
});
|
||||
|
||||
test('save validates store status', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(CabinetInfoTablet::class)
|
||||
->set('storeStatus', 'open') // 'open' is not a valid mode anymore
|
||||
->call('save')
|
||||
->assertHasErrors(['storeStatus']);
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(CabinetInfoTablet::class)
|
||||
->set('storeStatus', 'warning')
|
||||
->call('save')
|
||||
->assertHasNoErrors(['storeStatus']);
|
||||
});
|
||||
|
||||
test('save validates override time format', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(CabinetInfoTablet::class)
|
||||
->set('overrideOpenToday', 'abc')
|
||||
->call('save')
|
||||
->assertHasErrors(['overrideOpenToday']);
|
||||
});
|
||||
|
||||
test('save validates email format', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(CabinetInfoTablet::class)
|
||||
->set('contactEmail', 'not-an-email')
|
||||
->call('save')
|
||||
->assertHasErrors(['contactEmail']);
|
||||
});
|
||||
|
||||
test('save validates headline max length', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(CabinetInfoTablet::class)
|
||||
->set('noticeHeadline', str_repeat('A', 41))
|
||||
->call('save')
|
||||
->assertHasErrors(['noticeHeadline']);
|
||||
});
|
||||
|
||||
test('save allows empty opening hours for closed days', function () {
|
||||
CabinetTabletSetting::factory()->create([
|
||||
'hours_monday_open' => '10:00',
|
||||
'hours_monday_close' => '18:00',
|
||||
]);
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(CabinetInfoTablet::class)
|
||||
->set('hoursMondayOpen', '')
|
||||
->set('hoursMondayClose', '')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$settings = CabinetTabletSetting::current();
|
||||
expect($settings->hours_monday_open)->toBeNull();
|
||||
expect($settings->hours_monday_close)->toBeNull();
|
||||
});
|
||||
|
||||
test('clearOverrides resets override fields', function () {
|
||||
CabinetTabletSetting::factory()->create([
|
||||
'override_open_today' => '09:00',
|
||||
'override_close_today' => '20:00',
|
||||
]);
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(CabinetInfoTablet::class)
|
||||
->assertSet('overrideOpenToday', '09:00')
|
||||
->assertSet('overrideCloseToday', '20:00')
|
||||
->call('clearOverrides')
|
||||
->assertSet('overrideOpenToday', '')
|
||||
->assertSet('overrideCloseToday', '');
|
||||
|
||||
$settings = CabinetTabletSetting::current();
|
||||
expect($settings->override_open_today)->toBeNull();
|
||||
expect($settings->override_close_today)->toBeNull();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue