Skip to content

Commit

Permalink
Merge pull request #31 from ahumphreys87/marionette-inspector
Browse files Browse the repository at this point in the history
Add marionette inspector setup
  • Loading branch information
ahumphreys87 committed Mar 23, 2016
2 parents ad58dab + c98e40c commit e33304a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ import TouchView from './mixins/touch.view';
import Visibility from './helpers/visibility';
import ModuleHelper from './helpers/module';
import handlebarsHelpers from './helpers/handlebars';
import 'backbone.marionette';
import Marionette from 'backbone.marionette';
import 'backbone.stickit';

if (window.__agent) {
window.__agent.start(Backbone, Marionette);
}

handlebarsHelpers();

var func = Backbone.Marionette.Module.create;
Expand Down
67 changes: 42 additions & 25 deletions tests/spec/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,107 +5,124 @@

require('../app/support/setup');
var requireNew = require('require-new');
var Orchestra = requireNew('../../src/index.js');

describe('Orchestra', function() {
beforeEach(function() {
this.Orchestra = requireNew('../../src/index.js');
});

it('should expose Marionette classes', function() {
expect(Orchestra.CompositeView).to.be.a('function');
expect(Orchestra.Module).to.be.a('function');
expect(this.Orchestra.CompositeView).to.be.a('function');
expect(this.Orchestra.Module).to.be.a('function');
});

it('should expose the TouchView object', function() {
expect(Orchestra.TouchView).to.be.an('object');
expect(this.Orchestra.TouchView).to.be.an('object');
});

it('should expose the Backbone.Radio object', function() {
expect(Orchestra.Radio).to.be.an('object');
expect(this.Orchestra.Radio).to.be.an('object');
});

it('should expose the Backbone.Syphon object', function() {
expect(Orchestra.Syphon).to.be.an('object');
expect(this.Orchestra.Syphon).to.be.an('object');
});

it('should expose the Backbone.Validation object', function() {
expect(Orchestra.Validation).to.be.an('object');
expect(this.Orchestra.Validation).to.be.an('object');
});

it('should expose the Backbone.Cocktail object', function() {
expect(Orchestra.Cocktail).to.be.an('object');
expect(this.Orchestra.Cocktail).to.be.an('object');
});

it('should expose the Collection class', function() {
expect(Orchestra.Collection).to.be.a('function');
expect(this.Orchestra.Collection).to.be.a('function');
});

it('should expose the Currency helper object', function() {
expect(Orchestra.Currency).to.be.an('object');
expect(this.Orchestra.Currency).to.be.an('object');
});

it('should expose the Visibility helper object', function() {
expect(Orchestra.Visibility).to.be.an('object');
expect(this.Orchestra.Visibility).to.be.an('object');
});

it('should expose the Translator helper object', function() {
expect(Orchestra.Translator).to.be.an('object');
expect(this.Orchestra.Translator).to.be.an('object');
});

it('should expose the Module helper object', function() {
expect(Orchestra.ModuleHelper).to.be.an('object');
expect(this.Orchestra.ModuleHelper).to.be.an('object');
});

it('should expose jQuery', function() {
expect(Orchestra.$).to.be.a('function');
expect(this.Orchestra.$).to.be.a('function');
});

it('should expose lodash', function() {
expect(Orchestra._).to.be.a('function');
expect(this.Orchestra._).to.be.a('function');
});

it('should expose the getInstance function', function() {
expect(Orchestra.getInstance).to.be.a('function');
expect(this.Orchestra.getInstance).to.be.a('function');
});

describe('if window.agent exists', function() {
beforeEach(function() {
window.__agent = {
start: this.sandbox.stub()
};

this.Orchestra = requireNew('../../src/index.js');
});

it('should call start', function() {
expect(window.__agent.start.callCount).to.eql(1);
});
});

describe('getInstance()', function() {
var component;
describe('No instance exists', function() {

it('should have empty object for instances', function() {
expect(Orchestra.instances).to.eql({})
expect(this.Orchestra.instances).to.eql({})
});

it('should return new \'main\' orchestra instance', function() {
component = Orchestra.getInstance('main');
component = this.Orchestra.getInstance('main');
expect(component.namespace).to.eql('main');
});

it('should store reference for instance in instances object', function() {
expect(Orchestra.instances.main).to.be.an('object');
expect(Orchestra.instances.main.namespace).to.eql('main');
this.Orchestra.getInstance('main');
expect(this.Orchestra.instances.main).to.be.an('object');
expect(this.Orchestra.instances.main.namespace).to.eql('main');
});

});

describe('Instance already exists', function() {
it('should return a reference to previously created instance', function() {
expect(Orchestra.getInstance('main')).to.eql(component);
component = this.Orchestra.getInstance('main');
expect(this.Orchestra.getInstance('main')).to.eql(component);
});

it('should delete orchestra instance reference', function() {
component.destroy();
expect(Orchestra.instances).to.eql({});
expect(this.Orchestra.instances).to.eql({});
});
});

});

describe('Module.create()', function() {
before(function() {
this.instance = Orchestra.getInstance('main');
this.instance = this.Orchestra.getInstance('main');
});

it('should add namespace to options of the module', function() {
Orchestra.Module.create(this.instance, 'custom.module', {});
this.Orchestra.Module.create(this.instance, 'custom.module', {});
expect(this.instance.custom.module.options.namespace).to.eql('custom.module');
});
});
Expand Down

0 comments on commit e33304a

Please sign in to comment.