Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
Add fallback for baseURL
Browse files Browse the repository at this point in the history
Fix tests which weren't properly testing server state.

(c) Copyright IBM Corp. 2016
  • Loading branch information
jhpedemonte committed Mar 14, 2016
1 parent 0ea41b6 commit 3a142be
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion elements/urth-core-behaviors/jupyter-notebook-env.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
properties: {
_baseURL: {
value: function(){
return Urth._baseURL;
return Urth._baseURL || '/';
}
},

Expand Down
42 changes: 26 additions & 16 deletions elements/urth-core-import/test/urth-core-import.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,39 +61,53 @@
<script>
// STEP 4: Define any globals needed by the test suite.
var server;
var serverUrthImportCalledCount = 0;

before(function() {
beforeEach(function() {
server = sinon.fakeServer.create();
server.respondImmediately = true;
});
after(function() {
afterEach(function() {
server.restore();
serverUrthImportCalledCount = 0;
});

function setupServer() {
serverUrthImportCalledCount = 0;

server.respondWith('POST', '/urth_import', function(xhr, id) {
serverUrthImportCalledCount++;
xhr.respond(200, { 'Content-Type': 'application/json' }, '{ "status": 0}');
});

server.xhr.useFilters = true;
server.xhr.addFilter(function(method, uri) {
return !uri.startsWith('/urth_import');
});
}

// STEP 5: Define suite(s) and tests.
describe('package attribute', function() {
it('should cause POST server request to install the package if href is not found', function(done) {
server.respondWith('POST', '/urth_import',
[200, { 'Content-Type': 'application/json' }, '{ "status": 0}']);

setupServer();
var link = fixture('invalidHref');
var importSpy = sinon.spy(link, 'importHref');

link.addEventListener('load', function() {
expect(importSpy).to.be.calledOnce;
expect.fail('should have resulted in `importerror` instead of successful `load`');
done();
});
link.addEventListener('importerror', function() {
expect(importSpy).to.be.calledOnce;
expect(serverUrthImportCalledCount).to.equal(1);
done();
});
});

it('should not invoke POST server request if href exists', function(done) {
setupServer();
var link = fixture('validHref');
var importSpy = sinon.spy(link, 'importHref');

link.onload = function() {
expect(importSpy).to.not.be.called;
expect(serverUrthImportCalledCount).to.equal(0);
done();
};
link.onerror = function() {
Expand All @@ -114,16 +128,12 @@
});

it('should fire if the href can not be loaded', function(done) {
server.respondWith('POST', '/urth_import',
[200, { 'Content-Type': 'application/json' }, '{ "status": 0}']);

setupServer();
var link = fixture('invalidHref');
var importSpy = sinon.spy(link, 'importHref');

link.addEventListener('importerror', function(event) {
importSpy.restore();
expect(event.detail.msg).to.not.be.null;
expect(importSpy).to.be.calledOnce;
expect(serverUrthImportCalledCount).to.equal(1);
done();
});
});
Expand Down
1 change: 1 addition & 0 deletions nb-extension/js/init/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ define([
* @param {Object} config.events - Notebook events object
* @param {Object} config.WidgetManager - widget manager class
* @param {Object} config.WidgetModel - widget model class
* @return {Promise} resolved when widgets have been fully initialized
*/
return function(config) {
var Jupyter = config.namespace;
Expand Down

0 comments on commit 3a142be

Please sign in to comment.