major update
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser\Concerns;
|
||||
|
||||
use App\Models\User;
|
||||
use Modules\Platform\app\Models\Company;
|
||||
use Modules\Platform\app\Models\LicenseKey;
|
||||
use Modules\Platform\app\Models\Payment;
|
||||
use Modules\Warehouse\app\Models\Warehouse;
|
||||
use Modules\Warehouse\app\Models\WarehouseValidationRule;
|
||||
|
||||
trait CreatesWmsBrowserData
|
||||
{
|
||||
/**
|
||||
* Create a normal tenant user with an active licence.
|
||||
*/
|
||||
protected function createLicensedUser(array $attributes = []): User
|
||||
{
|
||||
return User::factory()->create($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an MPBA platform administrator attached to the system tenant.
|
||||
*/
|
||||
protected function createPlatformAdmin(array $attributes = []): User
|
||||
{
|
||||
return User::factory()->mpbaPlatformAdmin()->create($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a warehouse for the user's company tenant.
|
||||
*/
|
||||
protected function createWarehouseFor(User $user, array $attributes = []): Warehouse
|
||||
{
|
||||
return Warehouse::query()->create([
|
||||
'company_id' => $user->company_id,
|
||||
'code' => $attributes['code'] ?? 'MAIN',
|
||||
'name' => $attributes['name'] ?? 'Main Warehouse',
|
||||
'status' => $attributes['status'] ?? 'active',
|
||||
'address' => $attributes['address'] ?? 'Unit 1, Test Estate',
|
||||
'timezone' => $attributes['timezone'] ?? 'Europe/London',
|
||||
'settings' => $attributes['settings'] ?? [],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a validation rule for a warehouse.
|
||||
*/
|
||||
protected function createWarehouseRule(Warehouse $warehouse, array $attributes = []): WarehouseValidationRule
|
||||
{
|
||||
return WarehouseValidationRule::query()->create([
|
||||
'warehouse_id' => $warehouse->id,
|
||||
'name' => $attributes['name'] ?? 'Location required',
|
||||
'rule_key' => $attributes['rule_key'] ?? 'stock.location.required',
|
||||
'severity' => $attributes['severity'] ?? 'error',
|
||||
'is_active' => $attributes['is_active'] ?? true,
|
||||
'configuration' => $attributes['configuration'] ?? ['required' => true],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a non-system tenant company for admin screens.
|
||||
*/
|
||||
protected function createTenantCompany(array $attributes = []): Company
|
||||
{
|
||||
$company = Company::query()->create([
|
||||
'name' => $attributes['name'] ?? 'Browser Tenant Ltd',
|
||||
'slug' => $attributes['slug'] ?? 'browser-tenant-ltd',
|
||||
'status' => $attributes['status'] ?? 'active',
|
||||
'timezone' => $attributes['timezone'] ?? 'Europe/London',
|
||||
'is_system_company' => $attributes['is_system_company'] ?? false,
|
||||
'billing_email' => $attributes['billing_email'] ?? 'billing@browser-tenant.example',
|
||||
'settings' => $attributes['settings'] ?? [],
|
||||
]);
|
||||
|
||||
LicenseKey::issueFor($company, 'Browser Test Licence', 'enterprise', 100);
|
||||
|
||||
return $company;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a payment row for platform payment tables.
|
||||
*/
|
||||
protected function createPaymentFor(Company $company, array $attributes = []): Payment
|
||||
{
|
||||
return Payment::query()->create([
|
||||
'company_id' => $company->id,
|
||||
'stripe_payment_intent_id' => $attributes['stripe_payment_intent_id'] ?? null,
|
||||
'stripe_invoice_id' => $attributes['stripe_invoice_id'] ?? null,
|
||||
'amount' => $attributes['amount'] ?? 129900,
|
||||
'currency' => $attributes['currency'] ?? 'gbp',
|
||||
'status' => $attributes['status'] ?? 'paid',
|
||||
'description' => $attributes['description'] ?? 'Annual platform licence',
|
||||
'paid_at' => $attributes['paid_at'] ?? now(),
|
||||
'metadata' => $attributes['metadata'] ?? ['source' => 'browser_test'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Laravel\Dusk\Browser;
|
||||
|
||||
trait TestsResponsiveBreakpoints
|
||||
{
|
||||
/**
|
||||
* @return array<string, array{width:int, height:int}>
|
||||
*/
|
||||
protected function responsiveBreakpoints(): array
|
||||
{
|
||||
return [
|
||||
'desktop' => ['width' => 1440, 'height' => 900],
|
||||
'laptop' => ['width' => 1280, 'height' => 800],
|
||||
'tablet_portrait' => ['width' => 768, 'height' => 1024],
|
||||
'tablet_landscape' => ['width' => 1024, 'height' => 768],
|
||||
'mobile' => ['width' => 390, 'height' => 844],
|
||||
'small_mobile' => ['width' => 360, 'height' => 740],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a browser assertion across every supported WMS viewport.
|
||||
*
|
||||
* @param Closure(Browser, string): void $callback
|
||||
*/
|
||||
protected function eachBreakpoint(Browser $browser, Closure $callback): void
|
||||
{
|
||||
foreach ($this->responsiveBreakpoints() as $name => $size) {
|
||||
$browser->resize($size['width'], $size['height']);
|
||||
$callback($browser, $name);
|
||||
$browser->screenshot("wms-responsive-{$name}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decide whether the breakpoint should use the off-canvas mobile navigation.
|
||||
*/
|
||||
protected function isMobileNavigationBreakpoint(string $breakpoint): bool
|
||||
{
|
||||
return in_array($breakpoint, ['tablet_portrait', 'mobile', 'small_mobile'], true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user