|
388 | 388 | ->toBe(['Alpha', 'Bravo', 'Charlie']); |
389 | 389 | }); |
390 | 390 |
|
| 391 | + it('can duplicate a select field and preserve option settings', function (): void { |
| 392 | + $field = CustomField::factory() |
| 393 | + ->ofType('select') |
| 394 | + ->withOptions(['Red', 'Blue']) |
| 395 | + ->create([ |
| 396 | + 'custom_field_section_id' => $this->section->getKey(), |
| 397 | + 'entity_type' => $this->userEntityType, |
| 398 | + 'name' => 'Color Picker', |
| 399 | + 'code' => 'color_picker', |
| 400 | + ]); |
| 401 | + |
| 402 | + $field->options->first()->update(['settings' => new \Relaticle\CustomFields\Data\CustomFieldOptionSettingsData(color: '#ff0000')]); |
| 403 | + $field->options->last()->update(['settings' => new \Relaticle\CustomFields\Data\CustomFieldOptionSettingsData(color: '#0000ff')]); |
| 404 | + |
| 405 | + livewire(ManageCustomField::class, [ |
| 406 | + 'field' => $field->fresh(), |
| 407 | + ])->callAction('duplicate'); |
| 408 | + |
| 409 | + $clone = CustomField::query() |
| 410 | + ->withDeactivated() |
| 411 | + ->where('code', 'color-picker-copy') |
| 412 | + ->first(); |
| 413 | + |
| 414 | + expect($clone)->not->toBeNull(); |
| 415 | + expect($clone->options)->toHaveCount(2); |
| 416 | + |
| 417 | + $clonedOptions = $clone->options->sortBy('sort_order')->values(); |
| 418 | + |
| 419 | + expect($clonedOptions[0]->settings->color)->toBe('#ff0000'); |
| 420 | + expect($clonedOptions[1]->settings->color)->toBe('#0000ff'); |
| 421 | + }); |
| 422 | + |
391 | 423 | it('generates unique code when duplicating a field with existing copy', function (): void { |
392 | 424 | $field = CustomField::factory() |
393 | 425 | ->ofType('text') |
|
0 commit comments