Skip to content

Commit

Permalink
IBX-6330: [Behat] Cover "My Drafts" Page (#878)
Browse files Browse the repository at this point in the history
* Initial implementation

* FInished the task of testing draft deletion

* Added the test for the edition of draft, splited the tests into 2 versions.

* cleanup

* Improvemtn of the edit table selector

* Fixes regarding editing draft selectors

* code style check fix

* Fixes regarding veryfiing deletion, style fixes, veryfiisloaded added

* Added fix regarding not finding delete confirmation, naming fix

---------

Co-authored-by: Marek Nocoń <mnocon@users.noreply.github.com>
(cherry picked from commit b0e1549)
  • Loading branch information
jwibexa committed Aug 30, 2023
1 parent 50ccad7 commit aa8d42c
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 1 deletion.
2 changes: 2 additions & 0 deletions behat_suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ browser:
- Ibexa\AdminUi\Behat\BrowserContext\ContentViewContext
- Ibexa\AdminUi\Behat\BrowserContext\DashboardContext
- Ibexa\AdminUi\Behat\BrowserContext\LanguageContext
- Ibexa\AdminUi\Behat\BrowserContext\MyDraftsContext
- Ibexa\AdminUi\Behat\BrowserContext\NavigationContext
- Ibexa\AdminUi\Behat\BrowserContext\NotificationContext
- Ibexa\AdminUi\Behat\BrowserContext\ObjectStatesContext
Expand Down Expand Up @@ -78,6 +79,7 @@ browser:
- Ibexa\AdminUi\Behat\BrowserContext\ContentViewContext
- Ibexa\AdminUi\Behat\BrowserContext\DashboardContext
- Ibexa\AdminUi\Behat\BrowserContext\LanguageContext
- Ibexa\AdminUi\Behat\BrowserContext\MyDraftsContext
- Ibexa\AdminUi\Behat\BrowserContext\NavigationContext
- Ibexa\AdminUi\Behat\BrowserContext\NotificationContext
- Ibexa\AdminUi\Behat\BrowserContext\ObjectStatesContext
Expand Down
26 changes: 26 additions & 0 deletions features/standard/MyDrafts.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@IbexaOSS @IbexaHeadless @IbexaExperience @IbexaCommerce @javascript
Feature: My Drafts

Scenario: It is possible to delete a draft
Given I create "article" Content drafts
| title | short_title | parentPath | language |
| TestMyDraft | TestMyDraft | root | eng-GB |
And I am logged as admin
And I open "MyDrafts" page in admin SiteAccess
When I delete the draft "TestMyDraft" from my draft lists
Then I see the draft "TestMyDraft" is deleted

Scenario: It is possible to edit a draft
Given I create "article" Content drafts
| title | short_title | parentPath | language |
| TestMyDraft | TestMyDraft | root | eng-GB |
And I am logged as admin
And I open "MyDrafts" page in admin SiteAccess
When I edit "TestMyDraft" on MyDrafts page
And I set content fields
| label | value |
| Title | TestMyDraftSavePublish |
| Short title | TestMyDraftSavePublish |
| Intro | TestMyDraftIntro |
And I click on the edit action bar button "Save"
Then I should be on Content update page for "TestMyDraftSavePublish"
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ services:
Ibexa\AdminUi\Behat\BrowserContext\UserPreferencesContext: ~

Ibexa\AdminUi\Behat\BrowserContext\BookmarkContext: ~

Ibexa\AdminUi\Behat\BrowserContext\MyDraftsContext: ~
2 changes: 1 addition & 1 deletion src/bundle/Resources/config/services/test/pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ services:

Ibexa\AdminUi\Behat\Page\ChangePasswordPage: ~

Ibexa\AdminUi\Behat\Page\UserSettingsPage: ~
Ibexa\AdminUi\Behat\Page\MyDraftsPage: ~

Ibexa\AdminUi\Behat\Page\BookmarksPage: ~

Expand Down
45 changes: 45 additions & 0 deletions src/lib/Behat/BrowserContext/MyDraftsContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace Ibexa\AdminUi\Behat\BrowserContext;

use Behat\Behat\Context\Context;
use Ibexa\AdminUi\Behat\Page\MyDraftsPage;
use PHPUnit\Framework\Assert;

final class MyDraftsContext implements Context
{
private MyDraftsPage $myDraftsPage;

public function __construct(MyDraftsPage $myDraftsPage)
{
$this->myDraftsPage = $myDraftsPage;
}

/**
* @Given I delete the draft :draftName from my draft lists
*/
public function iDeleteADraftFromTheList(string $draftName): void
{
$this->myDraftsPage->deleteDraft($draftName);
}

/**
* @Given I see the draft :draftName is deleted
*/
public function iSeeTheDraftIsDeleted(string $draftName): void
{
Assert::assertFalse($this->myDraftsPage->isDraftOnTheList($draftName));
}

/**
* @Given I edit :draftName on MyDrafts page
*/
public function iEditDraft(string $draftName): void
{
$this->myDraftsPage->edit($draftName);
}
}
72 changes: 72 additions & 0 deletions src/lib/Behat/Page/MyDraftsPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace Ibexa\AdminUi\Behat\Page;

use Behat\Mink\Session;
use Ibexa\AdminUi\Behat\Component\Dialog;
use Ibexa\AdminUi\Behat\Component\Table\TableBuilder;
use Ibexa\AdminUi\Behat\Component\Table\TableInterface;
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;
use Ibexa\Behat\Browser\Page\Page;
use Ibexa\Behat\Browser\Routing\Router;

final class MyDraftsPage extends Page
{
private TableInterface $table;

private Dialog $dialog;

public function __construct(Session $session, Router $router, TableBuilder $tableBuilder, Dialog $dialog)
{
parent::__construct($session, $router);
$this->table = $tableBuilder->newTable()->build();
$this->dialog = $dialog;
}

public function verifyIsLoaded(): void
{
$this->getHTMLPage()
->find($this->getLocator('pageTitle'))
->assert()->textEquals('Drafts');
}

public function deleteDraft(string $draftName): void
{
$this->table->getTableRow(['Name' => $draftName])->select();
$this->getHTMLPage()->find($this->getLocator('deleteButton'))->click();
$this->dialog->verifyIsLoaded();
$this->dialog->confirm();
}

public function isDraftOnTheList(string $draftName): bool
{
return $this->table->hasElement(['Name' => $draftName]);
}

public function edit(string $draftName): void
{
$this->table->getTableRow(['Name' => $draftName])->edit();
}

protected function specifyLocators(): array
{
return [
new VisibleCSSLocator('deleteButton', '#confirm-content_remove_remove'),
new VisibleCSSLocator('pageTitle', '.ibexa-page-title h1'),
];
}

public function getName(): string
{
return 'MyDrafts';
}

protected function getRoute(): string
{
return 'contentdraft/list';
}
}

0 comments on commit aa8d42c

Please sign in to comment.