2024-02-03 17:51:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Form;
|
|
|
|
|
|
|
|
use App\Form\Models\Form;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2024-06-10 00:17:14 +02:00
|
|
|
use Illuminate\Support\Facades\Http;
|
2024-02-03 17:51:27 +01:00
|
|
|
|
2024-02-19 01:07:54 +01:00
|
|
|
class FormUpdateActionTest extends FormTestCase
|
2024-02-03 17:51:27 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
|
|
|
public function testItSetsCustomAttributesOfFields(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$form = Form::factory()->create();
|
|
|
|
$payload = FormRequest::new()->sections([
|
|
|
|
FormtemplateSectionRequest::new()->fields([
|
2024-02-19 01:07:54 +01:00
|
|
|
$this->dateField()->state(['max_today' => true]),
|
2024-02-03 17:51:27 +01:00
|
|
|
])
|
|
|
|
])->create();
|
|
|
|
|
|
|
|
$this->patchJson(route('form.update', ['form' => $form]), $payload)
|
|
|
|
->assertOk();
|
|
|
|
|
|
|
|
$form = $form->fresh();
|
|
|
|
|
2024-03-07 00:58:14 +01:00
|
|
|
$this->assertTrue($form->config->sections->get(0)->fields->get(0)->maxToday);
|
2024-02-03 17:51:27 +01:00
|
|
|
}
|
2024-03-01 03:00:33 +01:00
|
|
|
|
2024-06-10 00:17:14 +02:00
|
|
|
public function testItClearsFrontendCacheWhenFormUpdated(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$form = Form::factory()->create();
|
|
|
|
|
|
|
|
$this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->create());
|
|
|
|
|
|
|
|
$this->assertFrontendCacheCleared();
|
|
|
|
}
|
|
|
|
|
2024-03-01 03:00:33 +01:00
|
|
|
public function testItUpdatesActiveColumnsWhenFieldRemoved(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$form = Form::factory()
|
|
|
|
->sections([FormtemplateSectionRequest::new()->fields([
|
|
|
|
$this->textField('firstname'),
|
|
|
|
$this->textField('geb'),
|
|
|
|
$this->textField('lastname'),
|
|
|
|
])])
|
|
|
|
->create();
|
|
|
|
$payload = FormRequest::new()->sections([
|
|
|
|
FormtemplateSectionRequest::new()->fields([
|
|
|
|
$this->textField('firstname'),
|
|
|
|
])
|
|
|
|
])->create();
|
|
|
|
|
|
|
|
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk();
|
|
|
|
$this->assertEquals(['firstname'], $form->fresh()->meta['active_columns']);
|
|
|
|
}
|
2024-04-23 23:12:14 +02:00
|
|
|
|
2024-05-27 18:30:05 +02:00
|
|
|
public function testItUpdatesActiveState(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$form = Form::factory()->create();
|
|
|
|
|
|
|
|
$this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->isActive(false)->create())->assertSessionDoesntHaveErrors()->assertOk();
|
|
|
|
$this->assertFalse($form->fresh()->is_active);
|
|
|
|
$this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->isActive(true)->create())->assertSessionDoesntHaveErrors()->assertOk();
|
|
|
|
$this->assertTrue($form->fresh()->is_active);
|
|
|
|
}
|
|
|
|
|
2024-05-27 18:49:11 +02:00
|
|
|
public function testItUpdatesPrivateState(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$form = Form::factory()->create();
|
|
|
|
|
|
|
|
$this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->isPrivate(false)->create())->assertSessionDoesntHaveErrors()->assertOk();
|
|
|
|
$this->assertFalse($form->fresh()->is_private);
|
|
|
|
$this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->isPrivate(true)->create())->assertSessionDoesntHaveErrors()->assertOk();
|
|
|
|
$this->assertTrue($form->fresh()->is_private);
|
|
|
|
}
|
|
|
|
|
2024-04-23 23:12:14 +02:00
|
|
|
public function testItUpdatesActiveColumnsWhenFieldsAdded(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$form = Form::factory()
|
|
|
|
->sections([FormtemplateSectionRequest::new()->fields([])])
|
|
|
|
->create();
|
|
|
|
$payload = FormRequest::new()->sections([
|
|
|
|
FormtemplateSectionRequest::new()->fields([
|
|
|
|
$this->textField('firstname'),
|
|
|
|
$this->textField('geb'),
|
|
|
|
$this->textField('lastname'),
|
|
|
|
])
|
|
|
|
])->create();
|
|
|
|
|
|
|
|
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk();
|
|
|
|
$this->assertEquals(['firstname', 'geb', 'lastname'], $form->fresh()->meta['active_columns']);
|
|
|
|
}
|
2024-02-03 17:51:27 +01:00
|
|
|
}
|