trypost/tests/Feature/Settings/ProfileUpdateTest.php
Paulo Castellano f3f72afecd refactor: auth split layout, subscribe redesign, onboarding, i18n, cookie locale
Auth pages:
- Create AuthSplitLayout with animated feature slides (6 slides, 3 languages)
- All auth pages use split layout (form left, visual right)
- Add show/hide password toggle with tooltip on Register
- Legal footer only shown on Register via showLegal prop

Subscribe page:
- Redesign to match auth card pattern (centered, clean)
- Platform icons, feature checklist, dynamic trial days (trialDays - 1)
- Add "Switch workspace" link
- Full i18n (en, es, pt-BR)

Onboarding:
- Rename URLs: step1 -> role, step2 -> connect
- Add enforceStep() to prevent skipping/going back steps
- Redirect /onboarding to /onboarding/role
- Redesign Step2 with AuthSplitLayout and compact platform list
- 21 tests covering all step enforcement scenarios

Workspaces page:
- Redesign with AuthSplitLayout (list with avatars, current badge)

Language system:
- Move locale from DB to cookie (forever, unencrypted, session.domain)
- Create SetLocale middleware (sets cookie if missing, validates against config)
- Rename lang/pt-br to lang/pt-BR
- Add dayjs es locale

Other:
- Copy utils.ts from sendkit (formatNumber, formatMoney, copyToClipboard)
- ConfirmDeleteModal with text confirmation (sendkit pattern)
- i18n for ConfirmDeleteModal internal strings (common.php)
- EmptyState component for posts index
- Exact match for "All" posts in sidebar
- Posts breadcrumbs show current status filter
- DialogFooter buttons aligned left
- API Keys page redesign with Table, DropdownMenu, EmptyState
- Extract CreateApiKeyDialog and InviteMemberDialog to components
- Remove API Keys from sidebar
- DropdownMenuItem destructive variant for Remove action
2026-03-30 11:53:42 -03:00

178 lines
5.5 KiB
PHP

<?php
declare(strict_types=1);
use App\Enums\UserWorkspace\Role;
use App\Models\User;
use App\Models\Workspace;
test('profile page is displayed', function () {
$user = User::factory()->create();
$response = $this
->actingAs($user)
->get(route('app.profile.edit'));
$response->assertOk();
});
test('profile information can be updated', function () {
$user = User::factory()->create();
$response = $this
->actingAs($user)
->patch(route('app.profile.update'), [
'name' => 'Test User',
'email' => 'test@example.com',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect(route('app.profile.edit'));
$user->refresh();
expect($user->name)->toBe('Test User');
expect($user->email)->toBe('test@example.com');
expect($user->email_verified_at)->toBeNull();
});
test('email verification status is unchanged when the email address is unchanged', function () {
$user = User::factory()->create();
$response = $this
->actingAs($user)
->patch(route('app.profile.update'), [
'name' => 'Test User',
'email' => $user->email,
]);
$response
->assertSessionHasNoErrors()
->assertRedirect(route('app.profile.edit'));
expect($user->refresh()->email_verified_at)->not->toBeNull();
});
test('user can update their locale via cookie', function () {
$user = User::factory()->create();
$response = $this
->actingAs($user)
->from(route('app.posts.index'))
->patch(route('app.profile.language'), [
'locale' => 'es',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect(route('app.posts.index'));
$response->assertCookieNotExpired('locale');
});
test('user cannot update locale with invalid code', function () {
$user = User::factory()->create();
$response = $this
->actingAs($user)
->patch(route('app.profile.language'), [
'locale' => 'invalid',
]);
$response->assertSessionHasErrors('locale');
});
test('user can delete their account', function () {
$user = User::factory()->create();
$response = $this
->actingAs($user)
->delete(route('app.profile.destroy'), [
'password' => 'password',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect(route('app.home'));
$this->assertGuest();
expect($user->fresh())->toBeNull();
});
test('correct password must be provided to delete account', function () {
$user = User::factory()->create();
$response = $this
->actingAs($user)
->from(route('app.profile.edit'))
->delete(route('app.profile.destroy'), [
'password' => 'wrong-password',
]);
$response
->assertSessionHasErrors('password')
->assertRedirect(route('app.profile.edit'));
expect($user->fresh())->not->toBeNull();
});
test('deleting account updates members current_workspace_id when their workspace is deleted', function () {
$owner = User::factory()->create();
$member = User::factory()->create();
// Create a workspace owned by the owner
$workspace = Workspace::factory()->create(['user_id' => $owner->id]);
$owner->workspaces()->attach($workspace->id, ['role' => Role::Owner->value]);
$owner->update(['current_workspace_id' => $workspace->id]);
// Add member to the workspace and set it as their current
$member->workspaces()->attach($workspace->id, ['role' => Role::Member->value]);
$member->update(['current_workspace_id' => $workspace->id]);
// Verify setup
expect($member->current_workspace_id)->toBe($workspace->id);
// Owner deletes their account
$this
->actingAs($owner)
->delete(route('app.profile.destroy'), [
'password' => 'password',
]);
// Verify member's current_workspace_id is updated to null (since they have no other workspace)
expect($member->fresh()->current_workspace_id)->toBeNull();
});
test('deleting account updates members current_workspace_id to another workspace when available', function () {
$owner = User::factory()->create();
$member = User::factory()->create();
$otherOwner = User::factory()->create();
// Create workspace owned by the owner being deleted
$workspaceToDelete = Workspace::factory()->create(['user_id' => $owner->id]);
$owner->workspaces()->attach($workspaceToDelete->id, ['role' => Role::Owner->value]);
$owner->update(['current_workspace_id' => $workspaceToDelete->id]);
// Create another workspace owned by a different user
$otherWorkspace = Workspace::factory()->create(['user_id' => $otherOwner->id]);
$otherOwner->workspaces()->attach($otherWorkspace->id, ['role' => Role::Owner->value]);
// Add member to both workspaces
$member->workspaces()->attach($workspaceToDelete->id, ['role' => Role::Member->value]);
$member->workspaces()->attach($otherWorkspace->id, ['role' => Role::Member->value]);
$member->update(['current_workspace_id' => $workspaceToDelete->id]);
// Verify setup
expect($member->current_workspace_id)->toBe($workspaceToDelete->id);
// Owner deletes their account
$this
->actingAs($owner)
->delete(route('app.profile.destroy'), [
'password' => 'password',
]);
// Verify member's current_workspace_id is updated to the other workspace
expect($member->fresh()->current_workspace_id)->toBe($otherWorkspace->id);
});