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