From 57d7ce16eaafbece93044035c9f6d57f9c9a19fe Mon Sep 17 00:00:00 2001 From: Dennis Elsinga Date: Wed, 17 Apr 2024 19:31:48 +0200 Subject: [PATCH] feat: Add field existence checks for create and edit forms --- src/Stubs/Resource/Page/Create/Form/Fields/Exists.php | 9 ++++++++- src/Stubs/Resource/Page/Edit/Form/Fields/Exists.php | 9 ++++++++- stubs/Resource/Page/Create/Form/Fields/Exists.stub | 7 ++++--- stubs/Resource/Page/Edit/Form/Fields/Exists.stub | 9 ++++++--- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Stubs/Resource/Page/Create/Form/Fields/Exists.php b/src/Stubs/Resource/Page/Create/Form/Fields/Exists.php index c443cc20..8f7d4b5f 100644 --- a/src/Stubs/Resource/Page/Create/Form/Fields/Exists.php +++ b/src/Stubs/Resource/Page/Create/Form/Fields/Exists.php @@ -11,11 +11,18 @@ class Exists extends Base public function getDescription(): string { - return 'has a X field on create form'; + return 'has a field on create form'; } public function getShouldGenerate(): bool { return collect($this->getResourceCreateFields($this->resource))->count(); } + + public function getVariables(): array + { + return [ + 'CREATE_PAGE_FIELDS' => $this->convertDoubleQuotedArrayString(collect($this->getResourceCreateFields($this->resource))->keys()), + ]; + } } diff --git a/src/Stubs/Resource/Page/Edit/Form/Fields/Exists.php b/src/Stubs/Resource/Page/Edit/Form/Fields/Exists.php index d1b913c4..c0c8cbd2 100644 --- a/src/Stubs/Resource/Page/Edit/Form/Fields/Exists.php +++ b/src/Stubs/Resource/Page/Edit/Form/Fields/Exists.php @@ -11,11 +11,18 @@ class Exists extends Base public function getDescription(): string { - return 'has a X field on edit form'; + return 'has a field on edit form'; } public function getShouldGenerate(): bool { return collect($this->getResourceEditFields($this->resource))->count(); } + + public function getVariables(): array + { + return [ + 'EDIT_PAGE_FIELDS' => $this->convertDoubleQuotedArrayString(collect($this->getResourceEditFields($this->resource))->keys()), + ]; + } } diff --git a/stubs/Resource/Page/Create/Form/Fields/Exists.stub b/stubs/Resource/Page/Create/Form/Fields/Exists.stub index 34783ed8..7b90d323 100644 --- a/stubs/Resource/Page/Create/Form/Fields/Exists.stub +++ b/stubs/Resource/Page/Create/Form/Fields/Exists.stub @@ -1,3 +1,4 @@ -it({{ DESCRIPTION }}, function () { - // -}){{ RESOLVED_GROUP_METHOD }}->todo(); +it({{ DESCRIPTION }}, function (string $field) { + livewire({{ RESOURCE_CREATE_CLASS}}) + ->assertFormFieldExists($field); +})->with({{ CREATE_PAGE_FIELDS }}){{ RESOLVED_GROUP_METHOD }}; diff --git a/stubs/Resource/Page/Edit/Form/Fields/Exists.stub b/stubs/Resource/Page/Edit/Form/Fields/Exists.stub index 34783ed8..84043dd8 100644 --- a/stubs/Resource/Page/Edit/Form/Fields/Exists.stub +++ b/stubs/Resource/Page/Edit/Form/Fields/Exists.stub @@ -1,3 +1,6 @@ -it({{ DESCRIPTION }}, function () { - // -}){{ RESOLVED_GROUP_METHOD }}->todo(); +it({{ DESCRIPTION }}, function (string $field) { + $record = {{ MODEL_SINGULAR_NAME }}::factory()->create(); + + livewire({{ RESOURCE_EDIT_CLASS}}, ['record' => $record->getRouteKey()]) + ->assertFormFieldExists($field); +})->with({{ EDIT_PAGE_FIELDS }}){{ RESOLVED_GROUP_METHOD }};