backbone-generator/templates/view_spec.js.erb

50 lines
1.3 KiB
Plaintext
Raw Normal View History

2011-04-15 18:55:37 +00:00
describe('<%= object_name %>View', function() {
2011-04-29 19:05:54 +00:00
var view, model;
2011-04-15 18:55:37 +00:00
2011-04-29 19:05:54 +00:00
describe('new record', function() {
beforeEach(function() {
model = new <%= object_name %>();
});
2011-04-15 18:55:37 +00:00
2011-04-29 19:05:54 +00:00
it('should render with a create button', function() {
view = new <%= object_name %>View({model: model});
view.render();
2011-05-03 19:43:19 +00:00
expect(view.$('button.save')).toHaveText('Create');
2011-04-29 19:05:54 +00:00
});
});
describe('existing record', function() {
beforeEach(function() {
model = new <%= object_name %>({id: 1});
2011-05-03 19:53:36 +00:00
setFixtures('<div id="container" />');
2011-04-29 19:05:54 +00:00
});
it('should render with an update button', function() {
view = new <%= object_name %>View({model: model});
view.render();
2011-05-03 19:43:19 +00:00
expect(view.$('button.save')).toHaveText('Update');
2011-04-29 19:05:54 +00:00
});
2011-05-03 19:53:36 +00:00
2011-05-03 19:57:57 +00:00
it('should destroy the model', function() {
2011-05-03 19:53:36 +00:00
spyOn(window, 'confirm').andReturn(true);
spyOn(model, 'destroy');
$('#facility').append(view.el);
view.$('button.delete').trigger('click');
expect(model.destroy).toHaveBeenCalled();
expect(window.confirm).toHaveBeenCalled();
});
it('should remove the view when the model is destroyed', function() {
$('#container').append(view.render().el);
expect($('button.save')).toExist();
model.trigger('remove');
expect($('button.save')).not.toExist();
});
2011-04-15 18:55:37 +00:00
});
});