Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.

Commit 69cbc5c

Browse files
authored
refactor: add dimension and alignment to UpdateProfilePhotoForm (#36)
1 parent 42ab5fa commit 69cbc5c

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

resources/views/profile/update-profile-photo-form.blade.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
<div x-data="{ isUploading: false, select() { document.getElementById('photo').click(); } }" x-on:livewire-upload-start="isUploading = true" x-on:livewire-upload-finish="isUploading = false" x-on:livewire-upload-error="isUploading = false" class="relative flex flex-col items-center mb-4 md:items-start">
1+
<div
2+
x-data="{ isUploading: false, select() { document.getElementById('photo').click(); } }"
3+
x-on:livewire-upload-start="isUploading = true"
4+
x-on:livewire-upload-finish="isUploading = false"
5+
x-on:livewire-upload-error="isUploading = false"
6+
class="relative flex flex-col {{ $alignment ?? 'items-center mb-4 md:items-start' }}"
7+
>
28
<form wire:submit.prevent="store" id="livewire-form">
39
<div
410
style="background-image: url('{{ $this->user->photo }}')"

src/Components/UpdateProfilePhotoForm.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ class UpdateProfilePhotoForm extends Component
1313
use InteractsWithUser;
1414
use WithFileUploads;
1515

16+
public $alignment;
17+
1618
public $photo;
1719

20+
public $dimensions;
21+
1822
/**
1923
* Render the component.
2024
*

tests/Components/UpdateProfilePhotoFormTest.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Spatie\MediaLibrary\MediaCollections\FileAdderFactory;
99
use Tests\MediaUser;
1010

11-
it('can_upload_a_photo', function () {
11+
it('can upload a photo', function () {
1212
$this
1313
->mock(FileAdderFactory::class)
1414
->shouldReceive('createFromDisk->toMediaCollection')
@@ -21,7 +21,7 @@
2121
->set('photo', $photo);
2222
});
2323

24-
it('cannot_upload_a_photo_with_disallowed_extension', function () {
24+
it('cannot upload a photo with disallowed extension', function () {
2525
$photo = UploadedFile::fake()->create('logo.gif', 1000, 'image/gif');
2626

2727
Livewire::actingAs(MediaUser::fake())
@@ -30,11 +30,33 @@
3030
->assertHasErrors('photo');
3131
});
3232

33-
it('cannot_upload_a_photo_that_is_too_large', function () {
33+
it('cannot upload a photo that is too large', function () {
3434
$photo = UploadedFile::fake()->image('logo.jpeg')->size(5000);
3535

3636
Livewire::actingAs(MediaUser::fake())
3737
->test(UpdateProfilePhotoForm::class)
3838
->set('photo', $photo)
3939
->assertHasErrors('photo');
4040
});
41+
42+
it('can have custom dimensions', function () {
43+
Livewire::actingAs(MediaUser::fake())
44+
->test(UpdateProfilePhotoForm::class)
45+
->assertSet('dimensions', null)
46+
->assertSee('w-48 h-48')
47+
->assertDontSee('w-24 h-24')
48+
->set('dimensions', 'w-24 h-24')
49+
->assertSet('dimensions', 'w-24 h-24')
50+
->assertSee('w-24 h-24');
51+
});
52+
53+
it('can have a custom alignment', function () {
54+
Livewire::actingAs(MediaUser::fake())
55+
->test(UpdateProfilePhotoForm::class)
56+
->assertSet('alignment', null)
57+
->assertSee('items-center mb-4 md:items-start')
58+
->set('alignment', 'items-end')
59+
->assertSet('alignment', 'items-end')
60+
->assertSee('items-end')
61+
->assertDontSee('items-center mb-4 md:items-start');
62+
});

0 commit comments

Comments
 (0)