fix(test): image outlet test dan voucher test
-create opening hour factory -create facility factory
This commit is contained in:
parent
cdc50218e8
commit
62ff10c411
15
database/factories/FacilityFactory.php
Normal file
15
database/factories/FacilityFactory.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class FacilityFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->word(),
|
||||
];
|
||||
}
|
||||
}
|
||||
18
database/factories/OpeningHourFactory.php
Normal file
18
database/factories/OpeningHourFactory.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\Day;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class OpeningHourFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'day' => $this->faker->randomElement(Day::cases())->value,
|
||||
'open_time' => $this->faker->time('H:i'),
|
||||
'close_time' => $this->faker->time('H:i'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -20,18 +20,6 @@ public function definition(): array
|
||||
'address' => $this->faker->address(),
|
||||
'landmark' => $this->faker->streetName(),
|
||||
'maps_url' => 'https://goo.gl/maps/'.$this->faker->regexify('[A-Za-z0-9]{6,10}'),
|
||||
'opening_hours' => collect(['senin', 'selasa', 'rabu', 'kamis', 'jumat', 'sabtu', 'minggu'])
|
||||
->mapWithKeys(fn ($day) => [
|
||||
$day => [
|
||||
'open' => $this->faker->time('H:i'),
|
||||
'close' => $this->faker->time('H:i'),
|
||||
],
|
||||
])
|
||||
->toArray(),
|
||||
'facilities' => $this->faker->randomElements(
|
||||
['WiFi', 'Parking', 'Toilet', 'Musholla', 'Smoking Area'],
|
||||
$this->faker->numberBetween(1, 3)
|
||||
),
|
||||
'opened_date' => $this->faker->date(),
|
||||
'closed_date' => $this->faker->optional()->date(),
|
||||
];
|
||||
|
||||
@ -2,6 +2,9 @@
|
||||
|
||||
use App\Livewire\Studio\Loyalty\Voucher\Create;
|
||||
use App\Livewire\Studio\Loyalty\Voucher\Index;
|
||||
use App\Models\Facility;
|
||||
use App\Models\OpeningHour;
|
||||
use App\Models\Outlet;
|
||||
use App\Models\Voucher;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
@ -19,6 +22,12 @@
|
||||
->active()
|
||||
->raw();
|
||||
|
||||
$outletIds = Outlet::factory()
|
||||
->count(4)
|
||||
->has(OpeningHour::factory()->count(7))
|
||||
->has(Facility::factory()->count(5))
|
||||
->create();
|
||||
|
||||
Livewire::test(Create::class)
|
||||
->set('form.name', $data['name'])
|
||||
->set('form.code', $data['code'])
|
||||
@ -32,6 +41,7 @@
|
||||
->set('form.discount_amount', $data['discount_amount'])
|
||||
->set('form.max_discount', $data['max_discount'])
|
||||
->set('form.is_active', $data['is_active']->value)
|
||||
->set('form.outlet_ids', $outletIds->pluck('id')->toArray())
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertDispatched('refreshDatatable')
|
||||
|
||||
@ -3,6 +3,9 @@
|
||||
use App\Enums\IsActive;
|
||||
use App\Livewire\Studio\Loyalty\Voucher\Edit;
|
||||
use App\Livewire\Studio\Loyalty\Voucher\Index;
|
||||
use App\Models\Facility;
|
||||
use App\Models\OpeningHour;
|
||||
use App\Models\Outlet;
|
||||
use App\Models\Voucher;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
@ -26,6 +29,12 @@
|
||||
])
|
||||
->raw();
|
||||
|
||||
$outletIds = Outlet::factory()
|
||||
->count(4)
|
||||
->has(OpeningHour::factory()->count(7))
|
||||
->has(Facility::factory()->count(5))
|
||||
->create();
|
||||
|
||||
Livewire::test(Edit::class, ['voucher' => $voucher])
|
||||
->set('form.name', $data['name'])
|
||||
->set('form.code', $data['code'])
|
||||
@ -39,6 +48,7 @@
|
||||
->set('form.discount_amount', $data['discount_amount'])
|
||||
->set('form.max_discount', $data['max_discount'])
|
||||
->set('form.is_active', $data['is_active']->value)
|
||||
->set('form.outlet_ids', $outletIds->pluck('id')->toArray())
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertDispatched('refreshDatatable')
|
||||
|
||||
@ -1,9 +1,14 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\Day;
|
||||
use App\Livewire\Studio\Master\Outlet\Create;
|
||||
use App\Livewire\Studio\Master\Outlet\Index;
|
||||
use App\Models\Facility;
|
||||
use App\Models\Outlet;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
@ -15,7 +20,51 @@
|
||||
});
|
||||
|
||||
it('can create an outlet', function () {
|
||||
$data = Outlet::factory()->operational()->raw();
|
||||
$outlet = Outlet::factory()->operational()->raw();
|
||||
$facilities = Facility::factory()->count(5)->raw();
|
||||
|
||||
$makeLivewireFile = function ($name) {
|
||||
$file = UploadedFile::fake()->image($name, 100, 100);
|
||||
|
||||
$tmpId = Str::random(32);
|
||||
$filename = $tmpId.'-'.base64_encode($file->getClientOriginalName()).'.'.$file->getClientOriginalExtension();
|
||||
$path = "livewire-tmp/{$filename}";
|
||||
|
||||
Storage::disk('local')->putFileAs('livewire-tmp', $file, $filename);
|
||||
|
||||
return [
|
||||
'tmpFilename' => $filename,
|
||||
'name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => storage_path("app/private/{$path}"),
|
||||
'temporaryUrl' => url("livewire/preview-file/{$filename}"),
|
||||
'size' => $file->getSize(),
|
||||
];
|
||||
};
|
||||
|
||||
$featuredImage = $makeLivewireFile('featured.jpg');
|
||||
$images = [
|
||||
$makeLivewireFile('image1.jpg'),
|
||||
$makeLivewireFile('image2.png'),
|
||||
];
|
||||
|
||||
$data = array_merge(
|
||||
$outlet,
|
||||
[
|
||||
'opening_hours' => collect(Day::cases())
|
||||
->mapWithKeys(fn ($day) => [
|
||||
$day->value => [
|
||||
'day' => $day->value,
|
||||
'open_time' => fake()->time('H:i'),
|
||||
'close_time' => fake()->time('H:i'),
|
||||
],
|
||||
])
|
||||
->toArray(),
|
||||
'facilities' => collect($facilities)->pluck('name')->toArray(),
|
||||
'featured_image' => [$featuredImage],
|
||||
'images' => $images,
|
||||
]
|
||||
);
|
||||
|
||||
Livewire::test(Create::class)
|
||||
->set('form.name', $data['name'])
|
||||
@ -23,17 +72,31 @@
|
||||
->set('form.address', $data['address'])
|
||||
->set('form.landmark', $data['landmark'])
|
||||
->set('form.maps_url', $data['maps_url'])
|
||||
->set('form.opening_hours', $data['opening_hours'])
|
||||
->set('form.facilities', $data['facilities'])
|
||||
->set('form.opened_date', $data['opened_date'])
|
||||
->set('form.status', $data['status']->value)
|
||||
->set('form.opening_hours', $data['opening_hours'])
|
||||
->set('form.facilities', $data['facilities'])
|
||||
->set('form.featured_image', $data['featured_image'])
|
||||
->set('form.images', $data['images'])
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertDispatched('refreshDatatable')
|
||||
->assertRedirect(Index::class);
|
||||
|
||||
$outlet = Outlet::first();
|
||||
|
||||
$this->assertDatabaseHas('outlets', [
|
||||
'id' => $outlet->id,
|
||||
'name' => $data['name'],
|
||||
'phone_number' => $data['phone_number'],
|
||||
]);
|
||||
|
||||
$this->assertCount(1, $outlet->getMedia('featured_image'));
|
||||
$this->assertCount(2, $outlet->getMedia('images'));
|
||||
|
||||
expect($outlet->getFirstMedia('featured_image')->getPath())->toBeFile();
|
||||
|
||||
foreach ($outlet->getMedia('images') as $media) {
|
||||
expect($media->getPath())->toBeFile();
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,9 +1,14 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\Day;
|
||||
use App\Livewire\Studio\Master\Outlet\Edit;
|
||||
use App\Livewire\Studio\Master\Outlet\Index;
|
||||
use App\Models\Facility;
|
||||
use App\Models\Outlet;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
@ -18,8 +23,50 @@
|
||||
|
||||
it('can update an outlet', function () {
|
||||
$outlet = Outlet::factory()->operational()->create();
|
||||
$facilities = Facility::factory()->count(5)->raw();
|
||||
|
||||
$data = Outlet::factory()->operational()->raw();
|
||||
$makeLivewireFile = function ($name) {
|
||||
$file = UploadedFile::fake()->image($name, 100, 100);
|
||||
|
||||
$tmpId = Str::random(32);
|
||||
$filename = $tmpId.'-'.base64_encode($file->getClientOriginalName()).'.'.$file->getClientOriginalExtension();
|
||||
$path = "livewire-tmp/{$filename}";
|
||||
|
||||
Storage::disk('local')->putFileAs('livewire-tmp', $file, $filename);
|
||||
|
||||
return [
|
||||
'tmpFilename' => $filename,
|
||||
'name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => storage_path("app/private/{$path}"),
|
||||
'temporaryUrl' => url("livewire/preview-file/{$filename}"),
|
||||
'size' => $file->getSize(),
|
||||
];
|
||||
};
|
||||
|
||||
$featuredImage = $makeLivewireFile('featured.jpg');
|
||||
$images = [
|
||||
$makeLivewireFile('image1.jpg'),
|
||||
$makeLivewireFile('image2.png'),
|
||||
];
|
||||
|
||||
$data = array_merge(
|
||||
Outlet::factory()->operational()->raw(),
|
||||
[
|
||||
'opening_hours' => collect(Day::cases())
|
||||
->mapWithKeys(fn ($day) => [
|
||||
$day->value => [
|
||||
'day' => $day->value,
|
||||
'open_time' => fake()->time('H:i'),
|
||||
'close_time' => fake()->time('H:i'),
|
||||
],
|
||||
])
|
||||
->toArray(),
|
||||
'facilities' => collect($facilities)->pluck('name')->toArray(),
|
||||
'featured_image' => [$featuredImage],
|
||||
'images' => $images,
|
||||
]
|
||||
);
|
||||
|
||||
Livewire::test(Edit::class, ['outlet' => $outlet])
|
||||
->set('form.name', $data['name'])
|
||||
@ -27,10 +74,12 @@
|
||||
->set('form.address', $data['address'])
|
||||
->set('form.landmark', $data['landmark'])
|
||||
->set('form.maps_url', $data['maps_url'])
|
||||
->set('form.opening_hours', $data['opening_hours'])
|
||||
->set('form.facilities', $data['facilities'])
|
||||
->set('form.opened_date', $data['opened_date'])
|
||||
->set('form.status', $data['status']->value)
|
||||
->set('form.opening_hours', $data['opening_hours'])
|
||||
->set('form.facilities', $data['facilities'])
|
||||
->set('form.featured_image', $data['featured_image'])
|
||||
->set('form.images', $data['images'])
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertDispatched('refreshDatatable')
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
use App\Enums\OutletStatus;
|
||||
use App\Livewire\Studio\Master\Outlet\Index;
|
||||
use App\Models\Facility;
|
||||
use App\Models\OpeningHour;
|
||||
use App\Models\Outlet;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
@ -17,6 +19,8 @@
|
||||
it('displays all outlets', function () {
|
||||
Outlet::factory()
|
||||
->count(10)
|
||||
->has(OpeningHour::factory()->count(7))
|
||||
->has(Facility::factory()->count(5))
|
||||
->state(fn () => [
|
||||
'status' => fake()->randomElement(OutletStatus::cases()),
|
||||
])
|
||||
@ -28,7 +32,13 @@
|
||||
});
|
||||
|
||||
it('can delete an outlet', function () {
|
||||
$outlet = Outlet::factory()->operational()->create();
|
||||
$outlet = Outlet::factory()
|
||||
->has(OpeningHour::factory()->count(7))
|
||||
->has(Facility::factory()->count(5))
|
||||
->state(fn () => [
|
||||
'status' => fake()->randomElement(OutletStatus::cases()),
|
||||
])
|
||||
->create();
|
||||
|
||||
Livewire::test(Index::class)
|
||||
->call('delete', $outlet)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user