Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add component() method to get scoped Browser instance #1087

Merged
merged 9 commits into from
Feb 23, 2024

Conversation

ziadoz
Copy link
Contributor

@ziadoz ziadoz commented Feb 23, 2024

This PR adds a new component() method that returns a browser instance scoped to a component. It works identically to with(), only it doesn't require a closure, which can be more readable with many components on a page:

// Before
$browser->with(new DatePickerComponent, function ($browser) {
    $browser->typeDate('2021-02-03 04:05:06');
});

$browser->with(new PrimaryCategoryPickerComponent, function ($browser) {
    $browser->typeReference('FOO-123');
    $browser->assertPickerSelected('FOO-123');
});

$browser->with(new SecondaryCategoryPickerComponent, function ($browser) {
    $browser->typeReference('FOO-456');
    $browser->assertPickerSelected('FOO-456');
});

// After
$datePicker = $browser->component(new DatePickerComponent);
$datePicker->typeDate('2021-02-03 04:05:06');

$primaryCategoryPicker = $browser->component(new PrimaryCategoryPickerComponent);
$primaryCategoryPicker->typeReference('FOO-123');
$primaryCategoryPicker->assertPickerSelected('FOO-123');

$secondaryCategoryPicker = $browser->component(new SecondaryCategoryPickerComponent);
$secondaryCategoryPicker->typeReference('FOO-456');
$secondaryCategoryPicker->assertPickerSelected('FOO-456');

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@crynobone
Copy link
Member

$browser->with(new DatePickerComponent, function ($browser) {
    $browser->typeDate('2021-02-03 04:05:06');
})->with(new PrimaryCategoryPickerComponent, function ($browser) {
    $browser->typeReference('FOO-123');
    $browser->assertPickerSelected('FOO-123');
})->with(new SecondaryCategoryPickerComponent, function ($browser) {
    $browser->typeReference('FOO-456');
    $browser->assertPickerSelected('FOO-456');
});

Will this usage still be valid after this PR?

@ziadoz
Copy link
Contributor Author

ziadoz commented Feb 23, 2024

@crynobone Yes chaining like that should still work, and I've added a test for it.

@ziadoz ziadoz marked this pull request as ready for review February 23, 2024 16:36
@taylorotwell taylorotwell merged commit dce7c4c into laravel:7.x Feb 23, 2024
22 checks passed
@ziadoz ziadoz deleted the component-proxy branch March 4, 2024 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants