Skip to content
Snippets Groups Projects
Commit 8f47b350 authored by Aleksandr Osadchyi's avatar Aleksandr Osadchyi
Browse files

Merge remote-tracking branch 'mainline/develop' into MAGETWO-61725

parents 7ee9fef1 f3fb417c
Branches
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
{ {
"*": { "*": {
"Magento_Review/js/process-reviews": { "Magento_Review/js/process-reviews": {
"productReviewUrl": "<?php echo $block->escapeJs($block->escapeUrl($block->getProductReviewUrl())); ?>" "productReviewUrl": "<?php echo $block->escapeJs($block->escapeUrl($block->getProductReviewUrl())); ?>",
"reviewsTabSelector": "#tab-label-reviews"
} }
} }
} }
......
...@@ -11,7 +11,9 @@ define([ ...@@ -11,7 +11,9 @@ define([
$.ajax({ $.ajax({
url: url, url: url,
cache: true, cache: true,
dataType: 'html' dataType: 'html',
showLoader: true,
loaderContext: $('.product.data.items')
}).done(function (data) { }).done(function (data) {
$('#product-review-container').html(data); $('#product-review-container').html(data);
$('[data-role="product-review"] .pages a').each(function (index, element) { $('[data-role="product-review"] .pages a').each(function (index, element) {
...@@ -30,7 +32,17 @@ define([ ...@@ -30,7 +32,17 @@ define([
} }
return function (config, element) { return function (config, element) {
processReviews(config.productReviewUrl); var reviewTab = $(config.reviewsTabSelector);
var requiredReviewTabRole = 'tab';
if (reviewTab.attr('role') === requiredReviewTabRole && reviewTab.hasClass('active')) {
processReviews(config.productReviewUrl);
} else {
reviewTab.one('beforeOpen', function () {
processReviews(config.productReviewUrl);
});
}
$(function () { $(function () {
$('.product-info-main .reviews-actions a').click(function (event) { $('.product-info-main .reviews-actions a').click(function (event) {
event.preventDefault(); event.preventDefault();
......
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
/*eslint max-nested-callbacks: 0*/
/*jscs:disable jsDoc*/
define([
'jquery',
'Magento_Review/js/process-reviews'
], function ($, reviewProcessor) {
'use strict';
describe('Test product page reviews processor', function () {
var element,
config = {
reviewsTabSelector: '#review-tab'
};
beforeEach(function () {
element = $('<div id="review-tab" role="tab"></div>');
$('body').append(element);
});
afterEach(function () {
element.remove();
});
it('Should automatically load reviews after page load if review tab is active', function () {
element.addClass('active');
spyOn($, 'ajax').and.callFake(function () {
var d = $.Deferred();
d.promise().complete = function () {};
return d.promise();
});
reviewProcessor(config, null);
expect($.ajax).toHaveBeenCalled();
});
it('Should not automatically load reviews after page load if review tab is not active', function () {
spyOn($, 'ajax').and.callFake(function () {
var d = $.Deferred();
d.promise().complete = function () {};
return d.promise();
});
reviewProcessor(config, null);
expect($.ajax).not.toHaveBeenCalled();
});
it('Should load reviews if non active review tab was opened', function () {
spyOn($, 'ajax').and.callFake(function () {
var d = $.Deferred();
d.promise().complete = function () {};
return d.promise();
});
reviewProcessor(config, null);
element.trigger('beforeOpen');
expect($.ajax).toHaveBeenCalled();
});
});
});
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment