Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Add action collectors to scoped component browser instances #51

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
23 changes: 23 additions & 0 deletions src/Dusk/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace BeyondCode\DuskDashboard\Dusk;

use Closure;
use BeyondCode\DuskDashboard\BrowserActionCollector;

class Browser extends \Laravel\Dusk\Browser
Expand Down Expand Up @@ -61,6 +62,28 @@ public function refresh()
return $browser;
}

/** {@inheritdoc} */
public function with($selector, Closure $callback)
{
$action_collector_callback = function ($browser) use ($callback) {
$browser->setActionCollector($this->getActionCollector());

return $callback($browser);
};

return parent::with($selector, $action_collector_callback);
}

/** {@inheritdoc} */
public function onComponent($component, $parentResolver)
{
if ($this->getActionCollector() === null) {
$this->setActionCollector(new BrowserActionCollector('dog'));
}

parent::onComponent($component, $parentResolver);
}

public function getCurrentPageSource()
{
$this->ensurejQueryIsAvailable();
Expand Down