Skip to content

Commit

Permalink
fix: feature test bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cybersoldattech committed Jan 14, 2025
1 parent 1486790 commit 73b8ca4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Livewire/Pages/Collection/CollectionProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace App\Livewire\Pages\Collection;

use App\Models\Collection;
use App\Models\Product;
use Illuminate\Contracts\View\View;
use Livewire\Component;
use Shopper\Core\Models\Collection;

class CollectionProducts extends Component
{
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Pages/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function render(): View
->latest();

if (count($this->selectedAttributes) > 0) {
$query = $query->whereHas('attributes', function ($query) {
$query = $query->whereHas('options', function ($query) {
$query->whereIn('attribute_value_id', $this->selectedAttributes);
});
}
Expand Down
10 changes: 8 additions & 2 deletions tests/Feature/Livewire/Pages/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,24 @@

it('can filters products', function () {
$colorAttribute = Attribute::query()->create(['name' => 'Color', 'slug' => 'color', 'type' => 'checkbox']);
$this->assertNotNull($colorAttribute->id);

$redAttributeValue = AttributeValue::query()->create(['value' => 'Red', 'key' => '#1e3a8a', 'attribute_id' => $colorAttribute->id]);
$blueAttributeValue = AttributeValue::query()->create(['value' => 'Blue', 'key' => '#ddf048', 'attribute_id' => $colorAttribute->id]);

$sizeAttribute = Attribute::query()->create(['name' => 'Size', 'slug' => 'size', 'type' => 'checkbox']);

$this->assertNotNull($sizeAttribute->id);

$smallAttributeValue = AttributeValue::query()->create(['value' => 'Small', 'key' => 'XL', 'attribute_id' => $sizeAttribute->id]);
$largeAttributeValue = AttributeValue::query()->create(['value' => 'Large', 'key' => 'L', 'attribute_id' => $sizeAttribute->id]);

$this->product->attributes()->createMany([
$this->product->options()->attach([
['attribute_value_id' => $redAttributeValue->id, 'attribute_id' => $colorAttribute->id],
['attribute_value_id' => $smallAttributeValue->id, 'attribute_id' => $sizeAttribute->id],
]);

$this->secondProduct->attributes()->createMany([
$this->secondProduct->options()->attach([
['attribute_value_id' => $blueAttributeValue->id, 'attribute_id' => $colorAttribute->id],
['attribute_value_id' => $largeAttributeValue->id, 'attribute_id' => $sizeAttribute->id],
]);
Expand Down

0 comments on commit 73b8ca4

Please sign in to comment.