-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add variant attributes to product edit
- Loading branch information
1 parent
53605c6
commit 02bead9
Showing
4 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
tests/admin/Feature/Filament/Resources/ProductResource/Pages/EditProductTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
use Livewire\Livewire; | ||
|
||
uses(\Lunar\Tests\Admin\Unit\Filament\TestCase::class) | ||
->group('resource.product'); | ||
|
||
it('can edit variant attributes', function () { | ||
\Lunar\Models\CustomerGroup::factory()->create([ | ||
'default' => true, | ||
]); | ||
|
||
\Lunar\Models\Language::factory()->create([ | ||
'default' => true, | ||
]); | ||
|
||
$product = \Lunar\Models\Product::factory()->create(); | ||
$variant = \Lunar\Models\ProductVariant::factory()->create([ | ||
'product_id' => $product->id, | ||
]); | ||
|
||
$group = \Lunar\Models\AttributeGroup::factory()->create([ | ||
'attributable_type' => 'product_variant', | ||
'name' => [ | ||
'en' => 'Variant Details', | ||
], | ||
'handle' => 'variant_details', | ||
'position' => 1, | ||
]); | ||
|
||
$attribute = \Lunar\Models\Attribute::factory()->create([ | ||
'attribute_type' => 'product_variant', | ||
'attribute_group_id' => $group->id, | ||
'position' => 1, | ||
'name' => [ | ||
'en' => 'Test Attribute', | ||
], | ||
'handle' => 'test-attribute', | ||
'section' => 'main', | ||
'required' => false, | ||
'system' => false, | ||
'searchable' => false, | ||
]); | ||
|
||
\Illuminate\Support\Facades\DB::table('lunar_attributables')->insert([ | ||
'attribute_id' => $attribute->id, | ||
'attributable_type' => 'product_variant', | ||
'attributable_id' => $variant->id, | ||
]); | ||
|
||
$this->asStaff(admin: true); | ||
|
||
$component = Livewire::test(\Lunar\Admin\Filament\Resources\ProductResource\Pages\EditProduct::class, [ | ||
'record' => $product->id, | ||
'pageClass' => 'productEdit', | ||
])->assertSuccessful(); | ||
|
||
expect($variant->attr($attribute->handle))->toBeNull(); | ||
|
||
$component->set('data.variant_attributes.'.$attribute->handle, new \Lunar\FieldTypes\Text('Hello')); | ||
$component->call('save'); | ||
|
||
expect($variant->refresh()->attr($attribute->handle))->toBe('Hello'); | ||
}); |