|
| 1 | +define([ |
| 2 | + 'Magento_Ui/js/grid/sortBy' |
| 3 | +], function (sortBy) { |
| 4 | + 'use strict'; |
| 5 | + describe('Magento_Ui/js/grid/sortBy', function () { |
| 6 | + |
| 7 | + var sortByObj; |
| 8 | + |
| 9 | + beforeEach(function () { |
| 10 | + sortByObj = new sortBy({ |
| 11 | + options: [] |
| 12 | + }); |
| 13 | + }); |
| 14 | + |
| 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 | + |
| 33 | + 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 () { |
| 43 | + var columns = [{ |
| 44 | + sortable: false, |
| 45 | + label: 'magento', |
| 46 | + index: 'test' |
| 47 | + }], |
| 48 | + expectedValue = []; |
| 49 | + sortByObj.preparedOptions(columns); |
| 50 | + expect(sortByObj.options).toEqual(expectedValue); |
| 51 | + }); |
| 52 | + |
| 53 | + it('Check "options" array is set the correct value', function () { |
| 54 | + var columns = [{ |
| 55 | + sortable: true, |
| 56 | + label: 'magento', |
| 57 | + index: 'test' |
| 58 | + }], |
| 59 | + expectedValue = [{ |
| 60 | + value: 'test', |
| 61 | + label: 'magento' |
| 62 | + }]; |
| 63 | + sortByObj.preparedOptions(columns); |
| 64 | + expect(sortByObj.options).toEqual(expectedValue); |
| 65 | + }); |
| 66 | + |
| 67 | + it('Check "isVisible" set true if column is sortable', function () { |
| 68 | + var columns = [{ |
| 69 | + sortable: true, |
| 70 | + label: 'magento', |
| 71 | + index: 'test' |
| 72 | + }]; |
| 73 | + spyOn(sortByObj, "isVisible").and.callFake(function () { |
| 74 | + return true; |
| 75 | + }); |
| 76 | + sortByObj.preparedOptions(columns); |
| 77 | + expect(sortByObj.isVisible).toHaveBeenCalled(); |
| 78 | + expect(sortByObj.isVisible()).toBeTruthy(); |
| 79 | + }); |
| 80 | + |
| 81 | + it('Check "isVisible" set true if column is sortable', function () { |
| 82 | + var columns = [{ |
| 83 | + sortable: true, |
| 84 | + label: 'magento', |
| 85 | + index: 'test' |
| 86 | + }]; |
| 87 | + spyOn(sortByObj, "isVisible").and.callFake(function () { |
| 88 | + return false; |
| 89 | + }); |
| 90 | + sortByObj.preparedOptions(columns); |
| 91 | + expect(sortByObj.isVisible).toHaveBeenCalled(); |
| 92 | + expect(sortByObj.isVisible()).toBeFalsy(); |
| 93 | + }); |
| 94 | + }); |
| 95 | + 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'); |
| 106 | + sortByObj.applyChanges(); |
| 107 | + expect(sortByObj.selectedOption).toHaveBeenCalled(); |
| 108 | + }); |
| 109 | + |
| 110 | + it('Check "applied" method has been called', function () { |
| 111 | + spyOn(sortByObj, 'applied'); |
| 112 | + sortByObj.applyChanges(); |
| 113 | + expect(sortByObj.applied).toHaveBeenCalled(); |
| 114 | + }); |
| 115 | + }); |
| 116 | + }); |
| 117 | +}); |
0 commit comments