mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 23:18:10 +00:00
This commit is contained in:
parent
a88e72b75e
commit
ba3bf31bb7
29 changed files with 2379 additions and 215 deletions
89
tests/Feature/DeviceModelsTest.php
Normal file
89
tests/Feature/DeviceModelsTest.php
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Models\DeviceModel;
|
||||
use App\Models\User;
|
||||
|
||||
it('allows a user to view the device models page', function (): void {
|
||||
$user = User::factory()->create();
|
||||
$deviceModels = DeviceModel::factory()->count(3)->create();
|
||||
|
||||
$response = $this->actingAs($user)->get('/device-models');
|
||||
|
||||
$response->assertSuccessful();
|
||||
$response->assertSee('Device Models');
|
||||
$response->assertSee('Add Device Model');
|
||||
|
||||
foreach ($deviceModels as $deviceModel) {
|
||||
$response->assertSee($deviceModel->label);
|
||||
$response->assertSee((string) $deviceModel->width);
|
||||
$response->assertSee((string) $deviceModel->height);
|
||||
$response->assertSee((string) $deviceModel->bit_depth);
|
||||
}
|
||||
});
|
||||
|
||||
it('allows creating a device model', function (): void {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$deviceModelData = [
|
||||
'name' => 'test-model',
|
||||
'label' => 'Test Model',
|
||||
'description' => 'A test device model',
|
||||
'width' => 800,
|
||||
'height' => 600,
|
||||
'colors' => 256,
|
||||
'bit_depth' => 8,
|
||||
'scale_factor' => 1.0,
|
||||
'rotation' => 0,
|
||||
'mime_type' => 'image/png',
|
||||
'offset_x' => 0,
|
||||
'offset_y' => 0,
|
||||
];
|
||||
|
||||
$deviceModel = DeviceModel::create($deviceModelData);
|
||||
|
||||
$this->assertDatabaseHas('device_models', $deviceModelData);
|
||||
expect($deviceModel->name)->toBe($deviceModelData['name']);
|
||||
});
|
||||
|
||||
it('allows updating a device model', function (): void {
|
||||
$user = User::factory()->create();
|
||||
$deviceModel = DeviceModel::factory()->create();
|
||||
|
||||
$updatedData = [
|
||||
'name' => 'updated-model',
|
||||
'label' => 'Updated Model',
|
||||
'description' => 'An updated device model',
|
||||
'width' => 1024,
|
||||
'height' => 768,
|
||||
'colors' => 65536,
|
||||
'bit_depth' => 16,
|
||||
'scale_factor' => 1.5,
|
||||
'rotation' => 90,
|
||||
'mime_type' => 'image/jpeg',
|
||||
'offset_x' => 10,
|
||||
'offset_y' => 20,
|
||||
];
|
||||
|
||||
$deviceModel->update($updatedData);
|
||||
|
||||
$this->assertDatabaseHas('device_models', $updatedData);
|
||||
expect($deviceModel->fresh()->name)->toBe($updatedData['name']);
|
||||
});
|
||||
|
||||
it('allows deleting a device model', function (): void {
|
||||
$user = User::factory()->create();
|
||||
$deviceModel = DeviceModel::factory()->create();
|
||||
|
||||
$deviceModelId = $deviceModel->id;
|
||||
$deviceModel->delete();
|
||||
|
||||
$this->assertDatabaseMissing('device_models', ['id' => $deviceModelId]);
|
||||
});
|
||||
|
||||
it('redirects unauthenticated users from the device models page', function (): void {
|
||||
$response = $this->get('/device-models');
|
||||
|
||||
$response->assertRedirect('/login');
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue