Skip to content

Commit e9809ae

Browse files
committed
MAGETWO-89660: Create JSUnit tests
Add KO binding/UI component tests
1 parent 7724d26 commit e9809ae

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'Magento_Ui/js/form/element/color-picker'
8+
], function (ColorPicker) {
9+
'use strict';
10+
11+
describe('ColorPicker UI Component Form Element', function () {
12+
it('Should have colorPickerConfig.value set to UI component instance\'s value', function () {
13+
var colorPicker = new ColorPicker({
14+
dataScope: ''
15+
});
16+
17+
expect(colorPicker.colorPickerConfig.value).toBe(colorPicker.value);
18+
});
19+
});
20+
});
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'ko',
8+
'jquery',
9+
'Magento_Ui/js/lib/knockout/bindings/color-picker'
10+
], function (ko, $) {
11+
'use strict';
12+
13+
var $input,
14+
originaljQuery,
15+
originaljQueryInit,
16+
originaljQuerySpectrum;
17+
18+
beforeEach(function () {
19+
originaljQuery = $;
20+
originaljQueryInit = $.fn.init;
21+
originaljQuerySpectrum = $.fn.spectrum;
22+
});
23+
24+
afterEach(function () {
25+
$ = originaljQuery;
26+
$.fn.init = originaljQueryInit;
27+
$.fn.spectrum = originaljQuerySpectrum;
28+
});
29+
30+
describe('Colorpicker binding', function () {
31+
describe('"init" method', function () {
32+
it('Should call spectrum on $input with disabled configuration if view model disabled', function () {
33+
var valueAccessor = jasmine.createSpy().and.returnValue({});
34+
var viewModel = {
35+
disabled: jasmine.createSpy().and.returnValue(true)
36+
};
37+
38+
$.fn.spectrum = jasmine.createSpy();
39+
$input = jasmine.createSpy();
40+
41+
ko.bindingHandlers.colorPicker.init($input, valueAccessor, null, viewModel);
42+
43+
expect($.fn.spectrum).toHaveBeenCalledWith({
44+
disabled: true
45+
});
46+
47+
$.fn.init = jasmine.createSpy().and.returnValue($.fn);
48+
49+
ko.bindingHandlers.colorPicker.init($input, valueAccessor, null, viewModel);
50+
51+
expect($.fn.init).toHaveBeenCalledWith($input, undefined);
52+
});
53+
54+
it('Should call spectrum on $input with extra configuration if view model enabled', function () {
55+
var value = {
56+
configStuffInHere: true
57+
};
58+
var valueAccessor = jasmine.createSpy().and.returnValue(value);
59+
var viewModel = {
60+
disabled: jasmine.createSpy().and.returnValue(false)
61+
};
62+
63+
$.fn.spectrum = jasmine.createSpy();
64+
$input = jasmine.createSpy();
65+
66+
ko.bindingHandlers.colorPicker.init($input, valueAccessor, null, viewModel);
67+
68+
expect(value.change).toEqual(jasmine.any(Function));
69+
expect(value.hide).toEqual(jasmine.any(Function));
70+
expect(value.show).toEqual(jasmine.any(Function));
71+
expect(value.change).toBe(value.hide);
72+
73+
expect($.fn.spectrum).toHaveBeenCalledWith(value);
74+
75+
$.fn.init = jasmine.createSpy().and.returnValue($.fn);
76+
77+
ko.bindingHandlers.colorPicker.init($input, valueAccessor, null, viewModel);
78+
79+
expect($.fn.init).toHaveBeenCalledWith($input, undefined);
80+
});
81+
});
82+
});
83+
});

0 commit comments

Comments
 (0)