-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from clemblanco/click-poc
feat: PoC for clicking a link + asserting new URL
- Loading branch information
Showing
9 changed files
with
188 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ node_modules/ | |
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ | ||
.temp/e2e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pest\Browser\Operations; | ||
|
||
use Pest\Browser\Contracts\Operation; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class AssertUrlIs implements Operation | ||
{ | ||
/** | ||
* Creates an operation instance. | ||
*/ | ||
public function __construct( | ||
private string $url, | ||
) { | ||
// | ||
} | ||
|
||
public function compile(): string | ||
{ | ||
return sprintf("await expect(page.url()).toBe('%s');", $this->url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pest\Browser\Operations; | ||
|
||
use Pest\Browser\Contracts\Operation; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class ClickLink implements Operation | ||
{ | ||
/** | ||
* Creates an operation instance. | ||
*/ | ||
public function __construct( | ||
private string $text, | ||
) { | ||
// | ||
} | ||
|
||
public function compile(): string | ||
{ | ||
return sprintf("await page.locator('a').filter({ hasText: /%s/i }).click();", $this->text); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pest\Browser\ValueObjects; | ||
|
||
use Pest\Support\Arr; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class TestResultResponse | ||
{ | ||
private array $headers; | ||
|
||
private int $status; | ||
|
||
private string $url; | ||
|
||
/** | ||
* The test result response. | ||
*/ | ||
public function __construct(array $annotations) | ||
{ | ||
/** @todo would be cleaner with collect() and Str facade */ | ||
$annotation = Arr::last(array_filter($annotations, function ($annotation) { | ||
return Arr::get($annotation, 'type') === '_response'; | ||
})); | ||
|
||
[ | ||
'headers' => $this->headers, | ||
'status' => $this->status, | ||
'url' => $this->url | ||
] = json_decode(Arr::get($annotation, 'description'), true); | ||
} | ||
|
||
/** | ||
* Get the test result response headers. | ||
*/ | ||
public function headers(): array | ||
{ | ||
return $this->headers; | ||
} | ||
|
||
/** | ||
* Get the test result response status. | ||
*/ | ||
public function status(): int | ||
{ | ||
return $this->status; | ||
} | ||
|
||
/** | ||
* Get the test result response url. | ||
*/ | ||
public function url(): string | ||
{ | ||
return $this->url; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters