[OpenLayers-Dev] Testing
Andreas Hocevar
ahocevar at opengeo.org
Thu May 23 15:31:26 PDT 2013
But the real problem is that the clientX and clientY in your mock events is
relative to the map viewport, but should be relative to the browser
viewport. You'll need to use OpenLayers.Util.pagePosition to get the
position of the map's viewportDiv and add that to the pixel coordinate you
are currently using.
Andreas.
On Thu, May 23, 2013 at 5:20 PM, Andreas Hocevar <ahocevar at opengeo.org>wrote:
> Right now you are calling logEvent() once, and you're doing so when
> you define the listener:
>
> map.events.on({featureclick: logEvent()});
>
> Instead, this should read
>
> map.events.on({featureclick: logEvent});
>
> Andreas.
>
> On Thu, May 23, 2013 at 4:30 PM, Michael Ryan <mr at mry4n.net> wrote:
> > I checked that out, but that didn't seem to be it. I noticed in
> > buttonclick.html that it just uses onload=init() in the body tag and
> doesn't
> > call init() in any of the test functions.
> >
> > However, it seems ilke I have to add the featureclick event and assign
> it a
> > function with parantheses, whereas running it in the html requires no
> > parentheses.
> >
> > So the test function now looks like this:
> >
> > function test_onClick23(t) {
> > t.plan(1);
> > logevt = [];
> > map.events.on({featureclick: logEvent()});
> > events = map.events;
> > lonlat = new OpenLayers.LonLat(0,0);
> > pixel = map.getPixelFromLonLat(lonlat);
> > trigger('mousedown', pixel);
> > trigger('mouseup', pixel);
> > t.eq(logevt.length, 2, "testing log length");
> > t.wait_result( 3 );
> > }
> >
> > and the logEvent function is:
> >
> > function logEvent(e) {
> >
> > //alert("Does this happen?");
> > logevt.push(e);
> > }
> >
> >
> https://github.com/m1k3ry4n/openlayers/blob/master/tests/Events/featureclick.html
> >
> > The problem is that no matter how many features I add, the logevt array
> is
> > length 1.
> >
> > I tried using the t.wait_result() function, taking a wild stab that
> since a
> > featureclick event gets fired for each feature that maybe there's some
> > timing issue that gets taken care of when you view featureclick.html but
> > needs to be accounted for in testing. Unfortunately, t.wait_result()
> didn't
> > change anything.
> >
> > -Mike
> >
> > On May 23, 2013, at 3:26 PM, Andreas Hocevar <ahocevar at opengeo.org>
> wrote:
> >
> > I think the problem is that your init() function won't be called when the
> > page is loaded by the test runner. So you'll have to call init() from the
> > test function (test_onClick12 in the current code).
> >
> > Andreas.
> >
> >
> > On Thu, May 23, 2013 at 12:33 PM, Michael Ryan <mr at mry4n.net> wrote:
> >>
> >> Thanks for all the help, Andreas.
> >>
> >> I'm pretty sure I can figure the contrib stuff out.
> >>
> >> At the moment, I'm hitting a wall with why a very simple test works if I
> >> just run the featureclick.html page, but not when I run the test
> function:
> >>
> >>
> >>
> https://github.com/m1k3ry4n/openlayers/blob/master/tests/Events/featureclick.html
> >>
> >> When I run the html page the logevt array has length 2. In the test,
> it's
> >> length 0. Yet I'm running the exact same code.
> >>
> >> I know this is taking a while and I may be missing the 2.13 deadline,
> but
> >> I'll keep plugging away at this til I get it right.
> >>
> >> -Mike
> >>
> >> On May 22, 2013, at 10:02 PM, Andreas Hocevar <ahocevar at opengeo.org>
> >> wrote:
> >>
> >> Hey Michael,
> >>
> >> you should find all information on how to submit code here:
> >> http://trac.osgeo.org/openlayers/wiki/HowToContribute. You will want to
> >> create a pull request, as explained here:
> >> http://trac.osgeo.org/openlayers/wiki/CreatingPatches.
> >>
> >> I hope this helps.
> >>
> >> Andreas.
> >>
> >>
> >> On Wed, May 22, 2013 at 9:34 AM, Michael Ryan <mr at mry4n.net> wrote:
> >>>
> >>> Thank you Andreas for clearing up that I should assign events like so:
> >>>
> >>> events = map.events
> >>>
> >>> The other part of this is that you have specify that the event you are
> >>> triggering is a left-click.
> >>>
> >>> By tracing the code you see that you need to set the "which" attribute
> to
> >>> 1 in the object passed to triggerEvent(), otherwise onClick in
> >>> featureclick.js ignores the event.
> >>>
> >>> So, this is what my code should have looked like:
> >>>
> >>> events = map.events;
> >>> events.triggerEvent( 'mousedown', {xy: new OpenLayers.Pixel(0,0),
> which:
> >>> 1}, map);
> >>> events.triggerEvent('mouseup', {xy: new OpenLayers.Pixel(0,0), which:
> 1},
> >>> map);
> >>>
> >>> I'm assuming I can get tests written today. Although, I'm not exactly
> >>> clear how to submit them. If anyone wants to clue me in to that
> procedure
> >>> I'd appreciate it.
> >>>
> >>> -Mike
> >>>
> >>> On May 21, 2013, at 5:21 PM, Michael Ryan <mr at mry4n.net> wrote:
> >>>
> >>> While I've understood I need to use trigger() somehow, I have been
> >>> unsuccessful in implementing it.
> >>>
> >>> I was using test for buttonclick as a reference:
> >>>
> https://github.com/openlayers/openlayers/blob/master/tests/Events/buttonclick.html
> >>>
> >>> I would have assumed that within the context of the featurclick example
> >>> https://github.com/openlayers/openlayers/pull/174/files
> >>>
> >>> I could have used something like
> >>>
> >>> events = OpenLayers.Events(map, document.getElementById("map"));
> >>> events.triggerEvent({type: 'mousedown', xy: new OpenLayers.Pixel(0,0)},
> >>> map); events.triggerEvent({type: 'mouseup', xy: new
> OpenLayers.Pixel(0,0)},
> >>> map);
> >>>
> >>> But, apparently, that's wrong.
> >>>
> >>> Am I trying to do something that isn't possible? I'm assuming I'm just
> >>> implementing it wrong. Any thoughts?
> >>>
> >>> -Mike
> >>>
> >>> On May 20, 2013, at 5:04 PM, Michael Ryan <mr at mry4n.net> wrote:
> >>>
> >>> I'll answer my question about triggering a buttonclick by saying, it
> >>> looks like you use trigger() which takes coordinates as an argument as
> in
> >>> this test:
> >>>
> https://github.com/drewwells/openlayers/blob/master/tests/Control/Measure.html
> >>>
> >>>
> >>>
> >>>
> >>> _______________________________________________
> >>> Dev mailing list
> >>> Dev at lists.osgeo.org
> >>> http://lists.osgeo.org/mailman/listinfo/openlayers-dev
> >>>
> >>
> >>
> >>
> >> --
> >> Andreas Hocevar
> >> OpenGeo - http://opengeo.org/
> >> Expert service straight from the developers.
> >>
> >>
> >>
> >> _______________________________________________
> >> Dev mailing list
> >> Dev at lists.osgeo.org
> >> http://lists.osgeo.org/mailman/listinfo/openlayers-dev
> >>
> >
> >
> >
> > --
> > Andreas Hocevar
> > OpenGeo - http://opengeo.org/
> > Expert service straight from the developers.
> >
> >
>
>
>
> --
> Andreas Hocevar
> OpenGeo - http://opengeo.org/
> Expert service straight from the developers.
> _______________________________________________
> Dev mailing list
> Dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-dev
>
--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20130523/e45edcf7/attachment.html>
More information about the Dev
mailing list