Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/NativeComponents/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,17 @@ protected function showsContent(): bool

/**
* A profile across a block has its own page, as on the web, whatever devnull's message says. devnull sends who
* you blocked with it, for the page's name and avatar.
* you blocked with it, for the page's name and avatar. A handle no user has may be an organization's, which shares
* its link on the web, so until devnull has sent anything for it, the organization's screen takes this one's place.
*/
protected function refused(ApiException $exception): bool
{
if ($exception->status === 404 && ! $this->commitsLoaded && ($this->profile === null || $this->sketched)) {
$this->replace($this->tabRoot().'/organizations/'.rawurlencode($this->username));

return true;
}

if ($exception->is(ErrorCode::UserBlocked)) {
if ($exception->user !== null && $exception->user->username === $this->username) {
$this->profile = new ProfileData($exception->user);
Expand Down
30 changes: 30 additions & 0 deletions tests/Feature/Screens/ProfileTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Devnull\Data\User;
use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;
use Native\Mobile\Testing\Native;
Expand Down Expand Up @@ -469,3 +470,32 @@ function adaCommitJson(array $overrides = []): array

finishRefreshes($screen)->assertSet('skeletonFrame', false)->assertSee('Kept Name')->assertSee('Kept commit');
});

it("opens an organization's screen in its place when devnull has no user by that handle, as the web does", function (string $tab, Closure $data) {
fakeApi([
'GET /api/v1/users/dev-null-sh' => [['message' => 'No query results for model [App\\Models\\User] dev-null-sh'], 404],
'GET /api/v1/users/dev-null-sh/commits' => [['message' => 'No query results for model [App\\Models\\User] dev-null-sh'], 404],
]);

Native::visit("{$tab}/users/dev-null-sh", data: $data())->assertReplacedWith("{$tab}/organizations/dev-null-sh");
})->with([
'a link to it' => ['/log', fn (): array => []],
'a notification it sent' => ['/notifications', fn (): array => ['user' => User::fromArray(userJson(['handle' => 'dev-null-sh']))]],
]);

it("stays a person's profile when a thread on it is gone", function (Closure $profile, Closure $data) {
keep('commits/c1/replies', pageJson([]));
fakeApi([
'GET /api/v1/users/ada' => $profile(),
'GET /api/v1/users/ada/commits' => [pageJson([adaCommitJson(['id' => 'c1'])])],
'GET /api/v1/commits/c1/replies' => [['message' => 'No query results for model [App\\Models\\Commit] c1'], 404],
]);

Native::visit('/log/users/ada', data: $data())
->call('toggleReplies', 'c1')
->assertNoNavigation()
->assertSee('Ada Lovelace');
})->with([
'devnull sent it' => [fn (): array => [profileJson()], fn (): array => []],
"devnull couldn't send it yet" => [fn (): array => [['message' => 'Server Error'], 500], fn (): array => ['user' => User::fromArray(userJson(['handle' => 'ada', 'name' => 'Ada Lovelace']))]],
]);
Loading