|
| 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 ProgressBar', () => { |
| 8 | + const { ProgressBar } = Jodit.modules; |
| 9 | + |
| 10 | + let editor; |
| 11 | + beforeEach(() => { |
| 12 | + editor = getJodit(); |
| 13 | + }); |
| 14 | + |
| 15 | + describe('show', () => { |
| 16 | + it('should append progress bar to workplace', () => { |
| 17 | + const bar = new ProgressBar(editor); |
| 18 | + bar.show(); |
| 19 | + expect(editor.workplace.contains(bar.container)).to.be.true; |
| 20 | + bar.destruct(); |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + describe('hide', () => { |
| 25 | + it('should remove progress bar from DOM', () => { |
| 26 | + const bar = new ProgressBar(editor); |
| 27 | + bar.show(); |
| 28 | + expect(editor.workplace.contains(bar.container)).to.be.true; |
| 29 | + bar.hide(); |
| 30 | + expect(editor.workplace.contains(bar.container)).to.be.false; |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + describe('progress', () => { |
| 35 | + it('should set container width as percentage', () => { |
| 36 | + const bar = new ProgressBar(editor); |
| 37 | + bar.show(); |
| 38 | + bar.progress(50); |
| 39 | + expect(bar.container.style.width).eq('50%'); |
| 40 | + bar.destruct(); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should return self for chaining', () => { |
| 44 | + const bar = new ProgressBar(editor); |
| 45 | + expect(bar.progress(10)).eq(bar); |
| 46 | + bar.destruct(); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + describe('destruct', () => { |
| 51 | + it('should remove progress bar from DOM on destruct', () => { |
| 52 | + const bar = new ProgressBar(editor); |
| 53 | + bar.show(); |
| 54 | + expect(editor.workplace.contains(bar.container)).to.be.true; |
| 55 | + bar.destruct(); |
| 56 | + expect(editor.workplace.contains(bar.container)).to.be.false; |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + describe('showFileUploadAnimation', () => { |
| 61 | + const sel = '.jodit-progress-bar__file-animation'; |
| 62 | + |
| 63 | + it('should create animation element in DOM', () => { |
| 64 | + const bar = new ProgressBar(editor); |
| 65 | + bar.showFileUploadAnimation(); |
| 66 | + |
| 67 | + expect(document.querySelector(sel)).is.not.null; |
| 68 | + bar.destruct(); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should contain an SVG icon inside animation element', () => { |
| 72 | + const bar = new ProgressBar(editor); |
| 73 | + bar.showFileUploadAnimation(); |
| 74 | + |
| 75 | + const svg = document.querySelector(sel + ' svg'); |
| 76 | + expect(svg).is.not.null; |
| 77 | + bar.destruct(); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should apply position based on editor container rect', () => { |
| 81 | + const bar = new ProgressBar(editor); |
| 82 | + const rect = editor.container.getBoundingClientRect(); |
| 83 | + bar.showFileUploadAnimation({ x: 100, y: 50 }); |
| 84 | + |
| 85 | + const animEl = document.querySelector(sel); |
| 86 | + // End position = rect offset + to (default to = from + 60, from - 80) |
| 87 | + expect(animEl.style.left).eq(rect.left + 160 + 'px'); |
| 88 | + expect(animEl.style.top).eq(rect.top + -30 + 'px'); |
| 89 | + bar.destruct(); |
| 90 | + }); |
| 91 | + |
| 92 | + it('should use custom from and to positions', () => { |
| 93 | + const bar = new ProgressBar(editor); |
| 94 | + const rect = editor.container.getBoundingClientRect(); |
| 95 | + bar.showFileUploadAnimation({ x: 10, y: 20 }, { x: 200, y: 300 }); |
| 96 | + |
| 97 | + const animEl = document.querySelector(sel); |
| 98 | + expect(animEl.style.left).eq(rect.left + 200 + 'px'); |
| 99 | + expect(animEl.style.top).eq(rect.top + 300 + 'px'); |
| 100 | + bar.destruct(); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should set opacity to 0 for fade out', () => { |
| 104 | + const bar = new ProgressBar(editor); |
| 105 | + bar.showFileUploadAnimation(); |
| 106 | + |
| 107 | + const animEl = document.querySelector(sel); |
| 108 | + expect(animEl.style.opacity).eq('0'); |
| 109 | + bar.destruct(); |
| 110 | + }); |
| 111 | + |
| 112 | + it('should remove animation element on destruct', () => { |
| 113 | + const bar = new ProgressBar(editor); |
| 114 | + bar.showFileUploadAnimation(); |
| 115 | + |
| 116 | + expect(document.querySelector(sel)).is.not.null; |
| 117 | + bar.destruct(); |
| 118 | + expect(document.querySelector(sel)).is.null; |
| 119 | + }); |
| 120 | + |
| 121 | + it('should remove previous animation if called again', () => { |
| 122 | + const bar = new ProgressBar(editor); |
| 123 | + bar.showFileUploadAnimation(); |
| 124 | + bar.showFileUploadAnimation(); |
| 125 | + |
| 126 | + expect(document.querySelectorAll(sel).length).eq(1); |
| 127 | + bar.destruct(); |
| 128 | + }); |
| 129 | + |
| 130 | + it('should remove element after transitionend event', () => { |
| 131 | + const bar = new ProgressBar(editor); |
| 132 | + bar.showFileUploadAnimation(); |
| 133 | + |
| 134 | + const animEl = document.querySelector(sel); |
| 135 | + expect(animEl).is.not.null; |
| 136 | + |
| 137 | + animEl.dispatchEvent(new Event('transitionend')); |
| 138 | + |
| 139 | + expect(document.querySelector(sel)).is.null; |
| 140 | + bar.destruct(); |
| 141 | + }); |
| 142 | + }); |
| 143 | +}); |
0 commit comments