Skip to content

Commit 1fbeb2e

Browse files
committed
MAGETWO-67106: Unstable Automated test Magento\Paypal\Test\TestCase\InContextExpressCheckoutFromShoppingCartTest failed on variation InContextExpressCheckoutFromShoppingCartTestVariation1
1 parent e6bd3ea commit 1fbeb2e

File tree

8 files changed

+60
-7
lines changed

8 files changed

+60
-7
lines changed

app/code/Magento/Paypal/Block/Express/InContext/Minicart/Button.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class Button extends Template implements ShortcutInterface
2626

2727
const BUTTON_ELEMENT_INDEX = 'button_id';
2828

29+
const BUTTON_ELEMENT_CLASS_NAME = 'button_class';
30+
2931
const CART_BUTTON_ELEMENT_INDEX = 'add_to_cart_selector';
3032

3133
/**
@@ -132,6 +134,14 @@ public function getContainerId()
132134
return $this->getData(self::BUTTON_ELEMENT_INDEX);
133135
}
134136

137+
/**
138+
* @return string
139+
*/
140+
public function getButtonClassName()
141+
{
142+
return $this->getData(self::BUTTON_ELEMENT_CLASS_NAME);
143+
}
144+
135145
/**
136146
* @return string
137147
*/

app/code/Magento/Paypal/etc/frontend/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<item name="template" xsi:type="string">Magento_Paypal::express/in-context/shortcut/button.phtml</item>
9393
<item name="alias" xsi:type="string">paypal.express-in-context.mini-cart</item>
9494
<item name="button_id" xsi:type="string">paypal-express-in-context-mini-cart</item>
95+
<item name="button_class" xsi:type="string">paypal-express-in-context-checkout</item>
9596
</argument>
9697
<argument name="payment" xsi:type="object">Magento\Paypal\Model\Express</argument>
9798
</arguments>

app/code/Magento/Paypal/view/frontend/templates/express/in-context/shortcut/button.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use Magento\Paypal\Block\Express\InContext\Minicart\Button;
1212
$config = [
1313
'Magento_Paypal/js/in-context/button' => [
1414
'id' => $block->getContainerId(),
15+
'paypalButtonClass' => $block->getButtonClassName(),
1516
'paypalButton' => Button::PAYPAL_BUTTON_ID,
1617
'addToCartSelector' => $block->getAddToCartSelector()
1718
]
@@ -20,7 +21,7 @@ $config = [
2021
?>
2122
<div data-mage-init='<?php /* @noEscape */ echo json_encode($config); ?>'
2223
class="paypal checkout paypal-logo <?php /* @noEscape */ echo $block->getContainerId(); ?>-container">
23-
<a id="<?php /* @noEscape */ echo $block->getContainerId(); ?>" href="#">
24+
<a class="<?php /* @noEscape */ echo $block->getButtonClassName(); ?>" href="#">
2425
<img class="paypal-button-hidden"
2526
src="<?php /* @noEscape */ echo $block->getImageUrl() ?>"
2627
alt="Check out with PayPal" />

app/code/Magento/Paypal/view/frontend/web/js/in-context/button.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
define(
66
[
77
'uiComponent',
8+
'Magento_Checkout/js/model/quote',
89
'jquery',
910
'domReady!'
1011
],
1112
function (
1213
Component,
14+
quote,
1315
$
1416
) {
15-
'use strict';
16-
1717
return Component.extend({
1818

1919
defaults: {},
@@ -31,12 +31,25 @@ define(
3131
* @returns {Object}
3232
*/
3333
initEvents: function () {
34-
$('#' + this.id).off('click.' + this.id)
34+
35+
$('.' + this.paypalButtonClass).off('click.' + this.id)
3536
.on('click.' + this.id, this.click.bind(this));
3637

38+
quote.totals.subscribe(function (newValue) {
39+
// TODO: check for value
40+
this.showLink();
41+
}, this);
42+
3743
return this;
3844
},
3945

46+
/**
47+
* Display PayPal in-context checkout link
48+
*/
49+
showLink: function() {
50+
$('.' + this.paypalButtonClass).show();
51+
},
52+
4053
/**
4154
* @param {Object} event
4255
* @returns void

app/code/Magento/Paypal/view/frontend/web/js/in-context/express-checkout.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ define(
2525
defaults: {
2626
clientConfig: {
2727

28+
inited: false,
29+
2830
/**
2931
* @param {Object} event
3032
*/
@@ -33,7 +35,12 @@ define(
3335

3436
event.preventDefault();
3537

36-
paypalExpressCheckout.checkout.initXO();
38+
if (!this.clientConfig.inited) {
39+
paypalExpressCheckout.checkout.initXO();
40+
this.clientConfig.inited = true;
41+
} else {
42+
paypalExpressCheckout.checkout.closeFlow();
43+
}
3744

3845
$.get(
3946
this.path,
@@ -52,11 +59,11 @@ define(
5259
}
5360
).fail(
5461
function () {
55-
$('body').trigger('processStop');
5662
paypalExpressCheckout.checkout.closeFlow();
5763
}
5864
).always(
5965
function () {
66+
$('body').trigger('processStop');
6067
customerData.invalidate(['cart']);
6168
}
6269
);

app/design/frontend/Magento/blank/Magento_Paypal/web/css/source/module/_paypal-button.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,8 @@
5353
&:extend(.abs-action-button-as-link all);
5454
}
5555
}
56+
57+
.paypal-express-in-context-checkout {
58+
display: none;
59+
}
5660
}

app/design/frontend/Magento/luma/Magento_Paypal/web/css/source/module/_paypal-button.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@
4949
&:extend(.abs-action-button-as-link all);
5050
}
5151
}
52+
53+
.paypal-express-in-context-checkout {
54+
display: none;
55+
}
5256
}

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Cart extends Block
6262
*
6363
* @var string
6464
*/
65-
protected $inContextPaypalCheckoutButton = '#paypal-express-in-context-mini-cart';
65+
protected $inContextPaypalCheckoutButton = 'ul.checkout-methods-items a.paypal-express-in-context-checkout';
6666

6767
/**
6868
* Locator value for "Check out with Braintree PayPal" button.
@@ -184,6 +184,7 @@ public function paypalCheckout()
184184
*/
185185
public function inContextPaypalCheckout()
186186
{
187+
$this->waitForCheckoutButton();
187188
$this->_rootElement->find($this->inContextPaypalCheckoutButton)->click();
188189
$this->browser->selectWindow();
189190
$this->waitForFormLoaded();
@@ -262,4 +263,16 @@ public function waitCartContainerLoading()
262263
{
263264
$this->waitForElementVisible($this->cartContainer);
264265
}
266+
267+
/**
268+
* Wait until in-context checkout button is visible.
269+
*
270+
* @return void
271+
*/
272+
public function waitForCheckoutButton()
273+
{
274+
$this->waitForElementVisible($this->inContextPaypalCheckoutButton);
275+
}
276+
277+
265278
}

0 commit comments

Comments
 (0)