diff --git a/dev/tests/js/jasmine/tests/lib/mage/form.test.js b/dev/tests/js/jasmine/tests/lib/mage/form.test.js index 6202f93da999a..275fdc4fabf6f 100644 --- a/dev/tests/js/jasmine/tests/lib/mage/form.test.js +++ b/dev/tests/js/jasmine/tests/lib/mage/form.test.js @@ -11,252 +11,224 @@ define([ ], function ($) { 'use strict'; - /* - * jQuery ui version 1.9.2 belongs to the adminhtml. - * - * This test will fail on frontend since mage/backend/form only belongs to backend. - */ - if ($.ui.version === '1.9.2') { - describe('Test for mage/form jQuery plugin', function () { - var id = 'edit_form', - elementId = '#' + id; + describe('Test for mage/form jQuery plugin', function () { + var id = 'edit_form', + elementId = '#' + id; - beforeEach(function () { - var element = $('
'); + beforeEach(function () { + var element = $(''); - element.appendTo('body'); - }); - - afterEach(function () { - $(elementId).remove(); - }); + element.appendTo('body'); + }); + afterEach(function () { + $(elementId).remove(); + }); + it('check if form can be initialized', function () { + var form = $(elementId).form(); - it('check if form can be initialized', function () { - var form = $(elementId).form(); + expect(form.is(':mage-form')).toBeTruthy(); + }); + it('check get handlers', function () { + var form = $(elementId).form(), + handlersData = form.form('option', 'handlersData'), + handlers = []; - expect(form.is(':mage-form')).toBeTruthy(); + $.each(handlersData, function (key) { + handlers.push(key); }); - - it('check get handlers', function () { - var form = $(elementId).form(), - handlersData = form.form('option', 'handlersData'), - handlers = []; - - $.each(handlersData, function (key) { - handlers.push(key); - }); - expect(handlers.join(' ')).toBe(form.data('form')._getHandlers().join(' ')); + expect(handlers.join(' ')).toBe(form.data('mageForm')._getHandlers().join(' ')); + }); + it('check store attribute', function () { + var form = $(elementId).form(), + initialFormAttrs = { + action: form.attr('action'), + target: form.attr('target'), + method: form.attr('method') + }; + + form.data('mageForm')._storeAttribute('action'); + form.data('mageForm')._storeAttribute('target'); + form.data('mageForm')._storeAttribute('method'); + expect(form.data('mageForm').oldAttributes.action).toBe(initialFormAttrs.action); + expect(form.data('mageForm').oldAttributes.target).toBe(initialFormAttrs.target); + expect(form.data('mageForm').oldAttributes.method).toBe(initialFormAttrs.method); + }); + it('check bind', function () { + var form = $(elementId).form(), + submitted = false, + handlersData = form.form('option', 'handlersData'); + + form.on('submit', function (e) { + submitted = true; + e.stopImmediatePropagation(); + e.preventDefault(); }); - - it('check store attribute', function () { - var form = $(elementId).form(), - initialFormAttrs = { - action: form.attr('action'), - target: form.attr('target'), - method: form.attr('method') - }; - - form.data('form')._storeAttribute('action'); - form.data('form')._storeAttribute('target'); - form.data('form')._storeAttribute('method'); - - expect(form.data('form').oldAttributes.action).toBe(initialFormAttrs.action); - expect(form.data('form').oldAttributes.target).toBe(initialFormAttrs.target); - expect(form.data('form').oldAttributes.method).toBe(initialFormAttrs.method); + $.each(handlersData, function (key) { + form.trigger(key); + expect(submitted).toBeTruthy(); + submitted = false; }); - - it('check bind', function () { - var form = $(elementId).form(), - submitted = false, - handlersData = form.form('option', 'handlersData'); - - form.on('submit', function (e) { - submitted = true; - e.stopImmediatePropagation(); - e.preventDefault(); - }); - - $.each(handlersData, function (key) { - form.trigger(key); - expect(submitted).toBeTruthy(); - submitted = false; - }); - - form.off('submit'); - }); - - it('check get action URL', function () { - var form = $(elementId).form(), - action = form.attr('action'), - testUrl = 'new/action/url', - testArgs = { + form.off('submit'); + }); + it('check get action URL', function () { + var form = $(elementId).form(), + action = form.attr('action'), + testUrl = 'new/action/url', + testArgs = { + args: { + arg: 'value' + } + }; + + form.data('mageForm')._storeAttribute('action'); + expect(form.data('mageForm')._getActionUrl(testArgs)).toBe(action + '/arg/value/'); + expect(form.data('mageForm')._getActionUrl(testUrl)).toBe(testUrl); + expect(form.data('mageForm')._getActionUrl()).toBe(action); + }); + it('check process data', function () { + var form = $(elementId).form(), + initialFormAttrs = { + action: form.attr('action'), + target: form.attr('target'), + method: form.attr('method') + }, + testSimpleData = { + action: 'new/action/url', + target: '_blank', + method: 'POST' + }, + testActionArgsData = { + action: { args: { arg: 'value' } - }; - - form.data('form')._storeAttribute('action'); - expect(form.data('form')._getActionUrl(testArgs)).toBe(action + '/arg/value/'); - expect(form.data('form')._getActionUrl(testUrl)).toBe(testUrl); - expect(form.data('form')._getActionUrl()).toBe(action); - }); - - it('check process data', function () { - var form = $(elementId).form(), - initialFormAttrs = { - action: form.attr('action'), - target: form.attr('target'), - method: form.attr('method') - }, - testSimpleData = { - action: 'new/action/url', - target: '_blank', - method: 'POST' - }, - testActionArgsData = { - action: { - args: { - arg: 'value' - } - } - }, - processedData = form.data('form')._processData(testSimpleData); - - expect(form.data('form').oldAttributes.action).toBe(initialFormAttrs.action); - expect(form.data('form').oldAttributes.target).toBe(initialFormAttrs.target); - expect(form.data('form').oldAttributes.method).toBe(initialFormAttrs.method); - expect(processedData.action).toBe(testSimpleData.action); - expect(processedData.target).toBe(testSimpleData.target); - expect(processedData.method).toBe(testSimpleData.method); - - form.data('form')._rollback(); - processedData = form.data('form')._processData(testActionArgsData); - form.data('form')._storeAttribute('action'); - expect(processedData.action).toBe(form.data('form')._getActionUrl(testActionArgsData.action)); - }); - - it('check before submit', function () { - var testForm = $('').appendTo('body'), - testHandler = { - action: { - args: { - arg1: 'value1' - } + } + }, + processedData = form.data('mageForm')._processData(testSimpleData); + + expect(form.data('mageForm').oldAttributes.action).toBe(initialFormAttrs.action); + expect(form.data('mageForm').oldAttributes.target).toBe(initialFormAttrs.target); + expect(form.data('mageForm').oldAttributes.method).toBe(initialFormAttrs.method); + expect(processedData.action).toBe(testSimpleData.action); + expect(processedData.target).toBe(testSimpleData.target); + expect(processedData.method).toBe(testSimpleData.method); + form.data('mageForm')._rollback(); + processedData = form.data('mageForm')._processData(testActionArgsData); + form.data('mageForm')._storeAttribute('action'); + expect(processedData.action).toBe(form.data('mageForm')._getActionUrl(testActionArgsData.action)); + }); + it('check before submit', function () { + var testForm = $('').appendTo('body'), + testHandler = { + action: { + args: { + arg1: 'value1' } - }, - form = $(elementId).form({ - handlersData: { - testHandler: testHandler + } + }, + form = $(elementId).form({ + handlersData: { + testHandler: testHandler + } + }), + beforeSubmitData = { + action: { + args: { + arg2: 'value2' } - }), - beforeSubmitData = { - action: { - args: { - arg2: 'value2' - } - }, - target: '_blank' }, - eventData = { - method: 'POST' - }, - resultData = $.extend(true, {}, testHandler, beforeSubmitData, eventData); - - form.data('form')._storeAttribute('action'); - resultData = form.data('form')._processData(resultData); - testForm.prop(resultData); - - form.on('beforeSubmit', function (e, data) { - $.extend(data, beforeSubmitData); - }); - - form.on('submit', function (e) { - e.stopImmediatePropagation(); - e.preventDefault(); - }); - - form.data('form')._beforeSubmit('testHandler', eventData); - expect(testForm.prop('action')).toBe(form.prop('action')); - expect(testForm.prop('target')).toBe(form.prop('target')); - expect(testForm.prop('method')).toBe(form.prop('method')); - }); - - it('check submit', function () { - var formSubmitted = false, - form = $(elementId).form({ - handlersData: { - save: {} - } - }); - - form.data('form')._storeAttribute('action'); - form.data('form')._storeAttribute('target'); - form.data('form')._storeAttribute('method'); - - form.on('submit', function (e) { - e.preventDefault(); - e.stopImmediatePropagation(); - e.preventDefault(); - formSubmitted = true; - }).prop({ - action: 'new/action/url', - target: '_blank', + target: '_blank' + }, + eventData = { method: 'POST' + }, + resultData = $.extend(true, {}, testHandler, beforeSubmitData, eventData); + + form.data('mageForm')._storeAttribute('action'); + resultData = form.data('mageForm')._processData(resultData); + testForm.prop(resultData); + form.on('beforeSubmit', function (e, data) { + $.extend(data, beforeSubmitData); + }); + form.on('submit', function (e) { + e.stopImmediatePropagation(); + e.preventDefault(); + }); + form.data('mageForm')._beforeSubmit('testHandler', eventData); + expect(testForm.prop('action')).toBe(form.prop('action')); + expect(testForm.prop('target')).toBe(form.prop('target')); + expect(testForm.prop('method')).toBe(form.prop('method')); + }); + it('check submit', function () { + var formSubmitted = false, + form = $(elementId).form({ + handlersData: { + save: {} + } }); - form.data('form')._submit({ - type: 'save' - }); - - expect(form.attr('action')).toBe(form.data('form').oldAttributes.action); - expect(form.attr('target')).toBe(form.data('form').oldAttributes.target); - expect(form.attr('method')).toBe(form.data('form').oldAttributes.method); - expect(formSubmitted).toBeTruthy(); - - form.off('submit'); + form.data('mageForm')._storeAttribute('action'); + form.data('mageForm')._storeAttribute('target'); + form.data('mageForm')._storeAttribute('method'); + form.on('submit', function (e) { + e.preventDefault(); + e.stopImmediatePropagation(); + e.preventDefault(); + formSubmitted = true; + }).prop({ + action: 'new/action/url', + target: '_blank', + method: 'POST' }); - - it('check build URL', function () { - var dataProvider = [ - { - params: ['http://domain.com//', { - 'key[one]': 'value 1', - 'key2': '# value' - }], - expected: 'http://domain.com/key[one]/value%201/key2/%23%20value/' - }, - { - params: ['http://domain.com', { - 'key[one]': 'value 1', - 'key2': '# value' - }], - expected: 'http://domain.com/key[one]/value%201/key2/%23%20value/' - }, - { - params: ['http://domain.com?some=param', { - 'key[one]': 'value 1', - 'key2': '# value' - }], - expected: 'http://domain.com?some=param&key[one]=value%201&key2=%23%20value' - }, - { - params: ['http://domain.com?some=param&', { - 'key[one]': 'value 1', - 'key2': '# value' - }], - expected: 'http://domain.com?some=param&key[one]=value%201&key2=%23%20value' - } - ], - method = $.mage.form._proto._buildURL, - quantity = dataProvider.length, - i = 0; - - expect(quantity).toBeTruthy(); - - for (i; i < quantity; i++) { - expect(dataProvider[i].expected).toBe(method.apply(null, dataProvider[i].params)); - } + form.data('mageForm')._submit({ + type: 'save' }); + expect(form.attr('action')).toBe(form.data('mageForm').oldAttributes.action); + expect(form.attr('target')).toBe(form.data('mageForm').oldAttributes.target); + expect(form.attr('method')).toBe(form.data('mageForm').oldAttributes.method); + expect(formSubmitted).toBeTruthy(); + form.off('submit'); + }); + it('check build URL', function () { + var dataProvider = [ + { + params: ['http://domain.com//', { + 'key[one]': 'value 1', + 'key2': '# value' + }], + expected: 'http://domain.com/key[one]/value%201/key2/%23%20value/' + }, + { + params: ['http://domain.com', { + 'key[one]': 'value 1', + 'key2': '# value' + }], + expected: 'http://domain.com/key[one]/value%201/key2/%23%20value/' + }, + { + params: ['http://domain.com?some=param', { + 'key[one]': 'value 1', + 'key2': '# value' + }], + expected: 'http://domain.com?some=param&key[one]=value%201&key2=%23%20value' + }, + { + params: ['http://domain.com?some=param&', { + 'key[one]': 'value 1', + 'key2': '# value' + }], + expected: 'http://domain.com?some=param&key[one]=value%201&key2=%23%20value' + } + ], + method = $.mage.form._proto._buildURL, + quantity = dataProvider.length, + i = 0; + + expect(quantity).toBeTruthy(); + + for (i; i < quantity; i++) { + expect(dataProvider[i].expected).toBe(method.apply(null, dataProvider[i].params)); + } }); - } + }); }); diff --git a/dev/tests/js/jasmine/tests/lib/mage/translate-inline.test.js b/dev/tests/js/jasmine/tests/lib/mage/translate-inline.test.js index 7c5e6599038b8..0a4ea4504ba34 100644 --- a/dev/tests/js/jasmine/tests/lib/mage/translate-inline.test.js +++ b/dev/tests/js/jasmine/tests/lib/mage/translate-inline.test.js @@ -80,7 +80,7 @@ define([ }, expectedEequestData = 'area=test&test=test', translateInline = $(translateSelector).translateInline(options), - $submitButton = $('body').find('.action-primary'), + $submitButton = $('.action-primary:contains(\'Submit\')'), originalAjax = $.ajax; $.ajax = jasmine.createSpy().and.callFake(function (request) { diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/words_ce.xml b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/words_ce.xml index 5d6bd40a920a2..5c393b5bdea96 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/words_ce.xml +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/words_ce.xml @@ -104,5 +104,9 @@