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 Dusk tests for Queries tab #1687

Merged
merged 2 commits into from
Oct 10, 2024
Merged
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
60 changes: 60 additions & 0 deletions tests/DebugbarBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Routing\Router;
use Laravel\Dusk\Browser;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Database\Connection;

class DebugbarBrowserTest extends BrowserTestCase
{
Expand Down Expand Up @@ -65,6 +67,26 @@ protected function addWebRoutes(Router $router)
return view('ajax');
}
]);

$router->get('web/query', [
'uses' => function () {
debugbar()->boot();

/** @var Connection $connection */
$connection = $this->app['db']->connectUsing(
'runtime-connection',
[
'driver' => 'sqlite',
'database' => ':memory:',
],
);

$executedQuery = new QueryExecuted('SELECT * FROM users WHERE username = ?', ['debuguser'], 0, $connection);
event($executedQuery);

return 'PONG';
}
]);
}

/**
Expand Down Expand Up @@ -138,4 +160,42 @@ public function testItCapturesAjaxRequests()
->assertSee('GET api/ping');
});
}

public function testDatabaseTabIsClickable()
{
$this->browse(function (Browser $browser) {
$browser->visit('web/plain')
->waitFor('.phpdebugbar')
->assertDontSee('0 statements were executed')
->click('.phpdebugbar-tab[data-collector="queries"]')
->assertSee('0 statements were executed');
});
}

public function testDatabaseCollectsQueries()
{
if (version_compare($this->app->version(), '10', '<')) {
$this->markTestSkipped('This test is not compatible with Laravel 9.x and below');
}

$this->browse(function (Browser $browser) {
$browser->visit('web/query')
->waitFor('.phpdebugbar')
->click('.phpdebugbar-tab-history')
->assertSeeIn('.phpdebugbar-tab[data-collector="queries"] .phpdebugbar-badge', 2)
->click('.phpdebugbar-tab[data-collector="queries"]')
->screenshotElement('.phpdebugbar', 'queries-tab')
->waitForText('executed')
->assertSee('1 statement was executed')
->with('.phpdebugbar-widgets-sqlqueries', function ($queriesPane) {
$queriesPane->assertSee('SELECT * FROM users')
->click('.phpdebugbar-widgets-expandable:nth-child(2)')
->assertSee('Bindings')
->assertSee('debuguser')
->assertSee('Backtrace')
->assertSee('LaravelDebugbar.php:');
})
->screenshotElement('.phpdebugbar', 'queries-expanded');
});
}
}
Loading