Remove refs to rewirefy

Since it’s not really needed, one less dependency
pull/2662/head
Nicklas Gummesson 10 years ago
parent 38c7859fdb
commit b6d07e70e6

@ -48,7 +48,6 @@ Until our guidelines are publically available follow the existing file/directory
Tests reside in the `lib/assets/test` directory. We use
- [Jasmine 2.1](jasmine.github.io/2.1/introduction.html) as test framework
- [SinonJS 1.3.4](sinonjs.org) for test spies/stubs/mocks when Jasmine spies isn't good enough
- [Rewirefy](https://github.com/i-like-robots/rewireify) to mock CommonJS (browserify) `require` calls
When adding new files make sure they exist in an appropriate file located in `lib/build/js_files` (will depends
if you're writing tests for current code or the newer browserify modules).
@ -113,4 +112,3 @@ This will watch CSS and JS files and rebuild bundles automatically upon changes.
```
_Don't forget to restart Rails after you have modified `config/app_config.yml`._

@ -6,8 +6,6 @@ var HeaderViewModel = require('../../../../../../../javascripts/cartodb/new_dash
describe('new_common/views/dashboard_header/breadcrumbs/dropdown_view', function() {
beforeEach(function() {
var godModel = window.cdb.god;
BreadcrumbsDropdownView.__set__('cdb', cdb);
this.user = new cdbAdmin.User({
base_url: 'http://pepe.cartodb.com',
username: 'pepe'
@ -36,7 +34,6 @@ describe('new_common/views/dashboard_header/breadcrumbs/dropdown_view', function
expect(this.view).toHaveNoLeaks();
});
var Backbone = require('backbone');
it('should have rendered a URL for maps', function() {
expect(this.innerHTML()).toMatch('href="http://pepe.cartodb.com/dashboard/maps"');
});

@ -1,3 +1,4 @@
var NotificationsDropdown = require('../../../../../../javascripts/cartodb/new_common/views/dashboard_header/notifications/dropdown_view');
var UserNotifications = require('../../../../../../javascripts/cartodb/new_common/views/dashboard_header/notifications/view');
var cdbAdmin = require('cdb.admin');
var LocalStorage = require('../../../../../../javascripts/cartodb/new_common/local_storage');
@ -20,6 +21,8 @@ describe("new_common/views/dashboard_header/notifications/view", function() {
table_count: 1
});
spyOn(NotificationsDropdown.prototype, 'initialize').and.callThrough();
view = new UserNotifications({
user: user,
localStorage: this.localStorage
@ -56,15 +59,11 @@ describe("new_common/views/dashboard_header/notifications/view", function() {
describe('click', function() {
beforeEach(function() {
this.dropdownMock = jasmine.createSpyObj('fake-SettingsDropdown-object', ['render', 'on', 'open', 'clean']);
this.dropdownMock.options = {
target: jasmine.createSpyObj('dropdown-target-element', ['unbind'])
};
this.DropdownSpy = jasmine.createSpy('fake-SettingsDropdown-constructor');
this.DropdownSpy.and.returnValue(this.dropdownMock);
UserNotifications.__set__('NotificationsDropdown', this.DropdownSpy);
view.render();
spyOn(NotificationsDropdown.prototype, 'render').and.callThrough();
spyOn(NotificationsDropdown.prototype, 'open').and.callThrough();
spyOn(NotificationsDropdown.prototype, 'on').and.callThrough();
spyOn(NotificationsDropdown.prototype, 'clean').and.callThrough();
this.clickSettings = function() {
view.$el.click();
@ -73,18 +72,17 @@ describe("new_common/views/dashboard_header/notifications/view", function() {
it('should create dropdown view with expected params', function() {
this.clickSettings();
expect(NotificationsDropdown.prototype.initialize).toHaveBeenCalled();
expect(this.DropdownSpy).toHaveBeenCalled();
var viewToBeInstantiatedWith = this.DropdownSpy.calls.argsFor(0)[0];
var viewToBeInstantiatedWith = NotificationsDropdown.prototype.initialize.calls.argsFor(0)[0];
expect(viewToBeInstantiatedWith.target[0]).toEqual(view.$el[0]);
expect(viewToBeInstantiatedWith.template_base).toEqual('new_common/views/dashboard_header/notifications/templates/dropdown');
});
it('should have rendered and opened the dropdown view', function() {
this.clickSettings();
expect(this.dropdownMock.render).toHaveBeenCalled();
expect(this.dropdownMock.open).toHaveBeenCalled();
expect(NotificationsDropdown.prototype.render).toHaveBeenCalled();
expect(NotificationsDropdown.prototype.open).toHaveBeenCalled();
});
it('should add the dropdown view to the child views', function() {
@ -98,13 +96,13 @@ describe("new_common/views/dashboard_header/notifications/view", function() {
this.clickSettings();
expect(this.dropdownMock.on).toHaveBeenCalledWith('onDropdownHidden', jasmine.any(Function), view);
expect(NotificationsDropdown.prototype.on).toHaveBeenCalledWith('onDropdownHidden', jasmine.any(Function), view);
// trigger the listener callback manually to verify assertions below
this.dropdownMock.on.calls.argsFor(0)[1].call(view);
NotificationsDropdown.prototype.on.calls.argsFor(0)[1].call(view);
setTimeout(function() {
expect(self.dropdownMock.clean).toHaveBeenCalled();
expect(NotificationsDropdown.prototype.clean).toHaveBeenCalled();
expect(view.$el.hasClass('has--alerts')).toBeFalsy();
done();
}, 400);
@ -134,4 +132,8 @@ describe("new_common/views/dashboard_header/notifications/view", function() {
});
afterEach(function() {
view.clean();
});
});

@ -1,3 +1,5 @@
var PaginationModel = require('../../../../../javascripts/cartodb/new_common/views/pagination/model');
var PaginationView = require('../../../../../javascripts/cartodb/new_common/views/pagination/view');
var ContentFooterView = require('../../../../../javascripts/cartodb/new_dashboard/content_footer/view');
var cdb = require('cartodb.js');
var Router = require('../../../../../javascripts/cartodb/new_dashboard/router');
@ -19,23 +21,19 @@ describe('new_dashboard/content_footer/view', function() {
spyOn(this.router.model, 'bind').and.callThrough();
this.paginationModelStub = jasmine.createSpyObj('paginationModel', ['render', 'clean', 'set']);
this.PaginationModelSpy = jasmine.createSpy('PaginationModel');
this.PaginationModelSpy.and.returnValue(this.paginationModelStub);
ContentFooterView.__set__('PaginationModel', this.PaginationModelSpy);
spyOn(PaginationModel.prototype, 'initialize').and.callThrough();
spyOn(PaginationModel.prototype, 'set').and.callThrough();
this.paginationViewStub = jasmine.createSpyObj('paginationView', ['render', 'clean']);
this.paginationViewStub.el = $('<div class="Pagination"></div>')[0];
this.PaginationViewSpy = jasmine.createSpy('PaginationView');
this.PaginationViewSpy.and.returnValue(this.paginationViewStub);
ContentFooterView.__set__('PaginationView', this.PaginationViewSpy);
spyOn(PaginationView.prototype, 'initialize').and.callThrough();
spyOn(PaginationView.prototype, 'render').and.callThrough();
spyOn(PaginationView.prototype, 'clean').and.callThrough();
this.view = new ContentFooterView({
el: $el[0],
collection: this.collection,
router: this.router
});
spyOn(this.view, 'clearSubViews');
spyOn(this.view, 'clearSubViews').and.callThrough();
});
it('should listen to change events on router model', function() {
@ -44,19 +42,19 @@ describe('new_dashboard/content_footer/view', function() {
describe('should create a pagination view', function() {
it('with a pagination model args', function() {
expect(this.PaginationViewSpy).toHaveBeenCalled();
expect(PaginationView.prototype.initialize).toHaveBeenCalled();
var createdWith = this.PaginationViewSpy.calls.argsFor(0)[0];
expect(createdWith).toEqual(jasmine.objectContaining({ model: this.paginationModelStub }));
var createdWith = PaginationView.prototype.initialize.calls.argsFor(0)[0];
expect(createdWith).toEqual(jasmine.objectContaining({ model: jasmine.any(Object) }));
expect(createdWith).toEqual(jasmine.objectContaining({ router: this.router }));
});
it('but not render just yet', function() {
expect(this.paginationViewStub.render).not.toHaveBeenCalled();
expect(PaginationView.prototype.render).not.toHaveBeenCalled();
});
it('which model should be initially configured for routing', function() {
var viewmodelCreatedWith = this.PaginationModelSpy.calls.argsFor(0)[0];
var viewmodelCreatedWith = PaginationModel.prototype.initialize.calls.argsFor(0)[0];
expect(viewmodelCreatedWith).toEqual(jasmine.objectContaining({ current_page: jasmine.any(Number) }));
expect(viewmodelCreatedWith).toEqual(jasmine.objectContaining({ url_to: jasmine.any(Function) }));
});
@ -71,8 +69,8 @@ describe('new_dashboard/content_footer/view', function() {
});
it('should update the pagination model accordingly', function() {
expect(this.paginationModelStub.set).toHaveBeenCalledWith(jasmine.objectContaining({ per_page: this.collection.options.get('per_page') }));
expect(this.paginationModelStub.set).toHaveBeenCalledWith(jasmine.objectContaining({ total_count: this.collection.total_entries }));
expect(PaginationModel.prototype.set).toHaveBeenCalledWith(jasmine.objectContaining({ per_page: this.collection.options.get('per_page') }));
expect(PaginationModel.prototype.set).toHaveBeenCalledWith(jasmine.objectContaining({ total_count: this.collection.total_entries }));
});
});
@ -83,7 +81,7 @@ describe('new_dashboard/content_footer/view', function() {
});
it('should update the pagination model accordingly', function() {
expect(this.paginationModelStub.set).toHaveBeenCalledWith('current_page', this.router.model.get('page'));
expect(PaginationModel.prototype.set).toHaveBeenCalledWith('current_page', this.router.model.get('page'));
});
});
});
@ -102,7 +100,7 @@ describe('new_dashboard/content_footer/view', function() {
});
it('should render pagination view', function() {
expect(this.paginationViewStub.render).toHaveBeenCalled();
expect(PaginationView.prototype.render).toHaveBeenCalled();
});
it('should append the PaginationView to this el', function() {

@ -1,3 +1,5 @@
var DeleteItemsDialog = require('../../../../javascripts/cartodb/new_dashboard/dialogs/delete_items_view');
var ChangeLockDialog = require('../../../../javascripts/cartodb/new_dashboard/dialogs/change_lock_view');
var FiltersView = require('../../../../javascripts/cartodb/new_dashboard/filters_view');
var Router = require('../../../../javascripts/cartodb/new_dashboard/router');
var LocalStorage = require('../../../../javascripts/cartodb/new_common/local_storage');
@ -23,16 +25,6 @@ describe('new_dashboard/filters_view', function() {
this.localStorage = new LocalStorage('test');
this.deleteItemsDialogStub = jasmine.createSpyObj('DeleteItemsDialog stub', ['appendToBody', 'bind']);
this.DeleteItemsDialogSpy = jasmine.createSpy('DeleteItemsDialog');
this.DeleteItemsDialogSpy.and.returnValue(this.deleteItemsDialogStub);
FiltersView.__set__('DeleteItemsDialog', this.DeleteItemsDialogSpy);
this.changeLockDialogStub = jasmine.createSpyObj('ChangeLockDialog stub', ['appendToBody', 'bind']);
this.ChangeLockDialogSpy = jasmine.createSpy('ChangeLockDialog');
this.ChangeLockDialogSpy.and.returnValue(this.changeLockDialogStub);
FiltersView.__set__('ChangeLockDialog', this.ChangeLockDialogSpy);
this.view = new FiltersView({
user: this.user,
router: this.router,
@ -162,12 +154,14 @@ describe('new_dashboard/filters_view', function() {
{ selected: true }
];
this.collection.reset(this.selectedItems);
spyOn(DeleteItemsDialog.prototype, 'initialize').and.callThrough();
spyOn(DeleteItemsDialog.prototype, 'appendToBody').and.callThrough();
this.view.$('.js-delete').click();
this.createdWith = this.DeleteItemsDialogSpy.calls.argsFor(0)[0];
this.createdWith = DeleteItemsDialog.prototype.initialize.calls.argsFor(0)[0];
});
it('should open a delete-items dialog', function() {
expect(this.deleteItemsDialogStub.appendToBody).toHaveBeenCalled();
expect(DeleteItemsDialog.prototype.appendToBody).toHaveBeenCalled();
});
it('should created dialog with a view model', function() {
@ -188,12 +182,14 @@ describe('new_dashboard/filters_view', function() {
{ selected: true }
];
this.collection.reset(this.selectedItems);
spyOn(ChangeLockDialog.prototype, 'initialize').and.callThrough();
spyOn(ChangeLockDialog.prototype, 'appendToBody').and.callThrough();
this.view.$('.js-lock').click();
this.createdWith = this.ChangeLockDialogSpy.calls.argsFor(0)[0];
this.createdWith = ChangeLockDialog.prototype.initialize.calls.argsFor(0)[0];
});
it('should open a lock items dialog', function() {
expect(this.changeLockDialogStub.appendToBody).toHaveBeenCalled();
expect(ChangeLockDialog.prototype.appendToBody).toHaveBeenCalled();
});
it('should created dialog with a view model', function() {

@ -8,10 +8,6 @@ module.exports = {
// Add specs for browserify module code here:
'lib/assets/test/spec/cartodb/new_*/**/*.spec.js'
],
dest: '<%= browserify_modules.tests.dest %>',
options: {
transform: ['rewireify'] //Allow mocking of require() dependencies.
}
dest: '<%= browserify_modules.tests.dest %>'
}
};

@ -49,7 +49,6 @@
"moment": "^2.8.4",
"open": "0.0.5",
"queue-async": "^1.0.7",
"rewireify": "0.0.13",
"shelljs": "~0.2.6",
"source-map-support": "^0.2.8",
"uglify-js": "1.3.3",

Loading…
Cancel
Save