|
| 1 | +/** |
| 2 | + * Copyright 2014 Adobe |
| 3 | + * All Rights Reserved. |
| 4 | + */ |
| 5 | + |
| 6 | +define([ |
| 7 | + 'jquery', |
| 8 | + 'mage/adminhtml/form' |
| 9 | +], function ($) { |
| 10 | + 'use strict'; |
| 11 | + |
| 12 | + describe('mage/adminhtml/form', function () { |
| 13 | + var id = 'edit_form', |
| 14 | + elementId = '#' + id; |
| 15 | + |
| 16 | + beforeEach(function () { |
| 17 | + var element = $('<form id="' + id + '" action="action/url" method="GET" target="_self" ></form>'); |
| 18 | + |
| 19 | + element.appendTo('body'); |
| 20 | + }); |
| 21 | + afterEach(function () { |
| 22 | + $(elementId).remove(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should not enable inputs that have the disabled CSS class when dependencies are satisfied', function () { |
| 26 | + // Container that will be traversed with levels_up = 1 |
| 27 | + var container = document.createElement('div'); |
| 28 | + document.body.appendChild(container); |
| 29 | + |
| 30 | + // Target element (idTo) inside the container |
| 31 | + var target = document.createElement('input'); |
| 32 | + target.id = 'test_input_dependent'; |
| 33 | + container.appendChild(target); |
| 34 | + |
| 35 | + // Sibling input that carries CSS class "disabled" and is disabled initially |
| 36 | + var cssDisabled = document.createElement('input'); |
| 37 | + cssDisabled.id = 'css_disabled_input'; |
| 38 | + cssDisabled.className = 'disabled'; |
| 39 | + cssDisabled.disabled = true; |
| 40 | + container.appendChild(cssDisabled); |
| 41 | + |
| 42 | + // Another sibling input which is disabled initially but should be enabled after dependencies are met |
| 43 | + var normalInput = document.createElement('input'); |
| 44 | + normalInput.id = 'normal_input'; |
| 45 | + normalInput.disabled = true; |
| 46 | + container.appendChild(normalInput); |
| 47 | + |
| 48 | + // Dependency source element that satisfies the map |
| 49 | + var source = document.createElement('input'); |
| 50 | + source.id = 'dep_source'; |
| 51 | + source.value = '1'; |
| 52 | + document.body.appendChild(source); |
| 53 | + |
| 54 | + // Initialize controller with dependency that evaluates to true (shouldShowUp = true) |
| 55 | + /* eslint-disable no-new */ |
| 56 | + new window.FormElementDependenceController({ |
| 57 | + 'test_input_dependent': { |
| 58 | + 'dep_source': { values: ['1'] } |
| 59 | + } |
| 60 | + }, { |
| 61 | + levels_up: 1 |
| 62 | + }); |
| 63 | + /* eslint-enable no-new */ |
| 64 | + |
| 65 | + // The element with CSS class "disabled" must remain disabled |
| 66 | + expect(cssDisabled.disabled).toBe(true); |
| 67 | + // The normal input should be enabled because dependencies are satisfied |
| 68 | + expect(normalInput.disabled).toBe(false); |
| 69 | + |
| 70 | + // Cleanup |
| 71 | + document.body.removeChild(container); |
| 72 | + document.body.removeChild(source); |
| 73 | + }); |
| 74 | + }); |
| 75 | +}); |
0 commit comments