Skip to content

Commit 69e3b9c

Browse files
committed
add support and dashboard tests
1 parent f41628c commit 69e3b9c

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
use Inertia\Testing\AssertableInertia as Assert;
4+
use Modules\User\Models\User;
5+
6+
beforeEach(function () {
7+
$this->user = User::factory()->create();
8+
$this->loggedRequest = $this->actingAs($this->user);
9+
});
10+
11+
it('can render the dashboard page', function () {
12+
$dashboardUrl = route(config('modular.default-logged-route'));
13+
$response = $this->loggedRequest->get($dashboardUrl);
14+
15+
$response->assertStatus(200);
16+
17+
$response->assertInertia(
18+
fn (Assert $page) => $page
19+
->component('Dashboard/DashboardIndex')
20+
->has(
21+
'auth.user',
22+
fn (Assert $page) => $page
23+
->where('id', $this->user->id)
24+
->where('name', $this->user->name)
25+
->etc()
26+
)
27+
->has(
28+
'auth.permissions',
29+
)
30+
->has(
31+
'errors',
32+
)
33+
->has(
34+
'flash',
35+
2,
36+
)
37+
->has(
38+
'ziggy.routes',
39+
)
40+
);
41+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use Illuminate\Filesystem\Filesystem;
4+
use Illuminate\Http\UploadedFile;
5+
use Modules\Support\Traits\EditorImage;
6+
7+
use function PHPUnit\Framework\assertFileExists;
8+
9+
uses(EditorImage::class);
10+
11+
beforeEach(function () {
12+
(new Filesystem)->deleteDirectory(storage_path('editor-files'));
13+
});
14+
15+
afterAll(function () {
16+
(new Filesystem)->deleteDirectory(storage_path('editor-files'));
17+
});
18+
19+
it('can upload an image to the default editor media file path', function () {
20+
$file = UploadedFile::fake()->image('A nice file.jpg');
21+
22+
$result = $this->uploadImage($file, 'original');
23+
24+
expect($result)->toHaveKeys(['fileName', 'filePath', 'fileUrl', 'readableName']);
25+
expect($result['readableName'])->toBe('A nice file');
26+
assertFileExists($result['filePath']);
27+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
use Illuminate\Filesystem\Filesystem;
4+
use Illuminate\Http\UploadedFile;
5+
use Modules\Support\Traits\FileNameGenerator;
6+
7+
beforeEach(function () {
8+
(new Filesystem)->deleteDirectory(storage_path('editor-files'));
9+
});
10+
11+
afterAll(function () {
12+
(new Filesystem)->deleteDirectory(storage_path('editor-files'));
13+
});
14+
15+
uses(FileNameGenerator::class);
16+
17+
it('can set the name of a uploaded file', function () {
18+
$file = UploadedFile::fake()->image('A nice file.jpg');
19+
20+
$readableName = $this->getReadableName($file);
21+
$fileName = $this->getFileName($file, $readableName, 'original');
22+
23+
expect($fileName)->toBe('a-nice-file.jpg');
24+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Filesystem\Filesystem;
4+
use Modules\Support\Traits\UploadFile;
5+
6+
uses(UploadFile::class);
7+
8+
beforeEach(function () {
9+
(new Filesystem)->deleteDirectory(storage_path('user-files'));
10+
});
11+
12+
afterAll(function () {
13+
(new Filesystem)->deleteDirectory(storage_path('user-files'));
14+
});
15+
16+
it('can handle requests without uploads', function () {
17+
$result = $this->uploadFile('');
18+
19+
expect($result)->toBe([]);
20+
});
21+
22+
it('can handle requests with wrong inputs', function () {
23+
request('file', 'not an uploaded file');
24+
25+
$result = $this->uploadFile('file');
26+
27+
expect($result)->toBe([]);
28+
});

0 commit comments

Comments
 (0)