Skip to content

Commit

Permalink
Merge ae6c8e9 into 4d63425
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakorgaur committed Jun 25, 2021
2 parents 4d63425 + ae6c8e9 commit 1c8a2fd
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 15 deletions.
20 changes: 12 additions & 8 deletions tests/_support/Page/ticket/Create.php
Expand Up @@ -14,34 +14,38 @@
*/
class Create extends Authenticated
{
public function createTicket($subject, $message, $topic)
public function createTicket(array $ticket): string
{
$I = $this->tester;

$I->amOnPage(Url::to(['@ticket/create']));

(new Select2($I, '#thread-topics'))->setValue($topic);
(new Select2($I, '#thread-topics'))->setValue($ticket['topic']);

(new Input($I, '#thread-subject'))->setValue($subject);
(new Input($I, '#thread-message'))->setValue($message);
(new Input($I, '#thread-subject'))->setValue($ticket['subject']);
(new Input($I, '#thread-message'))->setValue($ticket['message']);

$this->seePreviewWorks($message);
if (isset($ticket['recipient'])) {
(new Select2($I, '#thread-recipient_id'))->setValue($ticket['recipient']);
}

$this->seePreviewWorks($ticket['message']);

$I->click('Create ticket', '#create-thread-form');
$this->seeTicketWasCreated($message, $topic);
$this->seeTicketWasCreated($ticket['message'], $ticket['topic']);

return $I->grabValueFrom(View::THREAD_ID_SELECTOR);
}

protected function seePreviewWorks($message)
protected function seePreviewWorks($message): void
{
$I = $this->tester;

$I->click('a[href="#preview-create-thread-form"]');
$I->waitForText($message, 30, '#preview-create-thread-form');
}

protected function seeTicketWasCreated($message, $topic)
protected function seeTicketWasCreated($message, $topic): void
{
$I = $this->tester;

Expand Down
62 changes: 62 additions & 0 deletions tests/acceptance/admin/TicketCreationCest.php
@@ -0,0 +1,62 @@
<?php

namespace hipanel\modules\ticket\tests\acceptance\Seller;

use hipanel\helpers\Url;
use Codeception\Example;
use hipanel\tests\_support\Step\Acceptance\Admin;
use hipanel\modules\ticket\tests\_support\Page\ticket\Create;
use hipanel\modules\ticket\tests\_support\Page\ticket\Index;
use hipanel\modules\ticket\tests\_support\Page\ticket\View;

class TicketCreationCest
{
private string $ticketId;

/**
* @dataProvider provideTicketData
*/
public function ensureICanCreateTicket(Admin $I, Example $example): void
{
$I->login();

$this->ticketId = $this->createTicket($I, $example);
$this->ensureISeeCreatedTicketOnIndexPage($I);
$this->ensureICanCommentTicket($I);
}

private function createTicket(Admin $I, Example $exampleTicket): ?string
{
$createPage = new Create($I);

$exampleArray = iterator_to_array($exampleTicket->getIterator());
return $createPage->createTicket($exampleArray);
}

private function ensureISeeCreatedTicketOnIndexPage(Admin $I): void
{
$index = new Index($I);

$index->hasLinkToTicket($this->ticketId);
}

private function ensureICanCommentTicket(Admin $I): void
{
$view = new View($I, $this->ticketId);

$view->visitTicket();
$view->postComment('This is a test comment. Ignore it, please.');
}

private function provideTicketData(): array
{
return [
'ticket' => [
'subject' => uniqid(),
'message' => 'someone abuses uniqid ' . uniqid(),
'topic' => 'Abuse',
'recipient' => 'hipanel_test_admin',
],
];
}
}
27 changes: 20 additions & 7 deletions tests/acceptance/client/TicketCest.php
Expand Up @@ -4,6 +4,7 @@

use Codeception\Scenario;
use hipanel\helpers\Url;
use Codeception\Example;
use hipanel\modules\ticket\tests\_support\Page\ticket\Create;
use hipanel\modules\ticket\tests\_support\Page\ticket\Index;
use hipanel\modules\ticket\tests\_support\Page\ticket\View;
Expand Down Expand Up @@ -67,13 +68,13 @@ public function ensureICanNavigateToCreateTicketPage(Client $I): void
(new Index($I))->ensureThatICanNavigateToCreateTicketPage();
}

public function ensureICanCreateTicket(Client $I): void
/**
* @dataProvider provideDataTicket
*/
public function ensureICanCreateTicket(Client $I, Example $example): void
{
$this->ticket_id = (new Create($I))->createTicket(
'Test ticket (' . date('Y-m-d H:i') . ')',
'This is a test ticket created by automated testing system. Ignore it, please.',
'VDS'
);
$ticketData = iterator_to_array($example->getIterator());
$this->ticket_id = (new Create($I))->createTicket($ticketData);
}

public function ensureISeeCreatedTicketOnIndexPage(Client $I, Scenario $scenario): void
Expand All @@ -86,7 +87,7 @@ public function ensureISeeCreatedTicketOnIndexPage(Client $I, Scenario $scenario
$index->hasLinkToTicket($this->ticket_id);
}

public function ensureICanCommentTicket(Client $I, Scenario $scenario)
public function ensureICanCommentTicket(Client $I, Scenario $scenario): void
{
if (!isset($this->ticket_id)) {
$scenario->incomplete('Ticket ID must be filled to run this test');
Expand Down Expand Up @@ -115,4 +116,16 @@ public function ensureICanChangeTicketState(Client $I, Scenario $scenario): void
$view->openTicket();
$view->closeTicket();
}

protected function provideDataTicket(): array
{
return [
'ticket' => [
'subject' => 'Test ticket (' . date('Y-m-d H:i') . ')',
'message' => 'This is a test ticket created by automated testing system. Ignore it, please.',
'topic' => 'VDS',
'recipient' => null,
],
];
}
}

0 comments on commit 1c8a2fd

Please sign in to comment.