Skip to content

Commit

Permalink
[Behat] Adapted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mnocon committed Dec 1, 2023
1 parent c840121 commit b3623d7
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 34 deletions.
1 change: 1 addition & 0 deletions features/personas/AddLocation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Feature: Verify that an Editor with Content Type limitation on content/create po
And I log in as "Add" with password "Passw0rd-42"
And I go to "Content structure" in "Content" tab
And I navigate to content "NewArticle" of type "Article" in root
And I am using the DXP in "Expert" mode
When I switch to "Locations" tab in Content structure
And I add a new Location under "root/Destination"
Then there exists Content view Page for "root/Destination/NewArticle"
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1750,11 +1750,6 @@ parameters:
count: 1
path: src/lib/Behat/BrowserContext/ContentViewContext.php

-
message: "#^Property Ibexa\\\\AdminUi\\\\Behat\\\\BrowserContext\\\\ContentViewContext\\:\\:\\$universalDiscoveryWidget is never read, only written\\.$#"
count: 1
path: src/lib/Behat/BrowserContext/ContentViewContext.php

-
message: "#^Method Ibexa\\\\AdminUi\\\\Behat\\\\BrowserContext\\\\LanguageContext\\:\\:deleteLanguageNamed\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -3035,21 +3030,11 @@ parameters:
count: 1
path: src/lib/Behat/Page/ContentViewPage.php

-
message: "#^Property Ibexa\\\\AdminUi\\\\Behat\\\\Page\\\\ContentViewPage\\:\\:\\$contentUpdatePage is never read, only written\\.$#"
count: 1
path: src/lib/Behat/Page/ContentViewPage.php

-
message: "#^Property Ibexa\\\\AdminUi\\\\Behat\\\\Page\\\\ContentViewPage\\:\\:\\$route has no type specified\\.$#"
count: 1
path: src/lib/Behat/Page/ContentViewPage.php

-
message: "#^Property Ibexa\\\\AdminUi\\\\Behat\\\\Page\\\\ContentViewPage\\:\\:\\$userUpdatePage is never read, only written\\.$#"
count: 1
path: src/lib/Behat/Page/ContentViewPage.php

-
message: "#^Method Ibexa\\\\AdminUi\\\\Behat\\\\Page\\\\DashboardPage\\:\\:editDraft\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
17 changes: 10 additions & 7 deletions src/lib/Behat/BrowserContext/ContentViewContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,27 @@
use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\TableNode;
use Ibexa\AdminUi\Behat\Component\DraftConflictDialog;
use Ibexa\AdminUi\Behat\Component\UniversalDiscoveryWidget;
use Ibexa\AdminUi\Behat\Page\ContentViewPage;
use Ibexa\Behat\Core\Behat\ArgumentParser;
use PHPUnit\Framework\Assert;

class ContentViewContext implements Context
final class ContentViewContext implements Context
{
private $argumentParser;

/** @var \Ibexa\AdminUi\Behat\Page\ContentViewPage */
private $contentViewPage;

/** @var \Ibexa\AdminUi\Behat\Component\UniversalDiscoveryWidget */
private $universalDiscoveryWidget;

/** @var \Ibexa\AdminUi\Behat\Component\DraftConflictDialog */
private $draftConflictDialog;

public function __construct(
ArgumentParser $argumentParser,
ContentViewPage $contentViewPage,
UniversalDiscoveryWidget $universalDiscoveryWidget,
DraftConflictDialog $draftConflictDialog
) {
$this->argumentParser = $argumentParser;
$this->contentViewPage = $contentViewPage;
$this->universalDiscoveryWidget = $universalDiscoveryWidget;
$this->draftConflictDialog = $draftConflictDialog;
}

Expand All @@ -50,6 +44,15 @@ public function startCreatingContent(string $contentType, string $language = nul
$this->contentViewPage->startCreatingContent($contentType, $language);
}

/**
* @Given I am using the DXP in :mode mode
*/
public function switchToUserMode(string $mode): void
{
$this->contentViewPage->switchToUserMode($mode);
$this->contentViewPage->verifyIsLoaded();
}

/**
* @Given I switch to :tab tab in Content structure
*/
Expand Down
35 changes: 35 additions & 0 deletions src/lib/Behat/Component/UpperMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
use Ibexa\Behat\Browser\Component\Component;
use Ibexa\Behat\Browser\Element\Criterion\ElementTextCriterion;
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;
use PHPUnit\Framework\Assert;

class UpperMenu extends Component
{
private const USER_MODES = ['Smart', 'Expert'];

public function goToDashboard(): void
{
$this->getHTMLPage()->find($this->getLocator('dashboardLink'))->click();
Expand Down Expand Up @@ -44,6 +47,37 @@ public function chooseFromUserDropdown(string $option): void
$this->getHTMLPage()->findAll($this->getLocator('userSettingsItem'))->getByCriterion(new ElementTextCriterion($option))->click();
}

public function switchToUserMode(string $newMode): void
{
$this->getHTMLPage()->find($this->getLocator('userSettingsToggle'))->click();

$currentMode = explode(
' ',
$this->getHTMLPage()->find($this->getLocator('userMode'))->getText()
)[0];

if (strtolower($newMode) === strtolower($currentMode)) {
$this->getHTMLPage()->find($this->getLocator('userMode'))->click();
} else {
$this->getHTMLPage()->find($this->getLocator('userSettingsToggle'))->click();
}
}

public function getCurrentUserMode(): string
{
$this->getHTMLPage()->find($this->getLocator('userSettingsToggle'))->click();

$mode = explode(
' ',
$this->getHTMLPage()->find($this->getLocator('userMode'))->getText()
)[0];
Assert::assertContains($mode, self::USER_MODES);

$this->getHTMLPage()->find($this->getLocator('userSettingsToggle'))->click();

return $mode;
}

public function verifyIsLoaded(): void
{
$this->getHTMLPage()->find($this->getLocator('userSettingsToggle'))->assert()->isVisible();
Expand All @@ -59,6 +93,7 @@ protected function specifyLocators(): array
new VisibleCSSLocator('userSettingsItem', '.ibexa-popup-menu__item'),
new VisibleCSSLocator('searchInput', '.ibexa-main-header #search_query'),
new VisibleCSSLocator('searchButton', '.ibexa-main-header .ibexa-input-text-wrapper__action-btn--search'),
new VisibleCSSLocator('userMode', '[name="user_mode_change"] .ibexa-toggle__label'),
];
}
}
41 changes: 29 additions & 12 deletions src/lib/Behat/Page/ContentViewPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Ibexa\AdminUi\Behat\Component\SubItemsList;
use Ibexa\AdminUi\Behat\Component\TranslationDialog;
use Ibexa\AdminUi\Behat\Component\UniversalDiscoveryWidget;
use Ibexa\AdminUi\Behat\Component\UpperMenu;
use Ibexa\Behat\Browser\Element\Condition\ElementExistsCondition;
use Ibexa\Behat\Browser\Element\Criterion\ElementTextCriterion;
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;
Expand All @@ -44,9 +45,6 @@ class ContentViewPage extends Page
/** @var \Ibexa\AdminUi\Behat\Component\ContentTypePicker */
private $contentTypePicker;

/** @var ContentUpdateItemPage */
private $contentUpdatePage;

/** @var string */
private $expectedContentType;

Expand All @@ -70,9 +68,6 @@ class ContentViewPage extends Page
/** @var \Ibexa\AdminUi\Behat\Component\ContentItemAdminPreview */
private $contentItemAdminPreview;

/** @var \Ibexa\AdminUi\Behat\Page\UserUpdatePage */
private $userUpdatePage;

/** @var \Ibexa\Contracts\Core\Repository\Repository */
private $repository;

Expand All @@ -85,40 +80,39 @@ class ContentViewPage extends Page
/** @var \Ibexa\AdminUi\Behat\Component\IbexaDropdown */
private $ibexaDropdown;

private UpperMenu $upperMenu;

public function __construct(
Session $session,
Router $router,
ContentActionsMenu $contentActionsMenu,
SubItemsList $subItemList,
ContentTypePicker $contentTypePicker,
ContentUpdateItemPage $contentUpdatePage,
LanguagePicker $languagePicker,
Dialog $dialog,
TranslationDialog $translationDialog,
Repository $repository,
Breadcrumb $breadcrumb,
ContentItemAdminPreview $contentItemAdminPreview,
UserUpdatePage $userUpdatePage,
ArgumentParser $argumentParser,
UniversalDiscoveryWidget $universalDiscoveryWidget,
IbexaDropdown $ibexaDropdown
IbexaDropdown $ibexaDropdown,
UpperMenu $upperMenu
) {
parent::__construct($session, $router);

$this->contentActionsMenu = $contentActionsMenu;
$this->subItemList = $subItemList;
$this->contentTypePicker = $contentTypePicker;
$this->contentUpdatePage = $contentUpdatePage;
$this->languagePicker = $languagePicker;
$this->dialog = $dialog;
$this->translationDialog = $translationDialog;
$this->breadcrumb = $breadcrumb;
$this->contentItemAdminPreview = $contentItemAdminPreview;
$this->userUpdatePage = $userUpdatePage;
$this->repository = $repository;
$this->argumentParser = $argumentParser;
$this->universalDiscoveryWidget = $universalDiscoveryWidget;
$this->ibexaDropdown = $ibexaDropdown;
$this->upperMenu = $upperMenu;
}

public function startCreatingContent(string $contentTypeName, string $language = null)
Expand Down Expand Up @@ -188,6 +182,29 @@ public function choosePreview(string $language): void
$this->verifyIsLoaded();
}

public function switchToUserMode(string $mode): void
{
$this->upperMenu->switchToUserMode($mode);

$expertModeTab = 'Technical Details';

if (strtolower($mode) === 'expert') {
$this->getHTMLPage()
->setTimeout(3)
->findAll($this->getLocator('tab'))
->getByCriterion(new ElementTextCriterion($expertModeTab))
->assert()
->isVisible();
} else {
$this->getHTMLPage()
->setTimeout(3)
->findAll($this->getLocator('tab'))
->filterBy(new ElementTextCriterion($expertModeTab))
->assert()
->isEmpty();
}
}

public function goToSubItem(string $contentItemName): void
{
$this->switchToTab('Sub-items');
Expand Down

0 comments on commit b3623d7

Please sign in to comment.