A free open source IT asset/license management system
Submit button component, users bulk edit update
snipe5c0ec85997d1
diff --git a/resources/views/blade/button/submit.blade.php b/resources/views/blade/button/submit.blade.phpnew file mode 100644index 0000000000..330296c5ba--- /dev/null+++ b/resources/views/blade/button/submit.blade.php@@ -0,0 +1,20 @@+@props([+ 'label' => null,+ 'icon' => 'checkmark',+ 'disabled' => false,+])++@php+ $label ??= trans('general.save');+@endphp++<button+ type="submit"+ {{ $attributes->merge(['class' => 'btn btn-primary', 'id' => 'submit_button']) }}+ @disabled($disabled)+>+ @if ($icon)+ <x-icon :type="$icon" />+ @endif+ {{ $label }}+</button>diff --git a/resources/views/settings/branding.blade.php b/resources/views/settings/branding.blade.phpindex bd897e059b..12d7eb768f 100644--- a/resources/views/settings/branding.blade.php+++ b/resources/views/settings/branding.blade.php@@ -352,9 +352,7 @@<a class="btn btn-link text-left" href="{{ route('settings.index') }}">{{ trans('button.cancel') }}</a></div><div class="text-right col-md-6">- <button type="submit" class="btn btn-primary"{{ config('app.lock_passwords') === true ? ' disabled' : '' }}>- <x-icon type="checkmark" /> {{ trans('general.save') }}- </button>+ <x-button.submit :disabled="config('app.lock_passwords') === true" /></div></div></x-slot:customfooter>diff --git a/resources/views/settings/google.blade.php b/resources/views/settings/google.blade.phpindex e2c3797008..2a4dc8ef6d 100644--- a/resources/views/settings/google.blade.php+++ b/resources/views/settings/google.blade.php@@ -94,9 +94,7 @@<a class="btn btn-link text-left" href="{{ route('settings.index') }}">{{ trans('button.cancel') }}</a></div><div class="text-right col-md-6">- <button type="submit" class="btn btn-success"{{ config('app.lock_passwords') === true ? ' disabled' : '' }}>- <x-icon type="checkmark" /> {{ trans('general.save') }}- </button>+ <x-button.submit class="btn-success" :disabled="config('app.lock_passwords') === true" /></div></div></x-slot:customfooter>diff --git a/resources/views/settings/saml.blade.php b/resources/views/settings/saml.blade.phpindex d0a681b731..be7c470f23 100644--- a/resources/views/settings/saml.blade.php+++ b/resources/views/settings/saml.blade.php@@ -174,9 +174,7 @@<a class="btn btn-link text-left" href="{{ route('settings.index') }}">{{ trans('button.cancel') }}</a></div><div class="text-right col-md-6">- <button type="submit" class="btn btn-theme"{{ config('app.lock_passwords') === true ? ' disabled': '' }}>- <x-icon type="checkmark" /> {{ trans('general.save') }}- </button>+ <x-button.submit class="btn-theme" :disabled="config('app.lock_passwords') === true" /></div></div></x-slot:customfooter>diff --git a/resources/views/users/bulk-edit.blade.php b/resources/views/users/bulk-edit.blade.phpindex 4d8b492f2c..736a01a10b 100644--- a/resources/views/users/bulk-edit.blade.php+++ b/resources/views/users/bulk-edit.blade.php@@ -299,10 +299,7 @@<x-slot:customfooter><div class="box-footer text-right"><a class="btn btn-link pull-left" href="{{ URL::previous() }}">{{ trans('button.cancel') }}</a>- <button type="submit" class="btn btn-success"{{ config('app.lock_passwords') ? ' disabled' : '' }}>- <x-icon type="checkmark" />- {{ trans('general.update') }}- </button>+ <x-button.submit class="btn-success" :label="trans('general.update')" :disabled="config('app.lock_passwords')" /></div></x-slot:customfooter>diff --git a/tests/Feature/Blade/ButtonSubmitTest.php b/tests/Feature/Blade/ButtonSubmitTest.phpnew file mode 100644index 0000000000..f023507048--- /dev/null+++ b/tests/Feature/Blade/ButtonSubmitTest.php@@ -0,0 +1,87 @@+<?php++namespace Tests\Feature\Blade;++use Illuminate\Support\Facades\Blade;+use Tests\TestCase;++class ButtonSubmitTest extends TestCase+{+ /**+ * Compile the given inline Blade fragment through the full component-+ * tag compiler and return the resulting HTML. Blade::render() bootstraps+ * a real compiler pass so attribute merging, @disabled evaluation, and+ * default @props resolution all fire the way they would in a live view.+ */+ private function render(string $inner): string+ {+ return Blade::render($inner);+ }++ public function test_defaults_render_a_primary_save_submit_button()+ {+ $html = $this->render('<x-button.submit />');++ $this->assertMatchesRegularExpression('/<button\b[^>]*type="submit"/', $html);+ $this->assertMatchesRegularExpression('/class="[^"]*\bbtn\b[^"]*"/', $html);+ $this->assertMatchesRegularExpression('/class="[^"]*\bbtn-primary\b[^"]*"/', $html);+ $this->assertStringContainsString(trans('general.save'), $html);+ }++ public function test_label_prop_overrides_default()+ {+ $html = $this->render('<x-button.submit label="Update Widget" />');++ $this->assertStringContainsString('Update Widget', $html);+ $this->assertStringNotContainsString(trans('general.save'), $html);+ }++ public function test_icon_defaults_to_checkmark_and_can_be_disabled()+ {+ $withIcon = $this->render('<x-button.submit />');+ $withoutIcon = $this->render('<x-button.submit :icon="false" />');++ // Checkmark by default; explicit :icon="false" strips it.+ // Callers use false (not null) because Blade's @props resolver+ // treats null as "not passed" and falls back to the default.+ $this->assertStringContainsString('fa-check', $withIcon);+ $this->assertStringNotContainsString('fa-check', $withoutIcon);+ }++ public function test_caller_class_merges_with_default()+ {+ $html = $this->render('<x-button.submit class="btn-success" />');++ // Both the caller color and the base .btn should still be present.+ $this->assertMatchesRegularExpression('/class="[^"]*\bbtn\b[^"]*"/', $html);+ $this->assertMatchesRegularExpression('/class="[^"]*\bbtn-success\b[^"]*"/', $html);+ }++ public function test_disabled_defaults_to_enabled()+ {+ // The component does not bake in any disable condition. Callers+ // pass :disabled="config('app.lock_passwords')" (or any other+ // reason) at the callsite when they want it off.+ config()->set('app.lock_passwords', true);+ $html = $this->render('<x-button.submit />');++ $this->assertDoesNotMatchRegularExpression('/<button\b[^>]*\bdisabled\b/', $html);+ }++ public function test_disabled_prop_passes_through()+ {+ $disabled = $this->render('<x-button.submit :disabled="true" />');+ $enabled = $this->render('<x-button.submit :disabled="false" />');++ $this->assertMatchesRegularExpression('/<button\b[^>]*\bdisabled\b/', $disabled);+ $this->assertDoesNotMatchRegularExpression('/<button\b[^>]*\bdisabled\b/', $enabled);+ }++ public function test_forwarded_attributes_reach_the_button()+ {+ $html = $this->render('<x-button.submit id="my-save" data-marker="X" />');++ $this->assertMatchesRegularExpression('/<button\b[^>]*id="my-save"/', $html);+ $this->assertMatchesRegularExpression('/<button\b[^>]*data-marker="X"/', $html);+ }+}