From 2ec47d1d1a65ddfa7b9ac542487c6b73aa6e6bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Thu, 8 Aug 2024 10:54:31 +0200 Subject: [PATCH] OP-319 - Added select parcel Behat test --- .../adding_image_to_shipping_method.feature | 2 +- ...ng_shipping_method_parcel_template.feature | 28 ++++++++++ .../ParcelTemplate/_inpost_template.html.twig | 6 +- .../Ui/Admin/ShippingExportContext.php | 18 +++++- .../Page/Admin/ShippingExport/IndexPage.php | 56 +++++++++++++++++++ .../ShippingExport/IndexPageInterface.php | 19 +++++++ tests/Behat/Resources/services/contexts.yml | 4 +- tests/Behat/Resources/services/pages.yml | 8 +++ tests/Behat/Resources/suites.yml | 33 +++++++++++ 9 files changed, 166 insertions(+), 8 deletions(-) create mode 100644 features/changing_shipping_method_parcel_template.feature create mode 100644 tests/Behat/Page/Admin/ShippingExport/IndexPage.php create mode 100644 tests/Behat/Page/Admin/ShippingExport/IndexPageInterface.php diff --git a/features/adding_image_to_shipping_method.feature b/features/adding_image_to_shipping_method.feature index 1ea5b4e..b97fd28 100644 --- a/features/adding_image_to_shipping_method.feature +++ b/features/adding_image_to_shipping_method.feature @@ -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 \ No newline at end of file + Then I should be notified that it has been successfully edited diff --git a/features/changing_shipping_method_parcel_template.feature b/features/changing_shipping_method_parcel_template.feature new file mode 100644 index 0000000..71fb854 --- /dev/null +++ b/features/changing_shipping_method_parcel_template.feature @@ -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 "user@bitbag.pl" 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 diff --git a/src/Resources/views/ShippingExport/Grid/Field/ParcelTemplate/_inpost_template.html.twig b/src/Resources/views/ShippingExport/Grid/Field/ParcelTemplate/_inpost_template.html.twig index 126857b..e921a34 100644 --- a/src/Resources/views/ShippingExport/Grid/Field/ParcelTemplate/_inpost_template.html.twig +++ b/src/Resources/views/ShippingExport/Grid/Field/ParcelTemplate/_inpost_template.html.twig @@ -17,7 +17,7 @@
{% for key, label in templates %} {% if parcelTemplate == key %} - + {% else %} {% if data.getExportedAt != null %} @@ -25,9 +25,7 @@
-
diff --git a/tests/Behat/Context/Ui/Admin/ShippingExportContext.php b/tests/Behat/Context/Ui/Admin/ShippingExportContext.php index 0b0e852..a20f6f1 100644 --- a/tests/Behat/Context/Ui/Admin/ShippingExportContext.php +++ b/tests/Behat/Context/Ui/Admin/ShippingExportContext.php @@ -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 { @@ -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(); + } } diff --git a/tests/Behat/Page/Admin/ShippingExport/IndexPage.php b/tests/Behat/Page/Admin/ShippingExport/IndexPage.php new file mode 100644 index 0000000..59a0e72 --- /dev/null +++ b/tests/Behat/Page/Admin/ShippingExport/IndexPage.php @@ -0,0 +1,56 @@ +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.'); + } + } +} diff --git a/tests/Behat/Page/Admin/ShippingExport/IndexPageInterface.php b/tests/Behat/Page/Admin/ShippingExport/IndexPageInterface.php new file mode 100644 index 0000000..0273f59 --- /dev/null +++ b/tests/Behat/Page/Admin/ShippingExport/IndexPageInterface.php @@ -0,0 +1,19 @@ +