Add test for isDirty
This commit is contained in:
parent
594c45aede
commit
e08ad63313
|
@ -11,6 +11,13 @@ class IsDirtyAction
|
||||||
{
|
{
|
||||||
use AsAction;
|
use AsAction;
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'config' => 'array|present',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function handle(Form $form, ActionRequest $request): JsonResponse
|
public function handle(Form $form, ActionRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
$form->config = $request->input('config');
|
$form->config = $request->input('config');
|
||||||
|
|
|
@ -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
|
public static function fake(Generator $faker): array
|
||||||
|
|
|
@ -39,7 +39,7 @@ class FormtemplateFieldRequest extends RequestFactory
|
||||||
'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6],
|
'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6],
|
||||||
'nami_type' => null,
|
'nami_type' => null,
|
||||||
'for_members' => true,
|
'for_members' => true,
|
||||||
'hint' => '',
|
'hint' => null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ class FormtemplateIndexActionTest extends TestCase
|
||||||
'name' => '',
|
'name' => '',
|
||||||
'type' => 'TextField',
|
'type' => 'TextField',
|
||||||
'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6],
|
'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6],
|
||||||
'value' => '',
|
'value' => null,
|
||||||
'nami_type' => null,
|
'nami_type' => null,
|
||||||
'for_members' => true,
|
'for_members' => true,
|
||||||
'special_type' => null,
|
'special_type' => null,
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Form;
|
||||||
|
|
||||||
|
use App\Form\Models\Form;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
|
class IsDirtyActionTest extends FormTestCase
|
||||||
|
{
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
|
public function testItChecksIfFormIsDirty(): void
|
||||||
|
{
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue