diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index 5273f81a..70b10646 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -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'); +}); diff --git a/tests/Feature/Screens/CommitMenuTest.php b/tests/Feature/Screens/CommitMenuTest.php index 41d75ed2..86485d53 100644 --- a/tests/Feature/Screens/CommitMenuTest.php +++ b/tests/Feature/Screens/CommitMenuTest.php @@ -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'); +}); diff --git a/tests/Feature/Screens/PollVoteTest.php b/tests/Feature/Screens/PollVoteTest.php index cbc8bc68..68555033 100644 --- a/tests/Feature/Screens/PollVoteTest.php +++ b/tests/Feature/Screens/PollVoteTest.php @@ -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() @@ -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)]], diff --git a/tests/Feature/Screens/QuoteTest.php b/tests/Feature/Screens/QuoteTest.php index 38d28c21..3d257b00 100644 --- a/tests/Feature/Screens/QuoteTest.php +++ b/tests/Feature/Screens/QuoteTest.php @@ -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(); diff --git a/tests/Feature/Screens/StargazersSheetTest.php b/tests/Feature/Screens/StargazersSheetTest.php index 0d37d788..e5f6e260 100644 --- a/tests/Feature/Screens/StargazersSheetTest.php +++ b/tests/Feature/Screens/StargazersSheetTest.php @@ -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']); diff --git a/tests/Pest.php b/tests/Pest.php index 6af30cc4..493aa65c 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -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 + */ +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.