|
| 1 | +/** |
| 2 | + * |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +/* eslint-disable max-nested-callbacks */ |
| 8 | +define([ |
| 9 | + 'squire' |
| 10 | +], function (Squire) { |
| 11 | + 'use strict'; |
| 12 | + |
| 13 | + var injector = new Squire(), |
| 14 | + mocks = { |
| 15 | + 'Magento_PageBuilder/js/events': jasmine.createSpyObj('events',['on', 'trigger']), |
| 16 | + 'Magento_PageBuilder/js/page-builder': function () {} |
| 17 | + }, |
| 18 | + wysiwyg, |
| 19 | + $; |
| 20 | + |
| 21 | + beforeEach(function (done) { |
| 22 | + injector.mock(mocks); |
| 23 | + injector.require(['Magento_PageBuilder/js/form/element/wysiwyg', 'jquery'], function (UiWysiwyg, jq) { |
| 24 | + var MockWysiwyg = function () {}; |
| 25 | + |
| 26 | + MockWysiwyg.prototype = Object.create(UiWysiwyg.prototype); |
| 27 | + MockWysiwyg.prototype.constructor = MockWysiwyg; |
| 28 | + wysiwyg = new MockWysiwyg(); |
| 29 | + $ = jq; |
| 30 | + $.extend(wysiwyg, UiWysiwyg.defaults, {pageBuilder: {id: 'pb-wysiwyg-test'}}); |
| 31 | + $(document.body).append( |
| 32 | + $('<div><div contenteditable="true"><a href="/login"></a><span tabindex="0"></span></div></div>') |
| 33 | + .attr('id', wysiwyg.pageBuilder.id) |
| 34 | + ); |
| 35 | + done(); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + afterEach(function () { |
| 40 | + try { |
| 41 | + injector.clean(); |
| 42 | + injector.remove(); |
| 43 | + } catch (e) {} |
| 44 | + $('#' + wysiwyg.pageBuilder.id).remove(); |
| 45 | + }); |
| 46 | + |
| 47 | + describe('Magento_PageBuilder/js/form/element/wysiwyg', function () { |
| 48 | + describe('toggleFocusableElements', function () { |
| 49 | + it('Should restore tabindex and contenteditable in fullscreen mode', function () { |
| 50 | + var $div = $('#' + wysiwyg.pageBuilder.id); |
| 51 | + |
| 52 | + wysiwyg.pageBuilder.isFullScreen = jasmine.createSpy().and.returnValue(false); |
| 53 | + wysiwyg.toggleFocusableElements(); |
| 54 | + expect($div.find('a').attr('tabindex')).toBe('-1'); |
| 55 | + expect($div.find('a').data('original-tabindex')).toBe(''); |
| 56 | + expect($div.find('span').attr('tabindex')).toBe('-1'); |
| 57 | + expect($div.find('span').data('original-tabindex')).toBe('0'); |
| 58 | + expect($div.find('[contenteditable]').attr('contenteditable')).toBe('false'); |
| 59 | + |
| 60 | + // check full screen mode |
| 61 | + wysiwyg.pageBuilder.isFullScreen = jasmine.createSpy().and.returnValue(true); |
| 62 | + wysiwyg.toggleFocusableElements(); |
| 63 | + // check that taindex is removed from "a" |
| 64 | + expect($div.find('a').attr('tabindex')).toBe(undefined); |
| 65 | + expect($div.find('a').data('original-tabindex')).toBe(undefined); |
| 66 | + // check that taindex is restored for "span" |
| 67 | + expect($div.find('span').attr('tabindex')).toBe('0'); |
| 68 | + expect($div.find('span').data('original-tabindex')).toBe(undefined); |
| 69 | + expect($div.find('[contenteditable]').attr('contenteditable')).toBe('true'); |
| 70 | + }); |
| 71 | + }); |
| 72 | + }); |
| 73 | +}); |
0 commit comments