writing helps thinking.. ;)

test should look like this:

    testMouseEvents: function() { with(this) {
      // mouse over
      var currentElement = $$('.user').first().down('td')
      Event.simulateMouse(currentElement, 'mouseover');
      assertIdentical( currentElement.up('tr').getStyle('background'),
'rgb(255, 165, 0)')
      // mouse click
      var uppdateElement = $('single_view')
      Event.simulateMouse(currentElement, 'click'); 
      assertIdentical( uppdateElement.down('h3').innerHTML,
'click')
      // mouse out
      Event.simulateMouse(currentElement, 'mouseout'); 
      assertIdentical( currentElement.up('tr').getStyle('background'),
'')
    }},

kalle



On 15 Apr., 13:11, kalle <[EMAIL PROTECTED]> wrote:
> Hey guys,
> i am just getting started with unit testing in javascript, and i not
> sure how to test the mouse events of my class.
> Here is an excample of what i trie do accomplishe:
>
> the class:
>
> var Finder =  Class.create({
>   initialize: function(rowElements) {
>     this.rowElements      = $$(rowElements)
>     this.addObservers();
>   },
>   addObservers: function(element) {
>     this.rowElements
>                     .invoke('observe', 'mouseover',
> this.onHover.bindAsEventListener(this))
>                       .invoke('observe', 'click',
> this.onClick.bindAsEventListener(this))
>                         .invoke('observe', 'mouseout',
> this.onBlur.bindAsEventListener(this));
>   },
>   onHover: function(event) {
>     this.currentElement = Event.element(event).up('tr');
>     this.currentElement.setStyle({backgroundColor: '#FFA500',
> cursor:"pointer"})
>   },
>   onClick: function(event) {
>   },
>   onBlur: function(event) {
>     this.currentElement.setStyle({backgroundColor: '', cursor:"auto"})
>   }
>
> });
>
> and thats my test:
>
>     // Mous over
>     testMousOver: function() { with(this) {
>       var currentElement = $$('.user').first()
>       currentElement.observe('mouseover', function()
> { this.setStyle({background: '#FFA500' }) });
>       Event.simulateMouse(currentElement, 'mouseover');
>       assertIdentical( currentElement.getStyle('background'),
> 'rgb(255, 165, 0)')
>     }},
>
> but that's actually doesn't test my finder class at all, how could i
> do that ??
> thanks for advice
>
> kalle
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to