Skip to content

Commit

Permalink
feat: UI test of team with environment locking to prevent collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
KminekMatej committed Dec 7, 2024
1 parent 748a16c commit 0135efb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
45 changes: 33 additions & 12 deletions app/module/autotest/app/user/TeamUiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,57 @@

namespace Tymy\Module\Autotest\Team;

use Nette;
use Tester\Assert;
use Tester\DomQuery;
use Tester\Environment;
use Tymy\Bootstrap;
use Tymy\Module\Autotest\UITest;

use function count;
use const ROOT_DIR;

require getenv("ROOT_DIR") . '/app/Bootstrap.php';
$container = Bootstrap::boot();

class TeamUiTest extends UITest
{
public function testPlayers()
public function getAllStatuses()
{
return [
"players" => ["players", "Hráči", 2],
"members" => ["members", "Členové", 1],
"inits" => ["inits", "Registrovaní", 1],
"sicks" => ["sicks", "Marodi", 1],
];
}

/**
* @dataProvider getAllStatuses
*/
public function testPlayers(string $action, string $caption, int $expectedCount)
{
Environment::lock('users', ROOT_DIR . "/temp");
$this->authorizeUser();
$dom = parent::getDomForAction('players');
$dom = parent::getDomForAction($action);

//has navbar
Assert::true($dom->has('div#snippet-navbar-nav'));

$this->assertBreadcrumb($dom, 0, "Hlavní stránka", true);
$this->assertBreadcrumb($dom, 1, "Hráči", false);
$this->assertBreadcrumb($dom, 1, $caption, false);

Assert::true($dom->has('div.container-fluid.users'));
parent::assertDomHas($dom, 'div.container-fluid.users div.row#snippet--userList div.col-md-3.my-2 div.card.sh-box', expectedCount: $expectedCount);
}

public function testAll()
{
Environment::lock('users', ROOT_DIR . "/temp");
$this->authorizeUser();
$dom = parent::getDomForAction();

Assert::true($dom->has('div.container div.row div.col ol.breadcrumb'));
Assert::equal(count($dom->find('ol.breadcrumb li.breadcrumb-item a[href]')), 2);
Assert::equal(count($dom->find('ol.breadcrumb li.breadcrumb-item')), 3);
Assert::true($dom->has('div#snippet-navbar-nav'));
$this->assertBreadcrumb($dom, 0, "Hlavní stránka", true);
$this->assertBreadcrumb($dom, 1, "Všichni", false);

Assert::true($dom->has('div.container-fluid.users'));
parent::assertDomHas($dom, 'div.container-fluid.users div.row#snippet--userList div.col-md-3.my-2 div.card.sh-box', expectedCount: 14);
parent::assertDomHas($dom, 'div.container-fluid.users div.row#snippet--userList div.col-md-3.my-2 div.card.sh-box', expectedCount: 5);
}

protected function getPresenter(): string
Expand Down
6 changes: 6 additions & 0 deletions app/module/autotest/app/user/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
namespace Tymy\Module\Autotest\User;

use Nette\Security\AuthenticationException;
use Tester\Environment;
use Tymy\Bootstrap;
use Tymy\Module\Autotest\ApiTest;
use Tymy\Module\Autotest\Entity\Assert;
use Tymy\Module\User\Model\User;
use Vojir\Responses\CsvResponse\ComposedCsvResponse;

use const ROOT_DIR;

require getenv("ROOT_DIR") . '/app/Bootstrap.php';
$container = Bootstrap::boot();

Expand Down Expand Up @@ -105,6 +108,7 @@ public function testStatus(): void

public function testCRUD(): void
{
Environment::lock('users', ROOT_DIR . "/temp");
$recordId = $this->createRecord()["id"];

$this->request($this->getBasePath() . "/" . $recordId)->expect(200, "array");
Expand Down Expand Up @@ -262,6 +266,7 @@ public function testRegisterFailure(): void

public function testUpdateFailures(): void
{
Environment::lock('users', ROOT_DIR . "/temp");
$this->authorizeAdmin();
$adminData = $this->request($this->getBasePath() . "/1", "PUT", ["roles" => ["USR"]])->expect(200)->getData();
Assert::contains("SUPER", $adminData["roles"]);
Expand All @@ -286,6 +291,7 @@ public function testUpdateFailures(): void

public function testAvatar(): void
{
Environment::lock('users', ROOT_DIR . "/temp");
$this->authorizeUser();
$myId = $this->config["user_test_id"];
$this->request(
Expand Down

0 comments on commit 0135efb

Please sign in to comment.