|
| 1 | +/** |
| 2 | + * Copyright © Magento, Inc. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | + |
| 6 | +/*eslint max-nested-callbacks: 0*/ |
| 7 | +define([ |
| 8 | + 'jquery', |
| 9 | + 'squire', |
| 10 | + 'underscore', |
| 11 | + 'Magento_Sales/js/grid/tree-massactions' |
| 12 | +], function ($, Squire, _, TreeMassaction) { |
| 13 | + 'use strict'; |
| 14 | + |
| 15 | + var injector = new Squire(), |
| 16 | + mocks = { |
| 17 | + 'Magento_Ui/js/grid/massactions': { |
| 18 | + defaultCallback: jasmine.createSpy().and.returnValue({}), |
| 19 | + applyAction: jasmine.createSpy().and.returnValue({}) |
| 20 | + } |
| 21 | + }, |
| 22 | + obj, |
| 23 | + utils; |
| 24 | + |
| 25 | + describe('Magento_Sales/js/grid/tree-massactions', function () { |
| 26 | + var model; |
| 27 | + |
| 28 | + beforeEach(function (done) { |
| 29 | + injector.mock(mocks); |
| 30 | + injector.require([ |
| 31 | + 'Magento_Ui/js/grid/massactions', |
| 32 | + 'mageUtils' |
| 33 | + ], function (instance, mageUtils) { |
| 34 | + obj = _.extend({}, instance); |
| 35 | + utils = mageUtils; |
| 36 | + done(); |
| 37 | + }); |
| 38 | + model = new TreeMassaction({ |
| 39 | + actions: [ |
| 40 | + { |
| 41 | + type: 'availability', |
| 42 | + actions: [{ |
| 43 | + type: 'enable' |
| 44 | + }, { |
| 45 | + type: 'disable' |
| 46 | + }] |
| 47 | + }, |
| 48 | + { |
| 49 | + type: 'hold_order', |
| 50 | + component: 'uiComponent', |
| 51 | + label: 'hold', |
| 52 | + url: 'http://local.magento/hold_order', |
| 53 | + modules: { |
| 54 | + selections: ['1','2','3'] |
| 55 | + }, |
| 56 | + actions: [{ |
| 57 | + callback: 'defaultCallback' |
| 58 | + }] |
| 59 | + }] |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + afterEach(function () { |
| 64 | + try { |
| 65 | + injector.clean(); |
| 66 | + injector.remove(); |
| 67 | + } catch (e) {} |
| 68 | + }); |
| 69 | + |
| 70 | + describe('check applyAction', function () { |
| 71 | + it('change visibility of submenu', function () { |
| 72 | + expect(model.actions()[0].visible()).toBeFalsy(); |
| 73 | + expect(model.applyAction('availability')).toBe(model); |
| 74 | + expect(model.actions()[0].visible()).toBeTruthy(); |
| 75 | + }); |
| 76 | + }); |
| 77 | + describe('check defaultCallback', function () { |
| 78 | + it('check model called with action and selected data', function () { |
| 79 | + expect(model.applyAction('hold_order')).toBe(model); |
| 80 | + expect(model.actions()[1].visible()).toBeTruthy(); |
| 81 | + expect(model.actions()[1].modules.selections).toBeTruthy(); |
| 82 | + expect(model.actions()[1].modules.selections.total).toBeFalsy(); |
| 83 | + }); |
| 84 | + |
| 85 | + it('check defaultCallback submitted the data', function () { |
| 86 | + var action = { |
| 87 | + component: 'uiComponent', |
| 88 | + label: 'Hold', |
| 89 | + type: 'hold_order', |
| 90 | + url: 'http://local.magento/hold_order/' |
| 91 | + }, |
| 92 | + data = { |
| 93 | + excludeMode: true, |
| 94 | + excluded: [], |
| 95 | + params: {}, |
| 96 | + selected: ['7', '6', '5', '4', '3', '2', '1'], |
| 97 | + total: 7 |
| 98 | + }, |
| 99 | + result; |
| 100 | + |
| 101 | + obj.getAction = jasmine.createSpy().and.returnValue('hold_order'); |
| 102 | + |
| 103 | + obj.applyAction(action); |
| 104 | + |
| 105 | + result = obj.defaultCallback(action, data); |
| 106 | + |
| 107 | + expect(typeof result).toBe('object'); |
| 108 | + spyOn(utils, 'submit').and.callThrough(); |
| 109 | + utils.submit({ |
| 110 | + url: action.url, |
| 111 | + data: data.selected |
| 112 | + }); |
| 113 | + expect(utils.submit).toHaveBeenCalled(); |
| 114 | + }); |
| 115 | + }); |
| 116 | + }); |
| 117 | +}); |
0 commit comments