diff --git a/app/Form/Actions/IsDirtyAction.php b/app/Form/Actions/IsDirtyAction.php index d2b53fa4..68df1a6b 100644 --- a/app/Form/Actions/IsDirtyAction.php +++ b/app/Form/Actions/IsDirtyAction.php @@ -11,6 +11,13 @@ class IsDirtyAction { use AsAction; + public function rules(): array + { + return [ + 'config' => 'array|present', + ]; + } + public function handle(Form $form, ActionRequest $request): JsonResponse { $form->config = $request->input('config'); diff --git a/app/Form/Fields/TextField.php b/app/Form/Fields/TextField.php index b4668402..71c7abe6 100644 --- a/app/Form/Fields/TextField.php +++ b/app/Form/Fields/TextField.php @@ -23,9 +23,9 @@ class TextField extends Field ]; } - public static function default(): string + public static function default(): ?string { - return ''; + return null; } public static function fake(Generator $faker): array diff --git a/tests/Feature/Form/FormtemplateFieldRequest.php b/tests/Feature/Form/FormtemplateFieldRequest.php index c950a633..6df96889 100644 --- a/tests/Feature/Form/FormtemplateFieldRequest.php +++ b/tests/Feature/Form/FormtemplateFieldRequest.php @@ -39,7 +39,7 @@ class FormtemplateFieldRequest extends RequestFactory 'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6], 'nami_type' => null, 'for_members' => true, - 'hint' => '', + 'hint' => null, ]; } diff --git a/tests/Feature/Form/FormtemplateIndexActionTest.php b/tests/Feature/Form/FormtemplateIndexActionTest.php index a165dac0..dd86b922 100644 --- a/tests/Feature/Form/FormtemplateIndexActionTest.php +++ b/tests/Feature/Form/FormtemplateIndexActionTest.php @@ -54,7 +54,7 @@ class FormtemplateIndexActionTest extends TestCase 'name' => '', 'type' => 'TextField', 'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6], - 'value' => '', + 'value' => null, 'nami_type' => null, 'for_members' => true, 'special_type' => null, diff --git a/tests/Feature/Form/IsDirtyActionTest.php b/tests/Feature/Form/IsDirtyActionTest.php new file mode 100644 index 00000000..a425ed3d --- /dev/null +++ b/tests/Feature/Form/IsDirtyActionTest.php @@ -0,0 +1,25 @@ +login()->loginNami(); + $form = Form::factory()->fields([ + $this->textField(), + ])->create(); + + $this->postJson(route('form.is-dirty', ['form' => $form]), ['config' => $form->config->toArray()])->assertJsonPath('result', false); + + $modifiedConfig = $form->config->toArray(); + data_set($modifiedConfig, 'sections.0.name', 'mod'); + $this->postJson(route('form.is-dirty', ['form' => $form]), ['config' => $modifiedConfig])->assertJsonPath('result', true); + } +}