Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit ebf22ff

Browse files
committed
MAGETWO-89675: Build Stabilization
Add/refactor JSUnit tests for UISelect component
1 parent 3df1b0d commit ebf22ff

File tree

2 files changed

+56
-15
lines changed
  • dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/form

2 files changed

+56
-15
lines changed

app/code/Magento/Catalog/view/frontend/templates/category/widget/link/link_href.phtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66

77
// @codingStandardsIgnoreFile
88
/** @var Magento\Catalog\Block\Widget\Link $block */
9-
// @codingStandardsIgnoreFile
109
?>
1110
<?= $block->escapeHtml($block->getHref()) ?>

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/form/ui-select.test.js

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ define([
88
'underscore',
99
'uiRegistry',
1010
'Magento_Ui/js/form/element/ui-select',
11-
'ko'
12-
], function (_, registry, Constr, ko) {
11+
'ko',
12+
'jquery'
13+
], function (_, registry, Constr, ko, $) {
1314
'use strict';
1415

1516
describe('Magento_Ui/js/form/element/ui-select', function () {
16-
17-
var obj;
17+
var obj,
18+
jQueryMethodsOverridden = {};
1819

1920
beforeEach(function () {
2021
obj = new Constr({
@@ -25,6 +26,14 @@ define([
2526

2627
obj.value = ko.observableArray([]);
2728
obj.cacheOptions.plain = [];
29+
30+
jQueryMethodsOverridden = {};
31+
});
32+
33+
afterEach(function () {
34+
_.each(jQueryMethodsOverridden, function (value, key) {
35+
$.fn[key] = value;
36+
});
2837
});
2938

3039
describe('"initialize" method', function () {
@@ -575,26 +584,30 @@ define([
575584
});
576585
});
577586
describe('"isSearchKeyCached" method', function () {
578-
it('Should return true if searchKey has already been cached and currentPage <= lastPage', function () {
587+
it('Should return false if searchKey has already been cached and total covers > 1 page', function () {
588+
obj.deviation = 30;
579589
obj.cachedSearchResults = {
580590
cake: {
581-
options: [],
582-
lastPage: 1
591+
options: [/** 50 options **/],
592+
lastPage: 1,
593+
total: 50
583594
}
584595
};
585596

586-
expect(obj.isSearchKeyCached('cake', 1)).toBe(true);
597+
expect(obj.isSearchKeyCached('cake')).toBe(false);
587598
});
588599

589-
it('Should return false if searchKey has already been cached and currentPage > lastPage', function () {
600+
it('Should return true if searchKey has already been cached and total only covers 1 page', function () {
601+
obj.deviation = 30;
590602
obj.cachedSearchResults = {
591603
cake: {
592-
options: [],
593-
lastPage: 1
604+
options: [/** 29 options **/],
605+
lastPage: 1,
606+
total: 29
594607
}
595608
};
596609

597-
expect(obj.isSearchKeyCached('cake', 2)).toBe(false);
610+
expect(obj.isSearchKeyCached('cake')).toBe(true);
598611
});
599612

600613
it('Should return false if searchKey is not cached', function () {
@@ -607,12 +620,41 @@ define([
607620
value: 'delicious'
608621
}];
609622

610-
obj.setCachedSearchResults('cake', options, 1);
623+
obj.setCachedSearchResults('cake', options, 1, 1);
611624

612625
expect(obj.getCachedSearchResults('cake')).toEqual({
613626
options: options,
614-
lastPage: 1
627+
lastPage: 1,
628+
total: 1
629+
});
630+
});
631+
});
632+
describe('"processRequest" method', function () {
633+
it('Should store options successfully fetched from ajax request', function () {
634+
var ajaxRequest,
635+
successfulAjaxResponse = {
636+
options: {
637+
'2053': {
638+
value: '2053',
639+
label: 'testProductName5a8ddfd933b5c',
640+
'is_active': 1,
641+
path: 'testSku5a8ddfd933b5c',
642+
optgroup: false
643+
}
644+
}
645+
};
646+
647+
jQueryMethodsOverridden.ajax = $.ajax;
648+
649+
spyOn($, 'ajax').and.callFake(function (request) {
650+
ajaxRequest = request.success.bind(obj);
615651
});
652+
653+
expect(obj.processRequest()).toBeUndefined();
654+
655+
ajaxRequest(successfulAjaxResponse);
656+
657+
expect(obj.options()).toEqual([successfulAjaxResponse.options['2053']]);
616658
});
617659
});
618660
});

0 commit comments

Comments
 (0)