Skip to content

Commit

Permalink
OP-319 - Added select parcel Behat test
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkalon committed Aug 8, 2024
1 parent dabaaca commit 2ec47d1
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 8 deletions.
2 changes: 1 addition & 1 deletion features/adding_image_to_shipping_method.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Feature: Adding shipping method image
When I want to modify a shipping method "InPost"
And I upload the "image/shipping_logo.jpg" image as shipping method logo
And I save my changes
Then I should be notified that it has been successfully edited
Then I should be notified that it has been successfully edited
28 changes: 28 additions & 0 deletions features/changing_shipping_method_parcel_template.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@managing_shipping_export_parcel_template_inpost
Feature: Changing shipping export parcel template
To send a query to the Inpost API with a different shipment template
As an Administrator
I need to be able to choose a parcel template

Background:
Given the store operates on a single channel in the "United States" named "Web-US"
And I am logged in as an administrator
And the store has "Inpost" shipping method with "$10.00" fee
And there is a registered "inpost" shipping gateway for this shipping method named "INPOST_PL"
And it has "Access token" field set to "123"
And it has "Organization ID" field set to "123"
And it has "Environment" field set to "sandbox"
And it has "service" field set to "inpost_locker_standard"
And the store has a product "Chicken" priced at "$2.00" in "Web-US" channel
And customer "[email protected]" has placed 1 orders on the "Web-US" channel in each buying 5 "Chicken" products
And the customer set the shipping address "Mike Ross" addressed it to "350 5th Ave", "10118" "New York" in the "United States" to orders
And those orders were placed with "Inpost" shipping method
And set product weight to "10"
And set units to the shipment

@ui
Scenario: Seeing shipments to export
When I go to the shipping export page
Then I should see 1 shipments with "New" state
When I select parcel template
Then I should see that shipping export parcel template is set
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
<div class="ui buttons">
{% for key, label in templates %}
{% if parcelTemplate == key %}
<button class="ui button primary">{{ label }}</button>
<button class="ui button primary" data-shipping-export-selected-template>{{ label }}</button>
{% else %}
{% if data.getExportedAt != null %}
<button class="ui button disabled">{{ label }}</button>
{% else %}
<form action="{{ path('bitbag_admin_shipping_export_select_parcel_template', {'id' : data.id, 'template': key}) }}"
method="POST">
<input type="hidden" name="_method" value="PUT">
<button class="ui button shipping-export-select-template-button"
data-content="The default theme's basic popup removes the pointing arrow."
data-variation="basic">
<button class="ui button shipping-export-select-template">
{{ label }}
</button>
</form>
Expand Down
18 changes: 17 additions & 1 deletion tests/Behat/Context/Ui/Admin/ShippingExportContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Behat\Behat\Context\Context;
use Tests\BitBag\SyliusInPostPlugin\Behat\Mocker\InPostApiMocker;
use Tests\BitBag\SyliusShippingExportPlugin\Behat\Page\Admin\ShippingExport\IndexPageInterface;
use Tests\BitBag\SyliusInPostPlugin\Behat\Page\Admin\ShippingExport\IndexPageInterface;

final class ShippingExportContext implements Context
{
Expand Down Expand Up @@ -48,4 +48,20 @@ public function iExportFirsShipments(): void
$this->indexPage->exportFirsShipment();
});
}

/**
* @When I select parcel template
*/
public function iSelectParcelTemplate(): void
{
$this->indexPage->selectParcelTemplate();
}

/**
* @Then I should see that shipping export parcel template is set
*/
public function iCheckParcelTemplate(): void
{
$this->indexPage->checkParcelTemplate();
}
}
56 changes: 56 additions & 0 deletions tests/Behat/Page/Admin/ShippingExport/IndexPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusInPostPlugin\Behat\Page\Admin\ShippingExport;

use Behat\Mink\Element\ElementInterface;
use Sylius\Behat\Page\Admin\Crud\IndexPage as BaseIndexPage;

final class IndexPage extends BaseIndexPage implements IndexPageInterface
{
public function getShipmentsWithState(string $state): array
{
$items = $this->getDocument()->findAll('css', '.shipping-export-state');
$result = [];

/** @var ElementInterface $item */
foreach ($items as $item) {
if ($item->getText() === $state) {
$result[] = $item;
}
}

return $result;
}

public function exportAllShipments(): void
{
$this->getDocument()->pressButton('Export all new shipments');
}

public function exportFirsShipment(): void
{
$this->getDocument()->find('css', '.shipping-export-state')->click();
}

public function selectParcelTemplate(): void
{
$this->getDocument()->find('css', '.shipping-export-select-template')->click();
}

public function checkParcelTemplate(): void
{
$button = $this->getDocument()->find('xpath', '//button[@data-shipping-export-selected-template]');
if (null === $button) {
throw new \Exception('Parcel template is not selected.');
}
}
}
19 changes: 19 additions & 0 deletions tests/Behat/Page/Admin/ShippingExport/IndexPageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusInPostPlugin\Behat\Page\Admin\ShippingExport;

use Tests\BitBag\SyliusShippingExportPlugin\Behat\Page\Admin\ShippingExport\IndexPageInterface as BaseIndexPageInterface;

interface IndexPageInterface extends BaseIndexPageInterface
{
public function selectParcelTemplate(): void;
}
4 changes: 2 additions & 2 deletions tests/Behat/Resources/services/contexts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ services:
class: Tests\BitBag\SyliusInPostPlugin\Behat\Context\Ui\Admin\ShippingExportContext
public: true
arguments:
- '@bitbag.behat.page.admin.shipping_export.index'
- '@bitbag.sylius_inpost_plugin.behat.page.admin.shipping_export.index'
- '@bitbag.sylius_inpost_plugin.behat.mocker.inpost_api_mocker'
-

bitbag.sylius_inpost_plugin.behat.context.ui.admin.shipping_image:
class: Tests\BitBag\SyliusInPostPlugin\Behat\Context\Ui\Admin\ShippingMethodContext
public: true
Expand Down
8 changes: 8 additions & 0 deletions tests/Behat/Resources/services/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ services:
public: false
arguments:
- 'bitbag_admin_shipping_method_update'

bitbag.sylius_inpost_plugin.behat.page.admin.shipping_export.index:
class: Tests\BitBag\SyliusInPostPlugin\Behat\Page\Admin\ShippingExport\IndexPage
parent: bitbag.behat.page.admin.shipping_export.index
public: false
arguments:
- 'bitbag_admin_shipping_export_select_parcel_template'

33 changes: 33 additions & 0 deletions tests/Behat/Resources/suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,36 @@ default:
- bitbag.sylius_inpost_plugin.behat.context.ui.admin.shipping_image
filters:
tags: "@managing_shipping_image_inpost&&@ui"

managing_shipping_export_parcel_template_inpost:
contexts:
- sylius.behat.context.hook.doctrine_orm
- bitbag.behat.context.hook.shipping_export

- sylius.behat.context.transform.customer
- sylius.behat.context.transform.channel
- sylius.behat.context.transform.lexical
- sylius.behat.context.transform.product
- sylius.behat.context.transform.shipping_method
- sylius.behat.context.transform.address
- sylius.behat.context.transform.order
- sylius.behat.context.transform.payment
- sylius.behat.context.transform.user

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.product
- sylius.behat.context.setup.admin_security
- sylius.behat.context.setup.shipping
- sylius.behat.context.setup.order
- sylius.behat.context.setup.product
- sylius.behat.context.setup.payment
- sylius.behat.context.setup.shop_security
- bitbag.behat.context.setup.shipping_gateway
- bitbag.behat.context.setup.shipping_export
- bitbag.sylius_inpost_plugin.behat.context.setup.shipping_gateway

- bitbag.behat.context.ui.admin.shipping_gateway
- bitbag.behat.context.ui.admin.shipping_export
- bitbag.sylius_inpost_plugin.behat.context.ui.admin.shipping_export
filters:
tags: "@managing_shipping_export_parcel_template_inpost&&@ui"

0 comments on commit 2ec47d1

Please sign in to comment.