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

In order refund page disable buttons if all order is refunded #158

Merged
merged 2 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions features/refunding_all_order_units.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Feature: Refunding all order units
When I want to refund some units of order "#00000022"
And I decide to refund all units of this order with "Space money" payment
Then I should be notified that selected order units have been successfully refunded
And I should not be able to refund anything
And this order refunded total should be "$40.00"
But I should not be able to refund 1st unit with product "Mr. Meeseeks T-Shirt"
And I should not be able to refund 2nd unit with product "Mr. Meeseeks T-Shirt"
Expand Down
7 changes: 4 additions & 3 deletions src/Resources/views/orderRefunds.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{% block title %}{{ 'sylius.ui.order'|trans ~' #'~ order.number }} {{ 'sylius_refund.ui.refunds'|trans }} {{ parent() }}{% endblock %}

{% set customer = order.customer %}
{% set disableButton = order.paymentState == constant('Sylius\\Component\\Core\\OrderPaymentStates::STATE_REFUNDED') ? 'disabled' : '' %}

{% block content %}
{% include '@SyliusRefundPlugin/_header.html.twig' %}
Expand All @@ -15,8 +16,8 @@
<div class="ui segment">
<div class="ui right aligned grid">
<div class="sixteen wide column">
<button data-refund-clear type="button" class="ui button">{{ 'sylius_refund.ui.clear_refunds'|trans }}</button>
<button data-refund-all type="button" class="ui button primary">{{ 'sylius_refund.ui.refund_all'|trans }}</button>
<button data-refund-clear type="button" class="ui button" {{ disableButton }}>{{ 'sylius_refund.ui.clear_refunds'|trans }}</button>
<button data-refund-all type="button" class="ui button primary" {{ disableButton }}>{{ 'sylius_refund.ui.refund_all'|trans }}</button>
<div class="ui hidden divider"></div>
</div>
</div>
Expand All @@ -42,7 +43,7 @@
<div class="two column row">
<div class="column">
<div class="ui buttons">
<button id="page-button" class="ui labeled icon primary button" type="submit">
<button id="page-button" class="ui labeled icon primary button" type="submit" {{ disableButton }}>
<i class="check icon"></i>{{ 'sylius.ui.refund'|trans }}
</button>
<a id="back" href="{{ path('sylius_admin_order_show', {'id': order.id}) }}" class="ui button">
Expand Down
8 changes: 8 additions & 0 deletions tests/Behat/Context/Ui/RefundingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ public function shouldStillBeAbleToRefundOrderShipment(): void
Assert::true($this->orderRefundsPage->isOrderShipmentAvailableToRefund());
}

/**
* @Then I should not be able to refund anything
*/
public function iShouldNotBeAbleToRefundAnything(): void
{
Assert::true($this->orderRefundsPage->eachRefundButtonIsDisabled());
}

/**
* @Then I should not be able to refund order shipment
*/
Expand Down
9 changes: 9 additions & 0 deletions tests/Behat/Page/Admin/OrderRefundsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ public function isUnitWithProductAvailableToRefund(string $productName, int $uni
return $this->isRefundable($this->getUnitsWithProduct($productName)[$unitNumber]);
}

public function eachRefundButtonIsDisabled(): bool
{
return
$this->getDocument()->find('css', 'button[data-refund-clear]')->getAttribute('disabled') !== null &&
$this->getDocument()->find('css', '#page-button')->getAttribute('disabled') !== null &&
$this->getDocument()->find('css', 'button[data-refund-all]')->getAttribute('disabled') !== null
;
}

public function isOrderShipmentAvailableToRefund(): bool
{
return $this->isRefundable($this->getOrderShipment());
Expand Down
2 changes: 2 additions & 0 deletions tests/Behat/Page/Admin/OrderRefundsPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function refund(): void;

public function isUnitWithProductAvailableToRefund(string $productName, int $unitNumber): bool;

public function eachRefundButtonIsDisabled(): bool;

public function isOrderShipmentAvailableToRefund(): bool;

public function hasBackButton(): bool;
Expand Down