Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UX] Allow to redirect logged-in user on any routes and add a redirection for registration page #15418

Open
wants to merge 10 commits into
base: 1.14
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Behat - Assert we have a redirection to dashboard when try to reach a…
…dmin login page
  • Loading branch information
Jibbarth committed Feb 11, 2024
commit 1d72f12748c22cd34ab640a2f52d1764c12acff7
15 changes: 15 additions & 0 deletions features/admin/redirect_when_already_logged_in.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@admin_dashboard
Feature: Redirect when already signed in
In order to be aware that I am already logged in
As an Administrator
I want to be redirected to the administration dashboard by using when accessing the login page

Background:
Given the store operates on a single channel in "United States"
And I am logged in as an administrator

@ui @no-api
Scenario: Trying to access login page as logged in administrator
When I want to log in
Then I should be redirected to the administration dashboard

15 changes: 13 additions & 2 deletions src/Sylius/Behat/Context/Ui/Admin/DashboardContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@

use Behat\Behat\Context\Context;
use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException;
use Sylius\Behat\Page\Admin\Account\LoginPageInterface;
use Sylius\Behat\Page\Admin\DashboardPageInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Webmozart\Assert\Assert;

final class DashboardContext implements Context
{
public function __construct(private DashboardPageInterface $dashboardPage)
{
public function __construct(
private DashboardPageInterface $dashboardPage,
private LoginPageInterface $loginPage
){
}

/**
Expand Down Expand Up @@ -148,4 +151,12 @@ public function iShouldNotSeeTheAdministrationDashboard(): void
{
Assert::false($this->dashboardPage->isOpen());
}

/**
* @Then I should be redirected to the administration dashboard
*/
public function iShouldBeRedirectedToMyAccountDashboard(): void
{
Assert::true($this->dashboardPage->isOpen());
}
}
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Context/Ui/Admin/LoginContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(
*/
public function iWantToLogIn()
{
$this->loginPage->open();
$this->loginPage->tryToOpen();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<service id="sylius.behat.context.ui.admin.dashboard" class="Sylius\Behat\Context\Ui\Admin\DashboardContext">
<argument type="service" id="sylius.behat.page.admin.dashboard" />
<argument type="service" id="sylius.behat.page.admin.login" />
</service>

<service id="sylius.behat.context.ui.admin.locale" class="Sylius\Behat\Context\Ui\Admin\LocaleContext">
Expand Down