Skip to content

Commit

Permalink
Merge pull request #200 from loic425/features/admin-dashboard
Browse files Browse the repository at this point in the history
Admin dashboard with initial content
  • Loading branch information
loic425 committed Jul 26, 2019
2 parents 87f06d3 + 483f74b commit e623578
Show file tree
Hide file tree
Showing 30 changed files with 514 additions and 19 deletions.
1 change: 1 addition & 0 deletions config/packages/sylius_customer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ sylius_customer:
customer:
classes:
model: App\Entity\Customer
repository: App\Repository\CustomerRepository
1 change: 1 addition & 0 deletions config/packages/sylius_fixtures.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ sylius_fixtures:
first_name: "Harry"
last_name: "Cover"
enabled: true
random: 10

oauth_client:
options:
Expand Down
6 changes: 5 additions & 1 deletion config/routes/backend.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
app_backend_dashboard:
path: /
defaults:
_controller: FrameworkBundle:Template:template
_controller: App\Controller\DashboardController:indexAction
template: 'backend/index.html.twig'

app_backend_partial:
resource: "backend/partial.yaml"
prefix: /_partial

sylius_backend_admin_user:
resource: "backend/admin_user.yaml"

Expand Down
3 changes: 3 additions & 0 deletions config/routes/backend/partial.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sylius_backend_partial_customer:
resource: partial/customer.yaml
prefix: /customers
10 changes: 10 additions & 0 deletions config/routes/backend/partial/customer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sylius_backend_partial_customer_latest:
path: /latest/{count}
methods: [GET]
defaults:
_controller: sylius.controller.customer::indexAction
_sylius:
repository:
method: findLatest
arguments: ['!!int $count']
template: $template
33 changes: 22 additions & 11 deletions config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
imports:
- { resource: services/command.yaml }
- { resource: services/context.yaml }
- { resource: services/fixtures.yaml }
- { resource: services/fixtures_factories.yaml }
- { resource: services/form.yaml }
- { resource: services/installer.yaml }
- { resource: services/listener.yaml }
- { resource: services/menu.yaml }
- { resource: services/validator.yaml }

parameters:
email_contact: contact@app_name.com
email_name: Contact AppName
Expand All @@ -8,6 +19,17 @@ services:
_defaults:
autoconfigure: true

# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
autowire: true
tags: ['controller.service_arguments']

App\Dashboard\:
resource: '../src/Dashboard'
autowire: true

sylius.controller.security:
class: Sylius\Bundle\UiBundle\Controller\SecurityController
public: true
Expand All @@ -20,14 +42,3 @@ services:

Sylius\Component\User\Canonicalizer\CanonicalizerInterface: '@sylius.canonicalizer'
Sylius\Component\User\Security\Generator\GeneratorInterface: '@sylius.app_user.token_generator.email_verification'

imports:
- { resource: services/command.yaml }
- { resource: services/context.yaml }
- { resource: services/fixtures.yaml }
- { resource: services/fixtures_factories.yaml }
- { resource: services/form.yaml }
- { resource: services/installer.yaml }
- { resource: services/listener.yaml }
- { resource: services/menu.yaml }
- { resource: services/validator.yaml }
20 changes: 20 additions & 0 deletions features/admin/dashboard.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@admin_dashboard
Feature: Statistics dashboard
In order to have an overview of my database
As an Administrator
I want to see overall statistics on my admin dashboard

Background:
Given I am logged in as an administrator

@ui
Scenario: Seeing statistics
Given there are 9 customers
When I open administration dashboard
Then I should see 9 new customers

@ui
Scenario: Seeing recent customers
Given there are 4 customers
When I open administration dashboard
Then I should see 4 new customers in the list
1 change: 1 addition & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"excludes": [
"Behat",
"Command",
"Controller",
"DependencyInjection",
"Formatter",
"Menu",
Expand Down
31 changes: 31 additions & 0 deletions spec/App/Dashboard/DashboardStatisticsProviderSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace spec\App\Dashboard;

use App\Dashboard\DashboardStatistics;
use App\Dashboard\DashboardStatisticsProvider;
use App\Repository\CustomerRepository;
use PhpSpec\ObjectBehavior;

class DashboardStatisticsProviderSpec extends ObjectBehavior
{
function let(CustomerRepository $customerRepository): void
{
$this->beConstructedWith($customerRepository);
}

function it_is_initializable()
{
$this->shouldHaveType(DashboardStatisticsProvider::class);
}

function it_obtains_statistics(
CustomerRepository $customerRepository
): void {
$expectedStats = new DashboardStatistics(6);

$customerRepository->countCustomers()->willReturn(6);

$this->getStatistics()->shouldBeLike($expectedStats);
}
}
25 changes: 25 additions & 0 deletions spec/App/Dashboard/DashboardStatisticsSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace spec\App\Dashboard;

use App\Dashboard\DashboardStatistics;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class DashboardStatisticsSpec extends ObjectBehavior
{
function let(): void
{
$this->beConstructedWith(10);
}

function it_is_initializable()
{
$this->shouldHaveType(DashboardStatistics::class);
}

function it_has_new_customers_stat(): void
{
$this->getNumberOfNewCustomers()->shouldReturn(10);
}
}
14 changes: 14 additions & 0 deletions src/Behat/Context/Setup/CustomerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ public function thereIsCustomer($email): void
$this->customerRepository->add($customer);
}

/**
* @Given there are :numberOfCustomers customers
*/
public function thereAreCustomers(int $numberOfCustomers): void
{
for ($i=0; $i<$numberOfCustomers; ++$i) {
$customer = $this->createCustomer(sprintf('john%s@doe.com', uniqid()));
$customer->setFirstname('John');
$customer->setLastname('Doe' . $i);

$this->customerRepository->add($customer);
}
}

/**
* @Given there is customer :email with first name :firstName
*/
Expand Down
53 changes: 53 additions & 0 deletions src/Behat/Context/Ui/Backend/DashboardContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* This file is part of monofony.
*
* (c) Mobizel
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Behat\Context\Ui\Backend;

use App\Behat\Page\Backend\DashboardPage;
use Behat\Behat\Context\Context;
use Webmozart\Assert\Assert;

class DashboardContext implements Context
{
/** @var DashboardPage */
private $dashboardPage;

public function __construct(DashboardPage $dashboardPage)
{
$this->dashboardPage = $dashboardPage;
}

/**
* @When I open administration dashboard
*/
public function iOpenAdministrationDashboard()
{
$this->dashboardPage->open();
}

/**
* @Then I should see :number new customers in the list
*/
public function iShouldSeeNewCustomersInTheList($number)
{
Assert::same($this->dashboardPage->getNumberOfNewCustomersInTheList(), (int) $number);
}

/**
* @Then I should see :number new customers
*/
public function iShouldSeeNewCustomers($number)
{
Assert::same($this->dashboardPage->getNumberOfNewCustomers(), (int) $number);
}
}
59 changes: 59 additions & 0 deletions src/Behat/Page/Backend/DashboardPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*
* This file is part of monofony.
*
* (c) Mobizel
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Behat\Page\Backend;

use App\Behat\Service\Accessor\TableAccessorInterface;
use Behat\Mink\Session;
use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage;
use Symfony\Component\Routing\RouterInterface;

class DashboardPage extends SymfonyPage
{
/** @var TableAccessorInterface */
private $tableAccessor;

public function __construct(
Session $session,
$minkParameters,
RouterInterface $router,
TableAccessorInterface $tableAccessor
) {
parent::__construct($session, $minkParameters, $router);

$this->tableAccessor = $tableAccessor;
}

public function getRouteName(): string
{
return 'app_backend_dashboard';
}

public function getNumberOfNewCustomersInTheList(): int
{
return $this->tableAccessor->countTableBodyRows($this->getElement('customer_list'));
}

public function getNumberOfNewCustomers(): int
{
return (int) $this->getElement('new_customers')->getText();
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'customer_list' => '#customers',
'new_customers' => '#new-customers',
]);
}
}
11 changes: 5 additions & 6 deletions src/Behat/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ services:
arguments:
- "%kernel.cache_dir%/spool"

App\Behat\Service\EmailCheckerInterface:
alias: app.behat.email_checker
App\Behat\Service\EmailCheckerInterface: '@app.behat.email_checker'

app.behat.notification_accessor:
class: App\Behat\Service\Accessor\NotificationAccessor
Expand All @@ -65,15 +64,15 @@ services:
arguments:
- "@app.behat.notification_accessor"

App\Behat\Service\NotificationCheckerInterface:
alias: app.behat.notification_checker
App\Behat\Service\NotificationCheckerInterface: '@app.behat.notification_checker'

App\Behat\Service\SharedStorage:
public: false

App\Behat\Service\SharedStorageInterface:
alias: App\Behat\Service\SharedStorage
App\Behat\Service\SharedStorageInterface: '@App\Behat\Service\SharedStorage'

app.behat.table_accessor:
class: App\Behat\Service\Accessor\TableAccessor
public: false

App\Behat\Service\Accessor\TableAccessorInterface: '@app.behat.table_accessor'
3 changes: 2 additions & 1 deletion src/Behat/Resources/config/services/pages/backend.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
imports:
- { resource: backend/administrator.yaml }
- { resource: backend/customer.yaml }
- { resource: backend/dashboard.yaml }

# Learn more about services, parameters and containers at
# http://symfony.com/doc/current/book/service_container.html
Expand Down Expand Up @@ -30,4 +31,4 @@ services:
class: App\Behat\Page\Backend\Crud\UpdatePage
parent: app.behat.symfony_page
abstract: true
public: false
public: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
App\Behat\Page\Backend\DashboardPage:
parent: app.behat.symfony_page
public: false
autowire: true
1 change: 1 addition & 0 deletions src/Behat/Resources/config/suites.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ imports:
- suites/ui/account/customer.yaml
- suites/ui/account/login.yaml
- suites/ui/account/registration.yaml
- suites/ui/admin/dashboard.yaml
- suites/ui/customer/managing_customers.yaml
- suites/ui/user/managing_administrators.yaml
12 changes: 12 additions & 0 deletions src/Behat/Resources/config/suites/ui/admin/dashboard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
default:
suites:
ui_dashboard:
contexts:
- App\Behat\Context\Hook\DoctrineORMContext

- App\Behat\Context\Setup\CustomerContext
- App\Behat\Context\Setup\AdminSecurityContext

- App\Behat\Context\Ui\Backend\DashboardContext
filters:
tags: "@admin_dashboard && @ui"

0 comments on commit e623578

Please sign in to comment.