Skip to content
Open
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: 7 additions & 2 deletions app/NativeComponents/Concerns/HoldsNewCommits.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Devnull\Data\Commit;
use App\Devnull\Data\Page;
use App\Devnull\FreshPage;
use App\Devnull\ResponseCache;

/**
* A list of commits that takes fresh first pages without moving under your
Expand Down Expand Up @@ -94,13 +95,17 @@ protected function waitingCommits(): array

/**
* Lays a fresh first page over the list. Newer commits wait for the pill
* unless $showNewer says you asked for them.
* unless $showNewer says you asked for them. Commits deleted on this phone
* leave it first, wherever they are in it: the fresh page only knows about
* its own, and the rows below it stay.
*
* @param array<string, mixed> $json
*/
protected function layFreshCommits(array $json, bool $showNewer = false): void
{
$fresh = FreshPage::over($this->commits, $this->nextCursor, Page::fromArray($json, Commit::fromArray(...)), $this->madeHere);
$deleted = array_flip(app(ResponseCache::class)->deletedIds());
$shown = array_values(array_filter($this->commits, fn (Commit $commit): bool => ! isset($deleted[$commit->id])));
$fresh = FreshPage::over($shown, $this->nextCursor, Page::fromArray($json, Commit::fromArray(...)), $this->madeHere);

$this->commits = $fresh->items;
$this->nextCursor = $fresh->nextCursor;
Expand Down
36 changes: 36 additions & 0 deletions tests/Feature/Screens/CommitMenuTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Devnull\Client;
use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;
use Native\Mobile\Events\Alert\ButtonPressed;
Expand Down Expand Up @@ -121,6 +122,41 @@
Http::assertSent(fn (Request $request): bool => $request->method() === 'DELETE' && $request->url() === 'http://devnull.test/api/v1/commits/c2');
});

it('takes a commit you deleted off your profile when it was further down than the first page', function () {
$deleted = [];

serveApi(function (Request $request) use (&$deleted) {
$route = $request->method().' '.parse_url($request->url(), PHP_URL_PATH);

return match (true) {
str_starts_with($route, 'DELETE /api/v1/commits/') => tap(Http::response(null, 204), function () use (&$deleted, $route): void {
$deleted[] = basename($route);
}),
$route === 'GET /api/v1/users/local_dev' => Http::response(['data' => userWithCountsJson(commits: 3 - count($deleted)), 'is_following' => false, 'pinned_commit' => null]),
$route === 'GET /api/v1/users/local_dev/commits' && str_contains($request->url(), 'cursor=older') => Http::response(pageJson(array_values(array_filter([
commitJson(['id' => 'c2', 'body' => 'Delete me here']),
commitJson(['id' => 'c1', 'body' => 'Delete me on its page']),
], fn (array $commit): bool => ! in_array($commit['id'], $deleted, true))))),
$route === 'GET /api/v1/users/local_dev/commits' => Http::response(pageJson([commitJson(['id' => 'c3', 'body' => 'Keep me'])], 'older')),
default => Http::response(currentUserJson()),
};
});

$screen = Native::visit('/log/users/local_dev', platform: 'ios')
->call('loadMore')
->assertSee('Delete me here')
->tap('delete-c2')
->emitNative(ButtonPressed::class, ['index' => 1, 'label' => 'Delete', 'id' => 'delete-commit'])
->assertDontSee('Delete me here')
->assertSee('Delete me on its page');

app(Client::class)->deleteCommit('c1');

$screen->call('onResume')
->assertDontSee('Delete me on its page')
->assertSee('Keep me');
});

it('deletes your reply from a commit page, staying on the page', function () {
$deleted = false;

Expand Down