Skip to content

Commit 4e65dc9

Browse files
refactoring test
1 parent d913e15 commit 4e65dc9

File tree

1 file changed

+21
-64
lines changed
  • dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid

1 file changed

+21
-64
lines changed

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/sortBy.test.js

Lines changed: 21 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,106 +12,63 @@ define([
1212
});
1313
});
1414

15-
describe('"initObservable" method', function () {
16-
it('Check for defined ', function () {
17-
expect(sortByObj.hasOwnProperty('initObservable')).toBeDefined();
18-
});
19-
it('Check method type', function () {
20-
var type = typeof sortByObj.initObservable;
21-
22-
expect(type).toEqual('function');
23-
});
24-
it('Check returned value if method called without arguments', function () {
25-
expect(sortByObj.initObservable()).toBeDefined();
26-
});
27-
it('Check returned value type if method called without arguments', function () {
28-
var type = typeof sortByObj.initObservable();
29-
expect(type).toEqual('object');
30-
});
31-
});
32-
3315
describe('"preparedOptions" method', function () {
34-
it('Check for defined ', function () {
35-
expect(sortByObj.hasOwnProperty('preparedOptions')).toBeDefined();
36-
});
37-
it('Check method type', function () {
38-
var type = typeof sortByObj.preparedOptions;
39-
expect(type).toEqual('function');
40-
});
41-
42-
it('Check "options" array is empty if sortable is set false', function () {
16+
it('return empty array if sorting is disabled for the columns', function () {
4317
var columns = [{
4418
sortable: false,
4519
label: 'magento',
46-
index: 'test'
20+
index: 'name'
4721
}],
48-
expectedValue = [];
22+
options = [];
4923
sortByObj.preparedOptions(columns);
50-
expect(sortByObj.options).toEqual(expectedValue);
24+
expect(sortByObj.options).toEqual(options);
5125
});
5226

53-
it('Check "options" array is set the correct value', function () {
27+
it('return array of options if sorting is enabled for the columns', function () {
5428
var columns = [{
5529
sortable: true,
5630
label: 'magento',
57-
index: 'test'
31+
index: 'name'
5832
}],
59-
expectedValue = [{
60-
value: 'test',
33+
options = [{
34+
value: 'name',
6135
label: 'magento'
6236
}];
6337
sortByObj.preparedOptions(columns);
64-
expect(sortByObj.options).toEqual(expectedValue);
38+
expect(sortByObj.options).toEqual(options);
6539
});
6640

67-
it('Check "isVisible" set true if column is sortable', function () {
41+
it('return "isVisible" method true if column is sortable', function () {
6842
var columns = [{
6943
sortable: true,
7044
label: 'magento',
71-
index: 'test'
45+
index: 'name'
7246
}];
73-
spyOn(sortByObj, "isVisible").and.callFake(function () {
74-
return true;
75-
});
7647
sortByObj.preparedOptions(columns);
77-
expect(sortByObj.isVisible).toHaveBeenCalled();
7848
expect(sortByObj.isVisible()).toBeTruthy();
7949
});
8050

81-
it('Check "isVisible" set true if column is sortable', function () {
51+
it('return "isVisible" method false if column is sortable', function () {
8252
var columns = [{
83-
sortable: true,
53+
sortable: false,
8454
label: 'magento',
85-
index: 'test'
55+
index: 'name'
8656
}];
87-
spyOn(sortByObj, "isVisible").and.callFake(function () {
88-
return false;
89-
});
9057
sortByObj.preparedOptions(columns);
91-
expect(sortByObj.isVisible).toHaveBeenCalled();
9258
expect(sortByObj.isVisible()).toBeFalsy();
9359
});
9460
});
9561
describe('"applyChanges" method', function () {
96-
it('Check for defined ', function () {
97-
expect(sortByObj.hasOwnProperty('applyChanges')).toBeDefined();
98-
});
99-
it('Check method type', function () {
100-
var type = typeof sortByObj.applyChanges;
101-
expect(type).toEqual('function');
102-
});
103-
104-
it('Check "selectedOption" method has been called', function () {
105-
spyOn(sortByObj, 'selectedOption');
62+
it('return applied option', function () {
63+
var applied = {
64+
field: 'selectedOption',
65+
direction: 'desc'
66+
};
67+
spyOn(sortByObj, 'selectedOption').and.returnValue('selectedOption');
10668
sortByObj.applyChanges();
69+
expect(sortByObj.applied()).toEqual(applied);
10770
expect(sortByObj.selectedOption).toHaveBeenCalled();
10871
});
109-
110-
it('Check "applied" method has been called', function () {
111-
spyOn(sortByObj, 'applied');
112-
sortByObj.applyChanges();
113-
expect(sortByObj.applied).toHaveBeenCalled();
114-
});
11572
});
11673
});
11774
});

0 commit comments

Comments
 (0)