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
27 changes: 27 additions & 0 deletions src/Server/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,33 @@ public function assertSee(array|string $text): static
return $this;
}

/**
* @param array<string>|string $text
*/
public function assertDontSee(array|string $text): static
{
$seeable = collect([
...$this->content(),
...$this->errors(),
])->filter()->unique()->values()->all();

foreach (is_array($text) ? $text : [$text] as $segment) {
foreach ($seeable as $message) {
if (str_contains($message, $segment)) {
// @phpstan-ignore-next-line
Assert::assertTrue(false, "The unexpected text [{$segment}] was found in the response content.");

return $this;
}
}
}

// @phpstan-ignore-next-line
Assert::assertTrue(true);

return $this;
}

public function assertNotificationCount(int $count): static
{
Assert::assertCount($count, $this->notifications, "The expected number of notifications [{$count}] does not match the actual count.");
Expand Down
21 changes: 17 additions & 4 deletions tests/Feature/Testing/Prompts/AssertSeeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,26 @@ public function shouldRegister(Request $request): bool
it('may assert that text is seen when returning string content', function (): void {
$response = HotelP::prompt(BookingPrompt::class);

$response->assertSee('Your booking is confirmed!');
$response->assertSee('Your booking is confirmed!')
->assertDontSee('The booking date cannot be in the past.')
->assertDontSee('Please select a more reasonable date.');
});

it('may assert that text is seen when providing arguments', function (): void {
$response = HotelP::prompt(BookingPrompt::class, ['date' => now()->addDay()->toDateString()]);

$response->assertSee('Your booking is confirmed!');
$response->assertSee('Your booking is confirmed!')
->assertDontSee('The booking date cannot be in the past.')
->assertDontSee('Please select a more reasonable date.');
});

it('may assert that text is seen when providing arguments that are wrong', function (): void {
$response = HotelP::prompt(BookingPrompt::class, ['date' => now()->subDay()->toDateString()]);

$response
->assertSee('The booking date cannot be in the past.');
->assertSee('The booking date cannot be in the past.')
->assertDontSee('Your booking is confirmed!')
->assertDontSee('Please select a more reasonable date.');
});

it('fails to assert that text is seen when not present', function (): void {
Expand All @@ -64,12 +70,19 @@ public function shouldRegister(Request $request): bool
$response->assertSee('This text is not present');
})->throws(ExpectationFailedException::class);

it('fails to assert that text is not seen when it is present', function (): void {
$response = HotelP::prompt(BookingPrompt::class);

$response->assertDontSee('Your booking is confirmed!');
})->throws(ExpectationFailedException::class);

it('may assert that text is seen when returning array content', function (): void {
$response = HotelP::prompt(BookingPrompt::class, ['date' => '2999-01-01']);

$response
->assertSee('That date is too far in the future')
->assertSee('Please select a more reasonable date.');
->assertSee('Please select a more reasonable date.')
->assertDontSee('Your booking is confirmed!');
});

it('fails if the prompt is not registered', function (): void {
Expand Down
18 changes: 15 additions & 3 deletions tests/Feature/Testing/Resources/AssertSeeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,26 @@ public function shouldRegister(Request $request): bool
it('may assert that text is seen when returning string content', function (): void {
$response = HotelR::resource(BookingResource::class);

$response->assertSee('Your booking is confirmed!');
$response->assertSee('Your booking is confirmed!')
->assertDontSee('The booking date cannot be in the past.')
->assertDontSee('Please select a more reasonable date.');
});

it('may assert that text is seen when providing arguments', function (): void {
$response = HotelR::resource(BookingResource::class, ['date' => now()->addDay()->toDateString()]);

$response->assertSee('Your booking is confirmed!');
$response->assertSee('Your booking is confirmed!')
->assertDontSee('The booking date cannot be in the past.')
->assertDontSee('Please select a more reasonable date.');
});

it('may assert that text is seen when providing arguments that are wrong', function (): void {
$response = HotelR::resource(BookingResource::class, ['date' => now()->subDay()->toDateString()]);

$response
->assertSee('The booking date cannot be in the past.');
->assertSee('The booking date cannot be in the past.')
->assertDontSee('Your booking is confirmed!')
->assertDontSee('Please select a more reasonable date.');
});

it('fails to assert that text is seen when not present', function (): void {
Expand All @@ -64,6 +70,12 @@ public function shouldRegister(Request $request): bool
$response->assertSee('This text is not present');
})->throws(ExpectationFailedException::class);

it('fails to assert that text is not seen when it is present', function (): void {
$response = HotelR::resource(BookingResource::class);

$response->assertDontSee('Your booking is confirmed!');
})->throws(ExpectationFailedException::class);

it('may assert that text is seen when returning array content', function (): void {
$response = HotelR::resource(BookingResource::class, ['date' => '2999-01-01']);

Expand Down
18 changes: 15 additions & 3 deletions tests/Feature/Testing/Tools/AssertSeeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,26 @@ public function shouldRegister(Request $request): bool
it('may assert that text is seen when returning string content', function (): void {
$response = HotelT::tool(BookingTool::class);

$response->assertSee('Your booking is confirmed!');
$response->assertSee('Your booking is confirmed!')
->assertDontSee('The booking date cannot be in the past.')
->assertDontSee('Please select a more reasonable date.');
});

it('may assert that text is seen when providing arguments', function (): void {
$response = HotelT::tool(BookingTool::class, ['date' => now()->addDay()->toDateString()]);

$response->assertSee('Your booking is confirmed!');
$response->assertSee('Your booking is confirmed!')
->assertDontSee('The booking date cannot be in the past.')
->assertDontSee('Please select a more reasonable date.');
});

it('may assert that text is seen when providing arguments that are wrong', function (): void {
$response = HotelT::tool(BookingTool::class, ['date' => now()->subDay()->toDateString()]);

$response
->assertSee('The booking date cannot be in the past.');
->assertSee('The booking date cannot be in the past.')
->assertDontSee('Your booking is confirmed!')
->assertDontSee('Please select a more reasonable date.');
});

it('fails to assert that text is seen when not present', function (): void {
Expand All @@ -64,6 +70,12 @@ public function shouldRegister(Request $request): bool
$response->assertSee('This text is not present');
})->throws(ExpectationFailedException::class);

it('fails to assert that text is not seen when it is present', function (): void {
$response = HotelT::tool(BookingTool::class);

$response->assertDontSee('Your booking is confirmed!');
})->throws(ExpectationFailedException::class);

it('may assert that text is seen when returning array content', function (): void {
$response = HotelT::tool(BookingTool::class, ['date' => '2999-01-01']);

Expand Down
Loading