MCPcopy
hub / github.com/yabwe/medium-editor / runAddTest

Function runAddTest

spec/dyn-elements.spec.js:130–186  ·  view source on GitHub ↗
(inputSupported)

Source from the content-addressed store, hash-verified

128 });
129
130 function runAddTest(inputSupported) {
131 it('should re-attach element properly when removed from dom, cleaned up and injected to dom again', function () {
132 var originalInputSupport = MediumEditor.Events.prototype.InputEventOnContenteditableSupported;
133 MediumEditor.Events.prototype.InputEventOnContenteditableSupported = inputSupported;
134
135 var editor = this.newMediumEditor('.editor'),
136 focusedEditable,
137 firedTarget,
138 firedCounter,
139 handler = function (event, editable) {
140 firedTarget = editable;
141 firedCounter++;
142 },
143 focusListener = function (event, editable) {
144 focusedEditable = editable;
145 };
146
147 firedCounter = 0;
148
149 editor.subscribe('focus', focusListener);
150 editor.subscribe('editableInput', handler);
151
152 editor.addElements(this.addOne);
153 expect(this.addOne.getAttribute('data-medium-editor-element')).toBeDefined();
154 expect(editor.elements.length).toBe(2);
155
156 // Detach + exec fn + reattach, asynchronous.
157 detach(this.addOne, true, function (reattach) {
158 editor.removeElements(this.addOne);
159 expect(editor.elements.length).toBe(1);
160
161 reattach();
162
163 editor.addElements(this.addTwo);
164 expect(editor.elements.length).toBe(2);
165 expect(this.addTwo.getAttribute('data-medium-editor-element')).toBeDefined();
166
167 editor.selectElement(this.addTwo.firstChild);
168 expect(focusedEditable).toBe(this.addTwo);
169
170 editor.selectElement(this.addTwo.firstChild);
171 this.addTwo.textContent = 'lore ipsum!';
172
173 // trigger onInput
174 fireEvent(this.addTwo, 'input');
175
176 // trigger faked 'selectionchange' event
177 fireEvent(document, 'selectionchange', { target: document, currentTarget: this.addTwo });
178
179 jasmine.clock().tick(1);
180 expect(firedTarget).toBe(this.addTwo);
181 expect(firedCounter).toBe(1);
182
183 MediumEditor.Events.prototype.InputEventOnContenteditableSupported = originalInputSupport;
184 }.bind(this));
185 });
186 }
187

Callers 1

Calls 3

detachFunction · 0.85
reattachFunction · 0.85
fireEventFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…