Skip to content

Commit

Permalink
feat: Add field existence checks for create and edit forms
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithDennis committed Apr 17, 2024
1 parent 4ba6e55 commit 57d7ce1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/Stubs/Resource/Page/Create/Form/Fields/Exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
];
}
}
9 changes: 8 additions & 1 deletion src/Stubs/Resource/Page/Edit/Form/Fields/Exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
];
}
}
7 changes: 4 additions & 3 deletions stubs/Resource/Page/Create/Form/Fields/Exists.stub
Original file line number Diff line number Diff line change
@@ -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 }};
9 changes: 6 additions & 3 deletions stubs/Resource/Page/Edit/Form/Fields/Exists.stub
Original file line number Diff line number Diff line change
@@ -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 }};

0 comments on commit 57d7ce1

Please sign in to comment.