diff --git a/app/Livewire/Cabinet/QuickStatus.php b/app/Livewire/Cabinet/QuickStatus.php index d9968785..13340bce 100644 --- a/app/Livewire/Cabinet/QuickStatus.php +++ b/app/Livewire/Cabinet/QuickStatus.php @@ -92,13 +92,6 @@ class QuickStatus extends Component 'noticeSubtext.max' => 'Subtext max. 80 Zeichen.', ]); - $showsNotice = in_array($this->storeStatus, ['notice', 'warning'], true); - - if (! $showsNotice) { - $this->noticeHeadline = ''; - $this->noticeSubtext = ''; - } - CabinetTabletSetting::current()->update([ 'store_status' => $this->storeStatus, 'notice_headline' => $this->noticeHeadline ?: null, diff --git a/tests/Feature/CabinetQuickStatusTest.php b/tests/Feature/CabinetQuickStatusTest.php index 63c73819..b2c43ccc 100644 --- a/tests/Feature/CabinetQuickStatusTest.php +++ b/tests/Feature/CabinetQuickStatusTest.php @@ -73,10 +73,11 @@ test('save persists status and headline to database', function () { expect($settings->notice_subtext)->toBe('Heute nur bis 14 Uhr'); }); -test('save clears headline when switching to auto', function () { +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]) @@ -84,8 +85,24 @@ test('save clears headline when switching to auto', function () { ->call('save') ->assertHasNoErrors(); - expect(CabinetTabletSetting::current()->store_status)->toBe('auto'); - expect(CabinetTabletSetting::current()->notice_headline)->toBeNull(); + $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 () {