|
| 1 | +/************************************************************************ |
| 2 | + * |
| 3 | + * Copyright 2024 Adobe |
| 4 | + * All Rights Reserved. |
| 5 | + * |
| 6 | + * NOTICE: All information contained herein is, and remains |
| 7 | + * the property of Adobe and its suppliers, if any. The intellectual |
| 8 | + * and technical concepts contained herein are proprietary to Adobe |
| 9 | + * and its suppliers and are protected by all applicable intellectual |
| 10 | + * property laws, including trade secret and copyright laws. |
| 11 | + * Dissemination of this information or reproduction of this material |
| 12 | + * is strictly forbidden unless prior written permission is obtained |
| 13 | + * from Adobe. |
| 14 | + * ************************************************************************ |
| 15 | + */ |
| 16 | + |
| 17 | +/* eslint-disable max-nested-callbacks */ |
| 18 | +define([ |
| 19 | + 'Magento_PageBuilder/js/form/element/html', |
| 20 | +], function (HtmlUiElement) { |
| 21 | + 'use strict'; |
| 22 | + |
| 23 | + describe('Magento_PageBuilder/js/form/element/html', function () { |
| 24 | + var model, |
| 25 | + htmlContainer, |
| 26 | + formId = 'form-' + Date.now(); |
| 27 | + |
| 28 | + function addNewElement(name, value) { |
| 29 | + var newElement = document.createElement('li'), |
| 30 | + inputElement = document.createElement('input'); |
| 31 | + |
| 32 | + inputElement.setAttribute('name', name); |
| 33 | + inputElement.setAttribute('type', 'hidden'); |
| 34 | + inputElement.setAttribute('data-form-part', formId); |
| 35 | + inputElement.value = value; |
| 36 | + newElement.appendChild(inputElement); |
| 37 | + htmlContainer.appendChild(newElement); |
| 38 | + model.elements.push(inputElement); |
| 39 | + return inputElement; |
| 40 | + } |
| 41 | + |
| 42 | + beforeEach(function () { |
| 43 | + model = new HtmlUiElement({inputSelector: '[data-form-part=' + formId + ']'}); |
| 44 | + htmlContainer = document.createElement('ul'); |
| 45 | + document.body.appendChild(htmlContainer); |
| 46 | + }); |
| 47 | + |
| 48 | + afterEach(function () { |
| 49 | + document.body.removeChild(htmlContainer); |
| 50 | + model = null; |
| 51 | + htmlContainer = null; |
| 52 | + }); |
| 53 | + |
| 54 | + describe('"updateValue" method', function () { |
| 55 | + it('Should collect all inputs values', function () { |
| 56 | + var param1, param2; |
| 57 | + |
| 58 | + model.updateValue(); |
| 59 | + expect(model.value()).toEqual({}); |
| 60 | + param1 = addNewElement('param1', 'value1'); |
| 61 | + model.updateValue(); |
| 62 | + expect(model.value()).toEqual({param1: 'value1'}); |
| 63 | + param2 = addNewElement('param2', 'value2'); |
| 64 | + model.updateValue(); |
| 65 | + expect(model.value()).toEqual({param1: 'value1', param2: 'value2'}); |
| 66 | + param2.value = 'value22'; |
| 67 | + model.updateValue(); |
| 68 | + expect(model.value()).toEqual({param1: 'value1', param2: 'value22'}); |
| 69 | + param1.remove(); |
| 70 | + model.updateValue(); |
| 71 | + expect(model.value()).toEqual({param2: 'value22'}); |
| 72 | + }); |
| 73 | + }); |
| 74 | + }); |
| 75 | +}); |
0 commit comments