-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #665 from magento-performance/MAGETWO-56071
[Performance] Unnecessary AJAX request for product reviews on product details page
- Loading branch information
Showing
3 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...ests/js/jasmine/tests/app/code/Magento/Review/view/frontend/web/js/process-review.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* 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(); | ||
}); | ||
}); | ||
}); |