-
Notifications
You must be signed in to change notification settings - Fork 41
feat: user profile address #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dbd815d
feat: specify login page class for partner and user panel providers
Clintonrocha98 ff5c840
feat(user-profile): add information and address management to user pr…
Clintonrocha98 5400b89
feat: add filament-smart-cep package for Brazilian postal code valida…
Clintonrocha98 65a0b29
feat(user-profile): enhance address form with ZIP code auto-fetch and…
Clintonrocha98 a416783
feat(tests): update claimed_at format in ClaimCharacterBadgeTest
Clintonrocha98 93491c1
feat(user-profile): update address form validation and notifications …
Clintonrocha98 9e8ace9
feat(user-profile): add tests for user profile information and addres…
Clintonrocha98 34f29bc
Merge branch '3.x' into feat/user-profile-address
Clintonrocha98 26afb02
wip
Clintonrocha98 ac4b70d
Merge branch 'feat/user-profile-address' of github.com:he4rt/he4rt-bo…
Clintonrocha98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
app-modules/user/tests/Feature/Filament/User/Pages/UserProfileTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Filament\Facades\Filament; | ||
| use He4rt\Tenant\Models\Tenant; | ||
| use He4rt\User\Filament\User\Pages\UserProfile; | ||
| use He4rt\User\Models\User; | ||
|
|
||
| beforeEach(function (): void { | ||
| $this->user = User::factory()->create(); | ||
| $this->tenant = Tenant::factory()->create([ | ||
| 'owner_id' => $this->user->id, | ||
| 'slug' => 'he4rt', | ||
| ]); | ||
|
|
||
| $this->actingAs($this->user); | ||
| Filament::setCurrentPanel('user'); | ||
| Filament::setTenant($this->tenant); | ||
| }); | ||
| it('renders the user profile page successfully for a tenant', function (): void { | ||
| Livewire::test(UserProfile::class, ['tenant' => $this->tenant]) | ||
| ->assertStatus(200) | ||
| ->assertSee('Information') | ||
| ->assertSee('Address'); | ||
| }); | ||
|
|
||
| it('saves user information correctly for tenant', function (): void { | ||
| $page = Livewire::test(UserProfile::class, ['tenant' => $this->tenant]); | ||
|
|
||
| $page->set('informationData', [ | ||
| 'name' => 'John Doe', | ||
| 'nickname' => 'Johnny', | ||
| 'birthdate' => '1995-03-14', | ||
| 'about' => 'Software developer.', | ||
| 'linkedin_url' => 'https://linkedin.com/in/johnny', | ||
| 'github_url' => 'https://github.com/johnny', | ||
| ]); | ||
|
|
||
| $page->call('saveInformation'); | ||
|
|
||
| $this->assertDatabaseHas('user_information', [ | ||
| 'user_id' => $this->user->id, | ||
| 'name' => 'John Doe', | ||
| 'nickname' => 'Johnny', | ||
| ]); | ||
| }); | ||
|
|
||
| it('saves address correctly for tenant', function (): void { | ||
| $page = Livewire::test(UserProfile::class, ['tenant' => $this->tenant]); | ||
|
|
||
| $page->set('addressData', [ | ||
| 'zip_code' => '13000-000', | ||
| 'country' => 'Brazil', | ||
| 'state' => 'São Paulo', | ||
| 'city' => 'Campinas', | ||
| ]); | ||
|
|
||
| $page->call('saveAddress'); | ||
|
|
||
| $this->assertDatabaseHas('user_address', [ | ||
| 'user_id' => $this->user->id, | ||
| 'city' => 'Campinas', | ||
| 'zip_code' => '13000-000', | ||
| ]); | ||
| }); | ||
|
|
||
| it('requires a name in information form', function (): void { | ||
| Livewire::test(UserProfile::class, ['tenant' => $this->tenant]) | ||
| ->set('informationData', [ | ||
| 'name' => '', | ||
| 'nickname' => 'Clint', | ||
| ]) | ||
| ->call('saveInformation') | ||
| ->assertHasErrors(['informationData.name' => 'required']); | ||
| }); | ||
|
|
||
| it('validates nickname max length', function (): void { | ||
| $tooLong = str_repeat('N', 300); | ||
|
|
||
| Livewire::test(UserProfile::class, ['tenant' => $this->tenant]) | ||
| ->set('informationData.nickname', $tooLong) | ||
| ->call('saveInformation') | ||
| ->assertHasErrors(['informationData.nickname' => 'max']); | ||
| }); | ||
|
|
||
| it('validates linkedin and github urls', function (): void { | ||
| Livewire::test(UserProfile::class, ['tenant' => $this->tenant]) | ||
| ->set('informationData.linkedin_url', 'not-a-url') | ||
| ->set('informationData.github_url', '1234') | ||
| ->call('saveInformation') | ||
| ->assertHasErrors([ | ||
| 'informationData.linkedin_url' => 'url', | ||
| 'informationData.github_url' => 'url', | ||
| ]); | ||
| }); | ||
|
|
||
| it('validates birthdate as a valid date', function (): void { | ||
| Livewire::test(UserProfile::class, ['tenant' => $this->tenant]) | ||
| ->set('informationData.birthdate', 'not-a-date') | ||
| ->call('saveInformation') | ||
| ->assertHasErrors(['informationData.birthdate' => 'date']); | ||
| }); | ||
|
|
||
| it('validates about field max 1000 characters', function (): void { | ||
| $tooLong = str_repeat('X', 1100); | ||
|
|
||
| Livewire::test(UserProfile::class, ['tenant' => $this->tenant]) | ||
| ->set('informationData.about', $tooLong) | ||
| ->call('saveInformation') | ||
| ->assertHasErrors(['informationData.about' => 'max']); | ||
| }); | ||
|
|
||
| it('saves valid information successfully', function (): void { | ||
| Livewire::test(UserProfile::class, ['tenant' => $this->tenant]) | ||
| ->set('informationData', [ | ||
| 'name' => 'John Doe', | ||
| 'nickname' => 'JD', | ||
| 'linkedin_url' => 'https://linkedin.com/in/johndoe', | ||
| 'github_url' => 'https://github.com/johndoe', | ||
| 'birthdate' => '1990-01-01', | ||
| 'about' => 'Senior developer at Example Inc.', | ||
| ]) | ||
| ->call('saveInformation') | ||
| ->assertHasNoErrors(); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.