b2in/tests/Feature/CabinetQuickStatusTest.php
Kevin Adametz 2a34adc515 QuickStatus: Hinweistext beim Wechsel auf Auto beibehalten.
Gespeicherte Headline und Subtext bleiben erhalten und stehen beim erneuten Umschalten auf Hinweis wieder zur Verfügung.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-18 08:27:44 +00:00

136 lines
4.6 KiB
PHP

<?php
use App\Livewire\Cabinet\QuickStatus;
use App\Models\CabinetTabletSetting;
use Livewire\Livewire;
const VALID_KEY = 'test-secret-key-123';
beforeEach(function () {
config(['domains.cabinet_status_key' => VALID_KEY]);
});
test('page is accessible without login', function () {
$this->get('/info/status?k='.VALID_KEY)
->assertSuccessful()
->assertSeeLivewire(QuickStatus::class);
});
test('page accepts key query parameter used in admin link', function () {
$this->get('/info/status?key='.VALID_KEY)
->assertSuccessful()
->assertSeeLivewire(QuickStatus::class);
});
test('page shows forbidden when key is missing', function () {
Livewire::test(QuickStatus::class, ['k' => ''])
->assertSet('authorized', false)
->assertSee('Kein Zugriff');
});
test('page shows forbidden when key is wrong', function () {
Livewire::test(QuickStatus::class, ['k' => 'wrong-key'])
->assertSet('authorized', false)
->assertSee('Kein Zugriff');
});
test('page loads current status when key is correct', function () {
CabinetTabletSetting::factory()->create([
'store_status' => 'notice',
'notice_headline' => 'Testhinweis',
]);
Livewire::test(QuickStatus::class, ['k' => VALID_KEY])
->assertSet('authorized', true)
->assertSet('storeStatus', 'notice')
->assertSet('noticeHeadline', 'Testhinweis');
});
test('selectStatus changes storeStatus', function () {
Livewire::test(QuickStatus::class, ['k' => VALID_KEY])
->call('selectStatus', 'closed')
->assertSet('storeStatus', 'closed');
});
test('selectStatus ignores unknown values', function () {
Livewire::test(QuickStatus::class, ['k' => VALID_KEY])
->call('selectStatus', 'invalid')
->assertSet('storeStatus', 'auto');
});
test('save persists status and headline to database', function () {
Livewire::test(QuickStatus::class, ['k' => VALID_KEY])
->set('storeStatus', 'notice')
->set('noticeHeadline', 'Sonderöffnung')
->set('noticeSubtext', 'Heute nur bis 14 Uhr')
->call('save')
->assertHasNoErrors()
->assertSet('saved', true);
$settings = CabinetTabletSetting::current();
expect($settings->store_status)->toBe('notice');
expect($settings->notice_headline)->toBe('Sonderöffnung');
expect($settings->notice_subtext)->toBe('Heute nur bis 14 Uhr');
});
test('save preserves headline when switching to auto', function () {
CabinetTabletSetting::factory()->create([
'store_status' => 'notice',
'notice_headline' => 'Alter Text',
'notice_subtext' => 'Alter Subtext',
]);
Livewire::test(QuickStatus::class, ['k' => VALID_KEY])
->set('storeStatus', 'auto')
->call('save')
->assertHasNoErrors();
$settings = CabinetTabletSetting::current();
expect($settings->store_status)->toBe('auto');
expect($settings->notice_headline)->toBe('Alter Text');
expect($settings->notice_subtext)->toBe('Alter Subtext');
});
test('switching back to notice restores saved headline from database', function () {
CabinetTabletSetting::factory()->create([
'store_status' => 'notice',
'notice_headline' => 'Gespeicherter Hinweis',
'notice_subtext' => 'Gespeicherter Subtext',
]);
Livewire::test(QuickStatus::class, ['k' => VALID_KEY])
->call('selectStatus', 'auto')
->call('selectStatus', 'notice')
->assertSet('noticeHeadline', 'Gespeicherter Hinweis')
->assertSet('noticeSubtext', 'Gespeicherter Subtext');
});
test('save validates headline max length', function () {
Livewire::test(QuickStatus::class, ['k' => VALID_KEY])
->set('storeStatus', 'notice')
->set('noticeHeadline', str_repeat('A', 41))
->call('save')
->assertHasErrors(['noticeHeadline']);
});
test('save validates subtext max length', function () {
Livewire::test(QuickStatus::class, ['k' => VALID_KEY])
->set('storeStatus', 'notice')
->set('noticeSubtext', str_repeat('A', 81))
->call('save')
->assertHasErrors(['noticeSubtext']);
});
test('unauthorized user cannot save', function () {
$component = Livewire::test(QuickStatus::class, ['k' => 'wrong'])
->set('storeStatus', 'closed')
->call('save');
expect(CabinetTabletSetting::count())->toBe(0);
});
test('all four status options are available', function () {
$component = Livewire::test(QuickStatus::class, ['k' => VALID_KEY]);
expect($component->get('statusOptions'))->toHaveKeys(['auto', 'closed', 'notice', 'warning']);
});