diff --git a/app/Fileshare/FileshareSettings.php b/app/Fileshare/FileshareSettings.php index 2c4c4812..c8f9a292 100644 --- a/app/Fileshare/FileshareSettings.php +++ b/app/Fileshare/FileshareSettings.php @@ -3,10 +3,10 @@ namespace App\Fileshare; use App\Fileshare\Actions\FileshareIndexAction; -use App\Setting\Contracts\Indexable; +use App\Setting\Contracts\Viewable; use App\Setting\LocalSettings; -class FileshareSettings extends LocalSettings implements Indexable +class FileshareSettings extends LocalSettings implements Viewable { public static function group(): string { diff --git a/app/Form/FormSettings.php b/app/Form/FormSettings.php index 7ca1636b..bacebde2 100644 --- a/app/Form/FormSettings.php +++ b/app/Form/FormSettings.php @@ -4,11 +4,11 @@ namespace App\Form; use App\Form\Actions\SettingIndexAction; use App\Form\Actions\SettingStoreAction; -use App\Setting\Contracts\Indexable; +use App\Setting\Contracts\Viewable; use App\Setting\Contracts\Storeable; use App\Setting\LocalSettings; -class FormSettings extends LocalSettings implements Indexable, Storeable +class FormSettings extends LocalSettings implements Viewable, Storeable { public string $registerUrl; public string $clearCacheUrl; diff --git a/app/Invoice/InvoiceSettings.php b/app/Invoice/InvoiceSettings.php index e842d37f..061ccfaa 100644 --- a/app/Invoice/InvoiceSettings.php +++ b/app/Invoice/InvoiceSettings.php @@ -2,11 +2,11 @@ namespace App\Invoice; -use App\Setting\Contracts\Indexable; +use App\Setting\Contracts\Viewable; use App\Setting\Contracts\Storeable; use App\Setting\LocalSettings; -class InvoiceSettings extends LocalSettings implements Indexable, Storeable +class InvoiceSettings extends LocalSettings implements Viewable, Storeable { public string $from_long; diff --git a/app/Mailgateway/MailgatewaySettings.php b/app/Mailgateway/MailgatewaySettings.php index 488e0dc6..6f73b645 100644 --- a/app/Mailgateway/MailgatewaySettings.php +++ b/app/Mailgateway/MailgatewaySettings.php @@ -3,10 +3,10 @@ namespace App\Mailgateway; use App\Mailgateway\Actions\IndexAction; -use App\Setting\Contracts\Indexable; +use App\Setting\Contracts\Viewable; use App\Setting\LocalSettings; -class MailgatewaySettings extends LocalSettings implements Indexable +class MailgatewaySettings extends LocalSettings implements Viewable { public static function group(): string { diff --git a/app/Module/ModuleSettings.php b/app/Module/ModuleSettings.php index 13e057c2..a2bab236 100644 --- a/app/Module/ModuleSettings.php +++ b/app/Module/ModuleSettings.php @@ -2,11 +2,11 @@ namespace App\Module; -use App\Setting\Contracts\Indexable; +use App\Setting\Contracts\Viewable; use App\Setting\Contracts\Storeable; use App\Setting\LocalSettings; -class ModuleSettings extends LocalSettings implements Indexable, Storeable +class ModuleSettings extends LocalSettings implements Viewable, Storeable { /** @var array */ public array $modules; diff --git a/app/Prevention/PreventionSettings.php b/app/Prevention/PreventionSettings.php index 90518f44..06dbd182 100644 --- a/app/Prevention/PreventionSettings.php +++ b/app/Prevention/PreventionSettings.php @@ -4,10 +4,10 @@ namespace App\Prevention; use App\Lib\Editor\EditorData; use App\Prevention\Actions\PreventionIndexAction; -use App\Setting\Contracts\Indexable; +use App\Setting\Contracts\Viewable; use App\Setting\LocalSettings; -class PreventionSettings extends LocalSettings implements Indexable +class PreventionSettings extends LocalSettings implements Viewable { public EditorData $formmail; diff --git a/app/Setting/Contracts/Indexable.php b/app/Setting/Contracts/Viewable.php similarity index 87% rename from app/Setting/Contracts/Indexable.php rename to app/Setting/Contracts/Viewable.php index 3a6bd3fd..e531af0c 100644 --- a/app/Setting/Contracts/Indexable.php +++ b/app/Setting/Contracts/Viewable.php @@ -2,7 +2,7 @@ namespace App\Setting\Contracts; -interface Indexable +interface Viewable { /** * @return class-string diff --git a/app/Setting/NamiSettings.php b/app/Setting/NamiSettings.php index e52d9a67..77e890f4 100644 --- a/app/Setting/NamiSettings.php +++ b/app/Setting/NamiSettings.php @@ -5,12 +5,12 @@ namespace App\Setting; use App\Group; use App\Nami\Actions\SettingIndexAction; use App\Nami\Actions\SettingSaveAction; -use App\Setting\Contracts\Indexable; +use App\Setting\Contracts\Viewable; use App\Setting\Contracts\Storeable; use Zoomyboy\LaravelNami\Api; use Zoomyboy\LaravelNami\Nami; -class NamiSettings extends LocalSettings implements Indexable, Storeable +class NamiSettings extends LocalSettings implements Viewable, Storeable { public int $mglnr; diff --git a/app/Setting/SettingFactory.php b/app/Setting/SettingFactory.php index e256bebd..67caab24 100644 --- a/app/Setting/SettingFactory.php +++ b/app/Setting/SettingFactory.php @@ -2,7 +2,7 @@ namespace App\Setting; -use App\Setting\Contracts\Indexable; +use App\Setting\Contracts\Viewable; use App\Setting\Contracts\Storeable; use Illuminate\Routing\Router; @@ -20,16 +20,16 @@ class SettingFactory { $this->settings[] = $setting; - if (new $setting() instanceof Indexable) { + if (new $setting() instanceof Viewable) { app(Router::class)->middleware(['web', 'auth:web', SettingMiddleware::class])->get($setting::url(), $setting::indexAction()); } if (new $setting() instanceof Storeable) { - app(Router::class)->middleware(['web', 'auth:web', SettingMiddleware::class])->post($setting::url(), $setting::storeAction()); + app(Router::class)->middleware(['web', 'auth:web'])->post($setting::url(), $setting::storeAction()); } if (1 === count($this->settings)) { - app(Router::class)->redirect('/setting', '/setting/'.$setting::slug()); + app(Router::class)->redirect('/setting', '/setting/' . $setting::slug()); } } @@ -40,9 +40,9 @@ class SettingFactory { return collect($this->settings)->map(fn ($setting) => [ 'url' => $setting::url(), - 'is_active' => '/'.request()->path() === $setting::url(), + 'is_active' => '/' . request()->path() === $setting::url(), 'title' => $setting::title(), ]) - ->toArray(); + ->toArray(); } } diff --git a/tests/Feature/Invoice/SettingTest.php b/tests/Feature/Invoice/SettingTest.php index 3e451023..a7826b8d 100644 --- a/tests/Feature/Invoice/SettingTest.php +++ b/tests/Feature/Invoice/SettingTest.php @@ -10,10 +10,10 @@ class SettingTest extends TestCase { use DatabaseTransactions; - public function testSettingIndex(): void + public function testDisplaySettings(): void { $this->withoutExceptionHandling()->login()->loginNami(); - InvoiceSettings::fake([ + app(InvoiceSettings::class)->fill([ 'from_long' => 'DPSG Stamm Muster', 'from' => 'Stamm Muster', 'mobile' => '+49 176 55555', @@ -25,43 +25,33 @@ class SettingTest extends TestCase 'iban' => 'DE05', 'bic' => 'SOLSDE', 'rememberWeeks' => 6 - ]); + ])->save(); - $response = $this->get('/setting/bill'); - - $response->assertOk(); - $this->assertInertiaHas([ - 'from_long' => 'DPSG Stamm Muster', - 'from' => 'Stamm Muster', - 'mobile' => '+49 176 55555', - 'email' => 'max@muster.de', - 'website' => 'https://example.com', - 'address' => 'Musterstr 4', - 'place' => 'Solingen', - 'zip' => '12345', - 'iban' => 'DE05', - 'bic' => 'SOLSDE', - 'remember_weeks' => 6 - ], $response, 'data'); + $this->get('/setting/bill') + ->assertOk() + ->assertComponent('setting/Bill') + ->assertInertiaPath('data.from_long', 'DPSG Stamm Muster') + ->assertInertiaPath('data.from', 'Stamm Muster') + ->assertInertiaPath('data.mobile', '+49 176 55555') + ->assertInertiaPath('data.email', 'max@muster.de') + ->assertInertiaPath('data.website', 'https://example.com') + ->assertInertiaPath('data.address', 'Musterstr 4') + ->assertInertiaPath('data.place', 'Solingen') + ->assertInertiaPath('data.zip', '12345') + ->assertInertiaPath('data.iban', 'DE05') + ->assertInertiaPath('data.bic', 'SOLSDE') + ->assertInertiaPath('data.remember_weeks', 6); } public function testItReturnsTabs(): void { $this->withoutExceptionHandling()->login()->loginNami(); - $response = $this->get('/setting/bill'); - - /** @var array */ - $menus = $this->inertia($response, 'setting_menu'); - $this->assertTrue( - collect($menus) - ->pluck('url') - ->contains('/setting/bill') - ); - - $settingMenu = collect($menus)->first(fn ($menu) => '/setting/bill' === $menu['url']); - $this->assertTrue($settingMenu['is_active']); - $this->assertEquals('Rechnung', $settingMenu['title']); + $this->get('/setting/bill') + ->assertInertiaPath('setting_menu.1.title', 'Rechnung') + ->assertInertiaPath('setting_menu.1.url', '/setting/bill') + ->assertInertiaPath('setting_menu.1.is_active', true) + ->assertInertiaPath('setting_menu.0.is_active', false); } public function testItCanChangeSettings(): void