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
7 changes: 7 additions & 0 deletions tests/Feature/Screens/CommitDetailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1016,3 +1016,10 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []):

expect(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($bar + 4 * 21);
});

it("offers delete on a commit from an organization you're a member of", function () {
joinOrganizations('org-1');
fakeThread(['author' => organizationAuthorJson('org-1', 'NativePHP')]);

Native::visit('/log/commits/c2')->assertElement('top_bar_action', fn (array $node): bool => ($node['props']['id'] ?? null) === 'delete');
});
31 changes: 31 additions & 0 deletions tests/Feature/Screens/CommitMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,34 @@

Http::assertNotSent(fn (Request $request): bool => str_ends_with($request->url(), '/pin'));
});

it("leaves Report commit off a commit from an organization you're a member of, which devnull won't take", function () {
joinOrganizations('org-1');
serveApi(fn () => Http::response(pageJson([commitJson(['id' => 'c1', 'author' => organizationAuthorJson('org-1', 'NativePHP')])])));

$screen = Native::visit('/log', platform: 'ios')->call('reportCommit', 'c1');

expect(array_column(array_filter(menuItems($screen, 'more-c1'), is_array(...)), 0))->not->toContain('report-c1')
->and($screen->instance()->sheetOpen)->toBeFalse();
});

it("deletes a commit from an organization you're a member of, as devnull lets you, without offering to pin it", function () {
joinOrganizations('org-1');
fakeApi([
'GET /api/v1/log/following' => [pageJson([commitJson(['id' => 'c1', 'body' => 'Delete me', 'author' => organizationAuthorJson('org-1', 'NativePHP')])])],
'DELETE /api/v1/commits/c1' => [null, 204],
]);

$screen = Native::visit('/log', platform: 'ios');

expect(menuItems($screen, 'more-c1'))->toBe([
['share-c1', 'Share link', 'custom:link'],
'divider',
['delete-c1', 'Delete commit', 'custom:trash-2'],
]);

$screen->tap('delete-c1')
->emitNative(ButtonPressed::class, ['index' => 1, 'label' => 'Delete', 'id' => 'delete-commit']);

Http::assertSent(fn (Request $request): bool => $request->method() === 'DELETE' && $request->url() === 'http://devnull.test/api/v1/commits/c1');
});
2 changes: 2 additions & 0 deletions tests/Feature/Screens/PollVoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function pollOnLog(array $commit = [], ?array $answer = null): TestableComponent
});

it('offers no vote where the web offers none', function (array $commit) {
joinOrganizations('org-1');
$screen = pollOnLog($commit)->call('choosePollOption', 'c1', 'o1');

expect(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'poll-vote-c1'))->toBeNull()
Expand All @@ -105,6 +106,7 @@ function pollOnLog(array $commit = [], ?array $answer = null): TestableComponent
Http::assertNotSent(fn (Request $request): bool => $request->method() === 'POST');
})->with([
'your own poll' => [['author' => userJson()]],
"an organization's you're a member of, which someone else posted" => [['author' => organizationAuthorJson('org-1', 'NativePHP')]],
'one awaiting approval' => [['status' => 'pending', 'poll' => openPollJson(['closes_at' => null])]],
'a closed poll' => [['poll' => openPollJson(['closes_at' => '2026-10-19T11:59:00Z'])]],
'one you voted on' => [['poll' => openPollJson(results: true)]],
Expand Down
9 changes: 9 additions & 0 deletions tests/Feature/Screens/QuoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ function quoteButtonDisabled(TestableComponent $screen): bool
expect(nodeByRef($screen, 'sheet')['props']['visible'])->toBeFalse();
});

it("quotes a commit from an organization you're a member of while it waits for approval, as devnull lets you", function () {
joinOrganizations('org-1');
serveQuoteLog([commitJson(['id' => 'c1', 'status' => 'pending', 'author' => organizationAuthorJson('org-1', 'NativePHP')])]);

$screen = Native::visit('/log', platform: 'ios')->tap('quote-c1');

expect(nodeByRef($screen, 'sheet')['props']['visible'])->toBeTrue();
});

it('opens a composer over the commit being quoted, drawn as the static quote card', function () {
$screen = quoteSheetOnLog();

Expand Down
26 changes: 26 additions & 0 deletions tests/Feature/Screens/StargazersSheetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,29 @@ function ownStarredCommit(int $count, array $pages, string $platform = 'ios'): T
expect(sentTo('GET', 'commits/c1/stars'))->toBe([])
->and(sentTo('GET', 'commits/c2/stars'))->toBe([]);
});

it('opens who starred a commit an organization you belong to posted, since devnull treats it as your commit', function (string $platform) {
$organization = fn (string $id, string $handle): array => userJson(['id' => $id, 'type' => 'organization', 'handle' => $handle, 'name' => $handle]);

serveApi([
'GET /api/v1/me' => [['data' => [...userJson(), 'organizations' => [['role' => 'admin', ...$organization('org-1', 'NativePHP')]]]]],
'GET /api/v1/log/following' => [pageJson([
commitJson(['id' => 'c1', 'stars_count' => 3, 'author' => $organization('org-1', 'NativePHP')]),
commitJson(['id' => 'c2', 'stars_count' => 2, 'author' => $organization('org-2', 'laravel')]),
])],
'GET /api/v1/commits/c1/stars' => [pageJson([stargazerJson('grace', 'Grace Hopper')], path: 'http://devnull.test/api/v1/commits/c1/stars')],
]);

$screen = finishRefreshes(Native::visit('/log', platform: $platform));

expect(nodeByRef($screen, 'star-count-c1'))->type->toBe('pressable')->props->a11y_label->toBe('3 stars, show who starred')
->and(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'star-c1'))->toBeNull()
->and(nodeByRef($screen, 'star-c2'))->type->toBe('pressable');

finishRefreshes($screen->call('toggleStar', 'c1'));

expect(sentTo('POST', 'commits/c1/star'))->toBe([])
->and(nodeByRef($screen, 'star-count-c1')['props']['a11y_label'])->toBe('3 stars, show who starred');

$screen->tap('star-count-c1')->assertSee('Starred by')->assertSee('Grace Hopper');
})->with(['ios', 'android']);
21 changes: 21 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,27 @@ function signIn(array $user = []): FakeBridge
return $bridge;
}

/**
* Makes you a member of the given organizations, as `GET /me` lists them, so devnull counts their commits as yours.
*/
function joinOrganizations(string ...$ids): void
{
app(Account::class)->rememberOrganizations(array_map(
fn (string $id): User => User::fromArray(userJson(['id' => $id, 'type' => 'organization', 'handle' => $id, 'name' => $id])),
$ids,
));
}

/**
* An organization as the API sends one as a commit's author.
*
* @return array<string, mixed>
*/
function organizationAuthorJson(string $id, string $handle): array
{
return userJson(['id' => $id, 'type' => 'organization', 'handle' => $handle, 'name' => $handle]);
}

/**
* A user as the API sends one to a signed request: a commit's author, a
* notification's actor. Its links follow the username unless a test sends its own.
Expand Down