From efac4648c2d123cbd145fcda9eb11d73aeddec81 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Thu, 19 Jan 2017 13:58:35 +0200 Subject: [PATCH] MAGETWO-54733: Unable to save product with all unchecked values for multiple select attribute #7687 --- .../Magento/Ui/base/js/form/client.test.js | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/form/client.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/form/client.test.js index 33b8c203a7164..89d8d4abdec4f 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/form/client.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/form/client.test.js @@ -12,7 +12,8 @@ define([ 'uiRegistry', 'Magento_Ui/js/form/client', 'jquery', - 'mageUtils' + 'mageUtils', + 'jquery/ui' ], function (_, registry, Constr, $, utils) { 'use strict'; @@ -78,8 +79,8 @@ define([ utils.filterFormData = jasmine.createSpy().and.returnValue(data); utils.serialize = jasmine.createSpy().and.returnValue(data); - $.ajax = jasmine.createSpy(); + $.ajax = jasmine.createSpy(); obj.save(data); expect(utils.filterFormData).toHaveBeenCalledWith(data); expect(utils.serialize).toHaveBeenCalledWith(data); @@ -93,6 +94,56 @@ define([ expect($.ajax).not.toHaveBeenCalled(); }); + it('Check call "beforeSave" method. Check "success" ajax callback with success response.' , function () { + var request; + + $.ajax = jasmine.createSpy().and.callFake(function (req) { + request = req.success; + }); + $.fn.notification = jasmine.createSpy(); + obj.urls.beforeSave = 'requestPath'; + obj.save(); + + expect(request({error: false})).toBe(true); + expect($('body').notification).not.toHaveBeenCalledWith('clear'); + }); + + it('Check call "beforeSave" method. Check "success" ajax callback with error response.' , function () { + var request, + notificationArguments; + + $.ajax = jasmine.createSpy().and.callFake(function (req) { + request = req.success; + }); + $.fn.notification = jasmine.createSpy(); + obj.urls.beforeSave = 'requestPath'; + obj.save(); + + notificationArguments = { + error: true, + message: 1, + insertMethod: jasmine.any(Function) + }; + + expect(request({ + error: true, + messages: [1] + })).toBeUndefined(); + expect($('body').notification.calls.allArgs()).toEqual([['clear'], ['add', notificationArguments]]); + }); + it('Check call "beforeSave" method. Check "complete" ajax callback with error response.' , function () { + var request; + + $.ajax = jasmine.createSpy().and.callFake(function (req) { + request = req.complete; + }); + $.fn.trigger = jasmine.createSpy(); + obj.urls.beforeSave = 'requestPath'; + obj.save(); + + expect(request()).toBeUndefined(); + expect($('body').trigger).toHaveBeenCalledWith('processStop'); + }); }); describe('"initialize" method', function () {