diff --git a/src/Fakes/WindowManagerFake.php b/src/Fakes/WindowManagerFake.php index 8604224f..64112b34 100644 --- a/src/Fakes/WindowManagerFake.php +++ b/src/Fakes/WindowManagerFake.php @@ -18,6 +18,8 @@ class WindowManagerFake implements WindowManagerContract public array $hidden = []; + public array $shown = []; + public array $forcedWindowReturnValues = []; public function __construct( @@ -64,6 +66,11 @@ public function hide($id = null) $this->hidden[] = $id; } + public function show($id = null) + { + $this->shown[] = $id; + } + public function current(): Window { $this->ensureForceReturnWindowsProvided(); @@ -156,6 +163,27 @@ public function assertHidden(string|Closure $id): void PHPUnit::assertTrue($hit); } + /** + * @param string|Closure(string): bool $id + */ + public function assertShown(string|Closure $id): void + { + if (is_callable($id) === false) { + PHPUnit::assertContains($id, $this->shown); + + return; + } + + $hit = empty( + array_filter( + $this->shown, + fn (mixed $shownId) => $id($shownId) === true + ) + ) === false; + + PHPUnit::assertTrue($hit); + } + public function assertOpenedCount(int $expected): void { PHPUnit::assertCount($expected, $this->opened); @@ -171,6 +199,11 @@ public function assertHiddenCount(int $expected): void PHPUnit::assertCount($expected, $this->hidden); } + public function assertShownCount(int $expected): void + { + PHPUnit::assertCount($expected, $this->shown); + } + private function ensureForceReturnWindowsProvided(): void { Assert::notEmpty($this->forcedWindowReturnValues, 'No windows were provided to return'); diff --git a/src/Windows/WindowManager.php b/src/Windows/WindowManager.php index 64046869..bdd7f90d 100644 --- a/src/Windows/WindowManager.php +++ b/src/Windows/WindowManager.php @@ -31,6 +31,13 @@ public function hide($id = null) ]); } + public function show($id = null) + { + $this->client->post('window/show', [ + 'id' => $id ?? $this->detectId(), + ]); + } + public function current(): Window { $window = (object) $this->client->get('window/current')->json(); diff --git a/tests/Fakes/FakeWindowManagerTest.php b/tests/Fakes/FakeWindowManagerTest.php index b2f4af25..f6c4804c 100644 --- a/tests/Fakes/FakeWindowManagerTest.php +++ b/tests/Fakes/FakeWindowManagerTest.php @@ -136,6 +136,24 @@ $this->fail('Expected assertion to fail'); }); +it('asserts that a window was shown', function () { + swap(WindowManagerContract::class, $fake = app(WindowManagerFake::class)); + + app(WindowManagerContract::class)->show('main'); + app(WindowManagerContract::class)->show('secondary'); + + $fake->assertShown('main'); + $fake->assertShown('secondary'); + + try { + $fake->assertShown('tertiary'); + } catch (AssertionFailedError) { + return; + } + + $this->fail('Expected assertion to fail'); +}); + it('asserts opened count', function () { Http::fake(['*' => Http::response(status: 200)]); @@ -196,6 +214,24 @@ $this->fail('Expected assertion to fail'); }); +it('asserts shown count', function () { + swap(WindowManagerContract::class, $fake = app(WindowManagerFake::class)); + + app(WindowManagerContract::class)->show('main'); + app(WindowManagerContract::class)->show(); + app(WindowManagerContract::class)->show(); + + $fake->assertShownCount(3); + + try { + $fake->assertShownCount(4); + } catch (AssertionFailedError) { + return; + } + + $this->fail('Expected assertion to fail'); +}); + it('forces the return value of current window', function () { swap(WindowManagerContract::class, $fake = app(WindowManagerFake::class));