test(backoffice): add base functional tests

test creation of a navigation
test creation of a menu
test creation of a page
This commit is contained in:
Simon Vieille 2023-01-09 22:25:39 +01:00
parent 5dbcc51309
commit dd3630237c
Signed by: deblan
GPG key ID: 579388D585F70417
4 changed files with 151 additions and 0 deletions

View file

@ -0,0 +1,50 @@
<?php
namespace App\Tests\Core;
use App\Repository\UserRepositoryQuery;
use Symfony\Component\Panther\Client as PantherClient;
use Symfony\Component\Panther\PantherTestCase as BasePantherTestCase;
abstract class PantherTestCase extends BasePantherTestCase
{
protected UserRepositoryQuery $query;
protected PantherClient $client;
protected function container()
{
if (null === self::$container) {
static::bootKernel();
}
return self::$container;
}
protected function setUp(): void
{
$this->client = static::createPantherClient([
'external_base_uri' => 'http://localhost:9080'
]);
$this->query = $this->container()->get(UserRepositoryQuery::class);
}
protected function authenticateAdmin(): void
{
$this->client->request('GET', '/login');
$this->client->submitForm('Login', [
'_username' => 'admin@localhost',
'_password' => 'admin_password',
]);
$this->client->waitFor('.nav-item-label');
}
protected function authenticateWriter(): void
{
$this->client->request('GET', '/login');
$this->client->submitForm('Login', [
'_username' => 'writer@localhost',
'_password' => 'writer_password',
]);
$this->client->waitFor('.nav-item-label');
}
}

View file

@ -0,0 +1,39 @@
<?php
namespace App\Tests\Core\Site;
use App\Tests\Core\PantherTestCase;
/**
* @internal
* @coversNothing
*/
class NavigationTest extends PantherTestCase
{
public function testCreateNavigation(): void
{
$this->authenticateAdmin();
$this->client->request('GET', '/admin/site/tree');
$this->client->waitFor('.toast-body.text-text-warning');
$this->assertSelectorTextContains('.toast-body.text-text-warning', 'You must add a navigation.');
$this->client->request('GET', '/admin/site/navigation');
$this->assertSelectorTextContains('h1', 'Navigations');
$this->client->request('GET', '/admin/site/navigation/new');
$this->assertSelectorTextContains('h1', 'New navigation');
$this->client->submitForm('Save', [
'navigation[label]' => 'Test navigation',
'navigation[locale]' => 'en',
'navigation[code]' => 'nav',
'navigation[domain]' => 'localhost',
]);
$this->client->waitFor('.toast-body.text-text-success');
$this->assertSelectorTextContains('.toast-body.text-text-success', 'The data has been saved.');
$this->client->request('GET', '/admin/site/navigation');
$this->assertSelectorTextContains('.table tbody tr td', 'Test navigation');
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace App\Tests\Core\Site;
use App\Tests\Core\PantherTestCase;
/**
* @internal
* @coversNothing
*/
class PageTest extends PantherTestCase
{
public function testCreatePage(): void
{
$this->client->request('GET', '/admin/site/tree');
$this->client->executeScript("document.querySelector('#node-2 .float-right button[data-modal]').click()");
$this->client->waitFor('#form-node-edit');
$this->client->executeScript("document.querySelector('#node-page-action .card-header label').click()");
$this->client->executeScript("document.querySelector('a[href=\"#form-node-edit-routing\"]').click()");
$this->client->executeScript("document.querySelector('#node_url').value='/foo'");
$this->client->executeScript("document.querySelector('#node_code').value='/foo'");
$this->client->executeScript("document.querySelector('.modal.show .modal-footer button[type=\"submit\"]').click()");
$this->client->waitFor('.toast-body.text-text-success');
$this->assertSelectorTextContains('.toast-body.text-text-success', 'The data has been saved.');
$this->assertSelectorTextContains('#node-2 .float-right a', 'Page');
}
}

View file

@ -0,0 +1,32 @@
<?php
namespace App\Tests\Core\Site;
use App\Tests\Core\PantherTestCase;
/**
* @internal
* @coversNothing
*/
class TreeTest extends PantherTestCase
{
public function testCreateTree(): void
{
$this->client->request('GET', '/admin/site/tree');
$this->assertSelectorTextContains('button[data-toggle="modal"]', 'Add a menu');
$this->client->executeScript("document.querySelector('button[data-toggle=\"modal\"]').click()");
$this->client->waitFor('#form-menu-new');
$this->client->submitForm('Save', [
'menu[label]' => 'Test menu',
'menu[code]' => 'menu',
]);
$this->client->waitFor('.toast-body.text-text-success');
$this->assertSelectorTextContains('.toast-body.text-text-success', 'The data has been saved.');
$this->client->request('GET', '/admin/site/tree');
$this->assertSelectorTextContains('.h4', 'Test menu');
$this->assertSelectorTextContains('#node-2 .col-6', 'First element');
}
}