Skip to content

Commit

Permalink
Added screen state test
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Jan 25, 2025
1 parent b8e3452 commit 9caec06
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/App/Screens/BaseScreenTesting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

Expand Down Expand Up @@ -84,4 +88,9 @@ public function methodWithValidation(Request $request): void

Toast::warning('Validation Success');
}

public function increment():void
{
$this->increment++;
}
}
17 changes: 17 additions & 0 deletions tests/Unit/Support/HelperDynamicTestScreenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 9caec06

Please sign in to comment.