Get help with testing, discuss unit testing strategies etc.


Post by Mrfr0g »

This may be beyond the scope of this testing framework, but it's been working so well for my ExtJS projects I decided to try it out on some of my other ones. I am writing a plugin for a rich text editor, and I wanted to test selecting some text within the editor. The editor keeps it's content within an iframe, the typical structure looks like this.
<html>
   <body>
      <iframe>
         <html>
            <body>
               <p>
                  Content content content
               </p>
            </body>
         </html>
      </iframe>
   </body>
</html>
Here is my test case,
StartTest(function(t) {
   // Forgive my pseudo code here
   t.drag(editor.contentDocument.body.p, [50, 10], function () {
      t.is(testSelectionRange.myTextSelected, 'Text is selected');
   });
});
Instead of seeing the event fire on the contentDocument, I see that it's fired on the iFrame. Since the passed element's document originates on the iFrame's contentDocument, it would be ideal to see the event fired on that document. Alternatively I could see passing the document I wish to fire the event on, something like:
t.drag([0, 0], [50, 0], null, function () {
   t.is(testSelectionRange.myTextSelected, 'Text is selected');
}, editor.contentDocument);

Post by nickolay »

Hm.. Seems your goal is to select the text in editor - this is probably not supported by using mouse events simulation (drag). Text selection should be possible though, using a dedicated API, like:
t.selectText(el, startPos, endPos)
t.copyText()
t.pasteText()
Haven't checked if its supported by all browsers.

Post by mats »

There is some basic text selection support in TextSelection.js, copy/past requires flash addon IIRC.

Post by Mrfr0g »

I did see the text selection simulator, and for this specific case it will work. But what would happen if I fired a right click on the editor? Would it fire on the iframe or on the element contained within it's contentDocument?

Post by nickolay »

it will be fired exactly for the element you passed to `rightClick`. And it will not propagate through the iframe boundaries.

Post Reply