From 9caec06dfc07b5fabfad6f9df963e12ce539eb3f Mon Sep 17 00:00:00 2001 From: Alexandr Chernyaev Date: Sun, 26 Jan 2025 02:55:31 +0300 Subject: [PATCH] Added screen `state` test --- tests/App/Screens/BaseScreenTesting.php | 11 ++++++++++- .../Support/HelperDynamicTestScreenTest.php | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/App/Screens/BaseScreenTesting.php b/tests/App/Screens/BaseScreenTesting.php index be36fce74..8b414d266 100644 --- a/tests/App/Screens/BaseScreenTesting.php +++ b/tests/App/Screens/BaseScreenTesting.php @@ -14,13 +14,17 @@ class BaseScreenTesting extends Screen { + + public int $increment = 0; + /** * Query data. */ public function query(?User $user = null): array { return [ - 'user' => $user, + 'user' => $user, + 'increment' => $this->increment, ]; } @@ -84,4 +88,9 @@ public function methodWithValidation(Request $request): void Toast::warning('Validation Success'); } + + public function increment():void + { + $this->increment++; + } } diff --git a/tests/Unit/Support/HelperDynamicTestScreenTest.php b/tests/Unit/Support/HelperDynamicTestScreenTest.php index cd26550c5..ba36c98f9 100644 --- a/tests/Unit/Support/HelperDynamicTestScreenTest.php +++ b/tests/Unit/Support/HelperDynamicTestScreenTest.php @@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Route; use Orchid\Platform\Models\User; +use Orchid\Support\Facades\Dashboard; use Orchid\Support\Testing\DynamicTestScreen; use Orchid\Support\Testing\ScreenTesting; use Orchid\Tests\App\Screens\BaseScreenTesting; @@ -112,4 +113,20 @@ public function testFollowingAndWithoutFollowingRedirects(): void ->assertRedirect() ->assertInvalid(['title', 'body']); } + + public function testUsageStateIncrementExample(): void + { + $screen = $this->screen() + ->register(BaseScreenTesting::class); + + $screen->display()->assertOk(); + + foreach (range(1, 10) as $i) { + $screen + ->followingRedirects() + ->method('increment'); + + $this->assertEquals($i, Dashboard::getCurrentScreen()->increment); + } + } }