Add formtemplate to form index
This commit is contained in:
parent
5cf49489d5
commit
c3db854eb5
|
@ -3,6 +3,8 @@
|
||||||
namespace App\Form\Resources;
|
namespace App\Form\Resources;
|
||||||
|
|
||||||
use App\Form\Models\Form;
|
use App\Form\Models\Form;
|
||||||
|
use App\Form\Models\Formtemplate;
|
||||||
|
use App\Lib\HasMeta;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,6 +12,9 @@ use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
*/
|
*/
|
||||||
class FormResource extends JsonResource
|
class FormResource extends JsonResource
|
||||||
{
|
{
|
||||||
|
|
||||||
|
use HasMeta;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform the resource into an array.
|
* Transform the resource into an array.
|
||||||
*
|
*
|
||||||
|
@ -33,4 +38,14 @@ class FormResource extends JsonResource
|
||||||
'config' => $this->config,
|
'config' => $this->config,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function meta(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'links' => [
|
||||||
|
'store' => route('form.store'),
|
||||||
|
],
|
||||||
|
'templates' => FormtemplateResource::collection(Formtemplate::get()),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,11 @@ namespace Database\Factories\Form\Models;
|
||||||
|
|
||||||
use App\Form\Models\Formtemplate;
|
use App\Form\Models\Formtemplate;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
use Tests\Feature\Form\FormtemplateSectionRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @extends Factory<Formtemplate>
|
* @extends Factory<Formtemplate>
|
||||||
|
* @method self name(string $name)
|
||||||
*/
|
*/
|
||||||
class FormtemplateFactory extends Factory
|
class FormtemplateFactory extends Factory
|
||||||
{
|
{
|
||||||
|
@ -25,4 +27,20 @@ class FormtemplateFactory extends Factory
|
||||||
'config' => [],
|
'config' => [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, FormtemplateSectionRequest> $sections
|
||||||
|
*/
|
||||||
|
public function sections(array $sections): self
|
||||||
|
{
|
||||||
|
return $this->state(['config' => ['sections' => $sections]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $args
|
||||||
|
*/
|
||||||
|
public function __call($method, $parameters): self
|
||||||
|
{
|
||||||
|
return $this->state([str($method)->snake()->toString() => $parameters[0]]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Tests\Feature\Form;
|
namespace Tests\Feature\Form;
|
||||||
|
|
||||||
use App\Form\Models\Form;
|
use App\Form\Models\Form;
|
||||||
|
use App\Form\Models\Formtemplate;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
@ -14,7 +15,8 @@ class FormIndexActionTest extends TestCase
|
||||||
public function testItDisplaysForms(): void
|
public function testItDisplaysForms(): void
|
||||||
{
|
{
|
||||||
$this->login()->loginNami()->withoutExceptionHandling();
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
$form = Form::factory()
|
Formtemplate::factory()->name('tname')->sections([FormtemplateSectionRequest::new()->name('sname')->create()])->create();
|
||||||
|
Form::factory()
|
||||||
->name('lala')
|
->name('lala')
|
||||||
->excerpt('fff')
|
->excerpt('fff')
|
||||||
->description('desc')
|
->description('desc')
|
||||||
|
@ -40,6 +42,9 @@ class FormIndexActionTest extends TestCase
|
||||||
->assertInertiaPath('data.data.0.from', '2023-05-05')
|
->assertInertiaPath('data.data.0.from', '2023-05-05')
|
||||||
->assertInertiaPath('data.data.0.to', '2023-06-07')
|
->assertInertiaPath('data.data.0.to', '2023-06-07')
|
||||||
->assertInertiaPath('data.data.0.registration_from', '2023-05-06 04:00:00')
|
->assertInertiaPath('data.data.0.registration_from', '2023-05-06 04:00:00')
|
||||||
->assertInertiaPath('data.data.0.registration_until', '2023-04-01 05:00:00');
|
->assertInertiaPath('data.data.0.registration_until', '2023-04-01 05:00:00')
|
||||||
|
->assertInertiaPath('data.meta.links.store', route('form.store'))
|
||||||
|
->assertInertiaPath('data.meta.templates.0.name', 'tname')
|
||||||
|
->assertInertiaPath('data.meta.templates.0.config.sections.0.name', 'sname');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class FormtemplateIndexActionTest extends TestCase
|
||||||
|
|
||||||
public function testItDisplaysIndexPage(): void
|
public function testItDisplaysIndexPage(): void
|
||||||
{
|
{
|
||||||
$formtemplate = Formtemplate::factory()->create();
|
$formtemplate = Formtemplate::factory()->sections([FormtemplateSectionRequest::new()->name('sname')->create()])->create();
|
||||||
|
|
||||||
$group = Group::factory()->has(Group::factory()->state(['inner_name' => 'child']), 'children')->create(['inner_name' => 'root']);
|
$group = Group::factory()->has(Group::factory()->state(['inner_name' => 'child']), 'children')->create(['inner_name' => 'root']);
|
||||||
$this->login()->loginNami(12345, 'pasword', $group)->withoutExceptionHandling();
|
$this->login()->loginNami(12345, 'pasword', $group)->withoutExceptionHandling();
|
||||||
|
@ -23,6 +23,7 @@ class FormtemplateIndexActionTest extends TestCase
|
||||||
->assertInertiaPath('data.data.0.links', [
|
->assertInertiaPath('data.data.0.links', [
|
||||||
'update' => route('formtemplate.update', ['formtemplate' => $formtemplate]),
|
'update' => route('formtemplate.update', ['formtemplate' => $formtemplate]),
|
||||||
])
|
])
|
||||||
|
->assertInertiaPath('data.data.0.config.sections.0.name', 'sname')
|
||||||
->assertInertiaPath('data.meta.groups', [
|
->assertInertiaPath('data.meta.groups', [
|
||||||
['id' => $group->id, 'name' => 'root'],
|
['id' => $group->id, 'name' => 'root'],
|
||||||
['id' => $group->children->first()->id, 'name' => '-- child'],
|
['id' => $group->children->first()->id, 'name' => '-- child'],
|
||||||
|
|
Loading…
Reference in New Issue