|
| 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 | + 'jquery', |
| 10 | + 'Magento_PageBuilder/js/form/element/wysiwyg' |
| 11 | +], function ($, UiWysiwyg) { |
| 12 | + 'use strict'; |
| 13 | + |
| 14 | + var wysiwyg; |
| 15 | + |
| 16 | + function createWysiwygMock() { |
| 17 | + var mock, |
| 18 | + MockWysiwyg = function () {}; |
| 19 | + |
| 20 | + MockWysiwyg.prototype = Object.create(UiWysiwyg.prototype); |
| 21 | + MockWysiwyg.prototype.constructor = MockWysiwyg; |
| 22 | + mock = new MockWysiwyg(); |
| 23 | + $.extend(mock, UiWysiwyg.defaults); |
| 24 | + return mock; |
| 25 | + } |
| 26 | + |
| 27 | + beforeEach(function () { |
| 28 | + wysiwyg = createWysiwygMock(); |
| 29 | + wysiwyg.pageBuilder = {id: 'pb-wysiwyg-test'}; |
| 30 | + $(document.body).append( |
| 31 | + $('<div><div contenteditable="true"><a href="/login"></a><span tabindex="0"></span></div></div>') |
| 32 | + .attr('id', wysiwyg.pageBuilder.id) |
| 33 | + ); |
| 34 | + }); |
| 35 | + |
| 36 | + afterEach(function () { |
| 37 | + $('#' + wysiwyg.pageBuilder.id).remove(); |
| 38 | + }); |
| 39 | + |
| 40 | + describe('Magento_PageBuilder/js/form/element/wysiwyg', function () { |
| 41 | + describe('toggleFocusableElements', function () { |
| 42 | + it('Should restore tabindex and contenteditable in fullscreen mode', function () { |
| 43 | + var $div = $('#' + wysiwyg.pageBuilder.id); |
| 44 | + |
| 45 | + wysiwyg.pageBuilder.isFullScreen = jasmine.createSpy().and.returnValue(false); |
| 46 | + wysiwyg.toggleFocusableElements(); |
| 47 | + expect($div.find('a').attr('tabindex')).toBe('-1'); |
| 48 | + expect($div.find('a').data('original-tabindex')).toBe(''); |
| 49 | + expect($div.find('span').attr('tabindex')).toBe('-1'); |
| 50 | + expect($div.find('span').data('original-tabindex')).toBe('0'); |
| 51 | + expect($div.find('[contenteditable]').attr('contenteditable')).toBe('false'); |
| 52 | + |
| 53 | + // check full screen mode |
| 54 | + wysiwyg.pageBuilder.isFullScreen = jasmine.createSpy().and.returnValue(true); |
| 55 | + wysiwyg.toggleFocusableElements(); |
| 56 | + // check that taindex is removed from "a" |
| 57 | + expect($div.find('a').attr('tabindex')).toBe(undefined); |
| 58 | + expect($div.find('a').data('original-tabindex')).toBe(undefined); |
| 59 | + // check that taindex is restored for "span" |
| 60 | + expect($div.find('span').attr('tabindex')).toBe('0'); |
| 61 | + expect($div.find('span').data('original-tabindex')).toBe(undefined); |
| 62 | + expect($div.find('[contenteditable]').attr('contenteditable')).toBe('true'); |
| 63 | + }); |
| 64 | + }); |
| 65 | + }); |
| 66 | +}); |
0 commit comments