|
| 1 | +/*! |
| 2 | + * Jodit Editor (https://xdsoft.net/jodit/) |
| 3 | + * Released under MIT see LICENSE.txt in the project root for license information. |
| 4 | + * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net |
| 5 | + */ |
| 6 | + |
| 7 | +describe('Test UIButton', () => { |
| 8 | + const { UIButton } = Jodit.modules; |
| 9 | + |
| 10 | + let editor; |
| 11 | + beforeEach(() => { |
| 12 | + editor = getJodit(); |
| 13 | + }); |
| 14 | + |
| 15 | + describe('aria-label', () => { |
| 16 | + it('should set aria-label from tooltip when text is empty', () => { |
| 17 | + const button = new UIButton(editor); |
| 18 | + button.state.tooltip = 'Bold'; |
| 19 | + |
| 20 | + expect(button.button.getAttribute('aria-label')).eq('Bold'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should not set aria-label when text is provided', () => { |
| 24 | + const button = new UIButton(editor); |
| 25 | + button.state.text = 'Bold'; |
| 26 | + button.state.tooltip = 'Make text bold'; |
| 27 | + |
| 28 | + expect(button.button.getAttribute('aria-label')).is.null; |
| 29 | + }); |
| 30 | + |
| 31 | + it('should remove aria-label when text is set after tooltip', () => { |
| 32 | + const button = new UIButton(editor); |
| 33 | + button.state.tooltip = 'Bold'; |
| 34 | + |
| 35 | + expect(button.button.getAttribute('aria-label')).eq('Bold'); |
| 36 | + |
| 37 | + button.state.text = 'Bold'; |
| 38 | + |
| 39 | + expect(button.button.getAttribute('aria-label')).is.null; |
| 40 | + }); |
| 41 | + |
| 42 | + it('should restore aria-label when text is cleared', async () => { |
| 43 | + const button = new UIButton(editor); |
| 44 | + button.state.tooltip = 'Bold'; |
| 45 | + button.state.text = 'Bold'; |
| 46 | + |
| 47 | + expect(button.button.getAttribute('aria-label')).is.null; |
| 48 | + |
| 49 | + button.state.text = ''; |
| 50 | + |
| 51 | + await editor.async.requestIdlePromise(); |
| 52 | + expect(button.button.getAttribute('aria-label')).eq('Bold'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should not set aria-label when both text and tooltip are empty', () => { |
| 56 | + const button = new UIButton(editor); |
| 57 | + |
| 58 | + expect(button.button.getAttribute('aria-label')).is.null; |
| 59 | + }); |
| 60 | + }); |
| 61 | +}); |
0 commit comments