This commit is contained in:
Meghdad committed 2026-07-10 04:20:13 +03:30
commit 8fe27cfa5e
52 files changed
+5299

No files matched your search

+157
View File
@@ -0,0 +1,157 @@
<?php
use MeghdadFadaee\NovaFormCard\Tests\Fixtures\SerializableCard;
use MeghdadFadaee\NovaFormCard\Tests\Fixtures\DependentCard;
it('serializes supported Nova fields for the card component', function (): void {
$serialized = $this->serializeFormCard(new SerializableCard());
$form = $serialized['formCard'];
expect($form['title'])->toBe('Invite User')
->and($form['endpoint'])->toBe('/nova-vendor/nova-form-card/submit')
->and($form['submitText'])->toBe('Submit')
->and($form['canSubmit'])->toBeTrue()
->and($form['token'])->toBeString()->not->toBeEmpty();
$types = collect($form['fields'])->pluck('formCardType', 'attribute')->all();
$components = collect($form['fields'])->pluck('component', 'attribute')->all();
expect($types)->not->toHaveKey('hidden_secret');
expect($types)->toMatchArray([
'email' => 'text',
'message' => 'textarea',
'role' => 'select',
'active' => 'boolean',
'seats' => 'number',
'starts_at' => 'date',
'starts_at_time' => 'date-time',
'work_email' => 'email',
'website' => 'url',
'password' => 'password',
'password_confirmation' => 'password-confirmation',
'tracking_code' => 'hidden',
'record_id' => 'id',
'price' => 'currency',
'brand_color' => 'color',
'payload' => 'code',
'country' => 'country',
'timezone' => 'timezone',
'tags' => 'multi-select',
'permissions' => 'boolean-group',
'metadata' => 'key-value',
'slug' => 'slug',
'api_token' => 'token',
'attachment' => 'file',
'avatar' => 'image',
'profile_photo' => 'avatar',
'voice_note' => 'audio',
'invite_summary' => 'heading',
'queue_label' => 'line',
'invite_stats' => 'stack',
'invite_trend' => 'sparkline',
'health' => 'badge',
'import_status' => 'status',
'sender_email' => 'gravatar',
'sender_name' => 'ui-avatar',
])->and($components)->toMatchArray([
'email' => 'text-field',
'message' => 'textarea-field',
'role' => 'select-field',
'active' => 'boolean-field',
'seats' => 'text-field',
'starts_at' => 'date-field',
'starts_at_time' => 'date-time-field',
'work_email' => 'email-field',
'website' => 'url-field',
'password' => 'password-field',
'password_confirmation' => 'password-field',
'tracking_code' => 'hidden-field',
'record_id' => 'id-field',
'price' => 'currency-field',
'brand_color' => 'color-field',
'payload' => 'code-field',
'country' => 'select-field',
'timezone' => 'select-field',
'tags' => 'multi-select-field',
'permissions' => 'boolean-group-field',
'metadata' => 'key-value-field',
'slug' => 'slug-field',
'api_token' => 'text-field',
'attachment' => 'file-field',
'avatar' => 'file-field',
'profile_photo' => 'file-field',
'voice_note' => 'audio-field',
'invite_summary' => 'heading-field',
'queue_label' => 'line-field',
'invite_stats' => 'stack-field',
'invite_trend' => 'sparkline-field',
'health' => 'badge-field',
'import_status' => 'status-field',
'sender_email' => 'file-field',
'sender_name' => 'file-field',
]);
$displayOnly = collect($form['fields'])->pluck('displayOnly', 'attribute')->all();
expect($displayOnly)->toMatchArray([
'password' => false,
'password_confirmation' => false,
'invite_summary' => true,
'queue_label' => true,
'invite_stats' => true,
'invite_trend' => true,
'health' => true,
'import_status' => true,
'sender_email' => true,
'sender_name' => true,
]);
$email = collect($form['fields'])->firstWhere('attribute', 'email');
$role = collect($form['fields'])->firstWhere('attribute', 'role');
$passwordConfirmation = collect($form['fields'])->firstWhere('attribute', 'password_confirmation');
$line = collect($form['fields'])->firstWhere('attribute', 'queue_label');
$badge = collect($form['fields'])->firstWhere('attribute', 'health');
$status = collect($form['fields'])->firstWhere('attribute', 'import_status');
$stack = collect($form['fields'])->firstWhere('attribute', 'invite_stats');
expect($email['required'])->toBeTrue()
->and($email['value'])->toBe('taylor@example.com')
->and($role['options'])->toContain([
'label' => 'Admin',
'value' => 'admin',
])
->and($badge['label'])->toBe('OK')
->and($passwordConfirmation['type'])->toBe('password')
->and($line['type'])->toBe('line')
->and($status['type'])->toBe('success')
->and($stack['lines'])->toHaveCount(2);
});
it('serializes and syncs Nova dependent fields', function (): void {
$serialized = $this->serializeFormCard(new DependentCard());
$form = $serialized['formCard'];
$email = collect($form['fields'])->firstWhere('attribute', 'email');
expect($form['syncEndpoint'])->toBe('/nova-vendor/nova-form-card/sync')
->and($email['visible'])->toBeFalse()
->and($email['dependsOn'])->toHaveKey('role')
->and($email['dependentComponentKey'])->toBeString()->not->toBeEmpty();
$this->patchJson($form['syncEndpoint'].'?'.http_build_query([
'token' => $form['token'],
'editing' => 'true',
'editMode' => 'create',
'field' => 'email',
'component' => $email['dependentComponentKey'],
]), [
'email' => '',
'role' => 'admin',
])
->assertOk()
->assertJson([
'attribute' => 'email',
'visible' => true,
'type' => 'text',
]);
});