mapbox-gl - how to instantiate a Map for a simple test - unit-testing

I'd like to start by asking Mapbox - please - to put documentation on their site that explains how to set up and start doing a simple test. There are many tests in their code on Github, but after days of reading and attempting to test I have failed to understand how they work.
I have a very simple method that:
updates some geoJson with some new coordinates and a new heading (rotation) for a marker.
uses setSource to set the changed Json to the Map
I would like to run my little method in a test and then check that the new coordinates have arrived in the Map.
Should be a piece of cake!
Now a Map needs a browser or similar. Yes, there's jsdom, which is almost certainly what is needed, but I have not discovered how you give the dom to the Map.
If I try to instantiate either window, which I found in mapbox-js utils, or Map, I get
ReferenceError: self is not defined. - 'self' appears to be the window object.
I use mocha, with babel 7, for what it's worth, but I think that all I need is to solve the mystery of setting up a Map instance so that I can then interrogate it.
Any help would be gratefully received.

Related

How to specify "element(by.id" or "element(by.css" in Ember.js using Protractor

New to ember.js -- used http://yoember.com/ to create a Demo ember.js site. I'm trying to figure out how to use Protractor to test certain elements, but I'm encountering issues specifying them.
Most, but not all, elements (buttons, text areas, etc) have a serialized id value: id='ember###' that changes every time the page is reloaded, which makes it impossible to indicate some elements in Protractor (like, element(by.id('ember557')).sendKeys('foo');).
Running a command like the one above will return the error: Failed: No element found using locator: By(css selector, *[id="ember557"]), which is due to the 3-digit id value changing.
In my demo app, I was able to go into the /app/templates/components/ file for that page and manually add something like id='name' into the handlebars input and was able to successfully find and test that element in Protractor.
This isn't ideal though, and I'd like to find a way to test sites that I don't have the ability to modify the html of.
Can anyone help me wrap my head around this? Thanks.

Unit test says function was called, but console.logs are not showing up

I have a function inside another function that is supposedly getting called, according to my expect(Parse.User.Login).toHaveBeenCalled() line, but there are some console statements inside the callback to that which aren't showing up.
Is there some type of dependency I'm missing on my unit test causing the callback not to have called? I think it is getting to the server, because it tells me I need a Parse.initialize with the application keys if that's not present.
How do I resolve it?
It just occurred to me, maybe that's something in Parse.js telling me I need the Parse.initialize(keys,keys). I changed the parse keys to nonsense, and its not telling me they're wrong, so it must be that parse isn't being touched at all. No request is being sent to the server.
I've been putting up a few questions about this, but now I guess this can't be done with Karma-jasmine -- at least the way the app is set up right now. It's depending on a web service to give the errors, instead of having an angular directive set up up front to detect the errors in the fields beforehand.
I'm a newbie at this obviously, or I would have recognized this sooner:
This type of testing, where you are depending on responses from the server and that's that, should be delegated to E2E tests.
Meaning, here what am I supposed to test that wouldn't be just hardcoding the desired response right into the jasmine Spy? What would that do to just set the rootScope to a user attribute? Maybe, if state.go changed the view to another page, and then acted on the $rootScope data, this would make sense. But for now, there's no point. I'm not designing the next step, nor do I know what it is at the moment, so I can only sit back.

Can a Custom DataProvider class expose Custom Templates?

I am currently in the process of writing a custom DataProvider. Using the Intergrate External Data documentation.
I've managed to show the external data in the Sitecore back end. However whenever I try to view the data in the items I created, I am getting an error
Null ids are not allowed. <br> Parameter name: displayName
There seems to be precious little on the subject on how to create a custom DataProvider on the Sitecore Developer Network.
The example on their website seems to only show how to import a SINGLE item into a static database. However I am simply trying to merge some items into the hierarchy and I can't find any useful documentation.
It seems that one of your methods that should return an ID doesn't. It might be GetChildIds and/or GetParentId.
Nick Wesselman wrote a good article about it gathering all the information including an example on the Marketplace. I think that is your best start. You can read it here.
Turns out I needed to include at the very least, the Fields->Section->Template in the GetParent method. To be on the safe side I included the Fields/Sections/Templates into my implementations of
GetChildIDs
GetItemDefinition
GetParentID
It wasn't obvious that this was the case, since I had in fact implemented the GetTemplates method correctly, and I had expected that should be enough.

Emberjs - unable to redefine named, explicitly compiled Handlebars template

As part of an attempt to port a fairly large/complex existing application to the Ember world, I'm generating and compiling named Handlebars templates dynamically, and associating views with them, using the technique:
var template = Ember.Handlebars.compile("some handlebars stuff");
Ember.TEMPLATES["myTemplate"] = template;
var view = Ember.View.create({
templateName: "myTemplate"
});
One of the things I'd like to do is be able to recompile new/different Handlebars template markup which overwrites the template named "myTemplate" and have it be accessible to views at that name.
I'm getting unexpected results trying to do this - a couple fiddles that illustrate the problems:
First fiddle - Shows what happens if you wait before rendering a view after the named template contents have changed.
Second fiddle - Shows what happens if there's no delay before rendering a view after the named template contents have changed.
There's obviously some magic under the hood that I'm not understanding. Can anyone shed some light on this?
UPDATE:
I went through the source code for Ember.View and the container module, and came to realize that I could solve the problem in the First fiddle by overriding the "template" computed property in a way that skips the container cache lookup. I've put up another fiddle here to demonstrate the solution I found.
This seems to be working the way I'd like it to - but - it feels like I might be fighting with the framework and "unhooking" from the container in a way that might bite me later. Is there a better, more Ember-esque way to accomplish what I'm trying to do? Will the hack I found break things?
UPDATE 2
I've also discovered that it's also possible to simply call
view2.get('container').reset();
before appending view2 in the First fiddle. Seems cleaner/safer, but is it "legal"? I've updated the First fiddle to illustrate this.
(in the second fiddle, both views show the second template)
This is because view1.appendTo($("#target")); just schedules the append, actual view rendering does not happen until end of the run loop. Before that happens, you've set Ember.TEMPLATES["myTemplate"] = template2;
(in the first fiddle, both views show the first template)
Pretty sure this is because ember container caches template fx, but not 100% on that. Checking...
I'm going to call this one answered. As I mentioned in my second comment, I'm using the solution shown in this fiddle in my project, along these lines:
mYiew.get('container').reset();
There's some discussion about the container not being intended to be used as an API here: https://github.com/emberjs/ember.js/commit/5becdc4467573f80a5c5dbb51d97c6b9239714a8 , but there doesn't seem to be any mention of using the container from Views for other use cases.
Also, a View's container can be accessed directly (at ".container") - meaning the devs haven't made it "hard" to get to the way they have for an Application's ".__ container __". This might suggest something about how they intend it to be used.
Since a View having the ability to clear its cache whenever it wants to doesn't seem to me to be unreasonable or a bad practice, I'm using the above mentioned solution...at least until someone sets me straight with a better idea (or a cache API).

Play framework testing controller method

I have a controller method that fetches data to render(fetched data) a HTML view of the same. I wanted to write a test to ensure the jpa model is queried correctly. However I am not finding a way to intercept what is being passed into render().
Can someone please let me know if there is a way to get what is passed into render from a test case. If not should I move this code/line into a different class that I can test easily.
Thanks
I know it's not exactly what you want but you could just write some selenium tests that will confirm whether the controller is rendering the correct data in the template. (see: http://www.playframework.org/documentation/1.2.4/guide10#selenium)
Also writing a Functional Test may help (see: http://www.playframework.org/documentation/1.2.4/guide10#controller)
Could you see if the Play Response object i.e. the out contains your expected value?