Initial commit

This commit is contained in:
zhongjin
2020-06-15 10:58:47 +08:00
commit 4f1dfe7564
8590 changed files with 1516878 additions and 0 deletions
@@ -0,0 +1,46 @@
var NotifierCollection = require('builder/components/notifier/notifier-collection.js');
describe('components/notifier/notifier-collection', function () {
beforeEach(function () {
this.collection = new NotifierCollection();
this.collection.add({
id: 'foo',
info: 'Test'
});
});
it('should add properly', function () {
expect(this.collection.length).toBe(1);
});
it('should search properly', function () {
var model = this.collection.findById('foo');
expect(model.get('id')).toBe('foo');
});
it('should remove view properly', function () {
var model = this.collection.findById('foo');
this.collection.remove(model);
expect(this.collection.length).toBe(0);
});
describe('.addNotification', function () {
it('should add a notification if there are no other notifications with the same info', function () {
this.collection.addNotification({
id: 'Test 1',
info: 'Test 1'
});
expect(this.collection.size()).toEqual(2);
});
it('should not add a notification if there is another notification with the same info', function () {
this.collection.addNotification({
id: 'Test 1',
info: 'Test'
});
expect(this.collection.size()).toEqual(1);
});
});
});
@@ -0,0 +1,14 @@
var NotifierModel = require('builder/components/notifier/notifier-model.js');
describe('components/notifier/notifier-model', function () {
var model = new NotifierModel({}, {});
describe('.getInfo', function () {
model.updateInfo('< & Hello >');
it('should return current info', function () {
var info = model.getInfo();
expect(info).toBe('< & Hello >');
});
});
});
@@ -0,0 +1,176 @@
var Backbone = require('backbone');
var Notifier = require('builder/components/notifier/notifier.js');
var ConfigModel = require('builder/data/config-model');
var VisDefinitionModel = require('builder/data/vis-definition-model');
var CoreView = require('backbone/core-view');
describe('components/notifier/notifier-view', function () {
var view;
var editorModel;
beforeAll(function () {
editorModel = new Backbone.Model();
editorModel.isEditing = function () {
return false;
};
var configModel = new ConfigModel({
base_url: 'foo'
});
var visDefinitionModel = new VisDefinitionModel({
name: 'Foo Map',
privacy: 'PUBLIC',
updated_at: '2016-06-21T15:30:06+00:00',
type: 'derived'
}, {
configModel: configModel
});
Notifier.init({
editorModel: editorModel,
visDefinitionModel: visDefinitionModel
});
Notifier.getCollection().reset();
});
beforeEach(function () {
jasmine.clock().install();
view = Notifier.getView();
view.render();
Notifier.addNotification({
id: 'foo',
closable: false
});
});
afterEach(function () {
Notifier.off();
jasmine.clock().uninstall();
});
it('should render properly', function () {
expect(view.el).toBeDefined();
expect(view.$('.Notifier-inner').length).toBe(1);
expect(view.$('.Notifier-icon').length).toBe(0);
expect(view.$('#foo').length).toBe(1);
});
it('should rebind events properly', function () {
var holder = new CoreView();
var notifierView = Notifier.getView();
spyOn(notifierView, 'rebindEvents');
holder.$el.append(notifierView.render().el);
holder.addView(notifierView);
// clearSubViews calls to clear listeners
holder.clearSubViews();
Notifier.getView();
expect(view.rebindEvents).toHaveBeenCalled();
});
it('should add subview properly', function () {
Notifier.addNotification({
id: 'bar'
});
expect(view.$('.Notifier-inner').length).toBe(2);
expect(view.$('#foo').length).toBe(1);
expect(view.$('#bar').length).toBe(1);
});
it('should remove subview properly', function () {
Notifier.addNotification({
id: 'bar'
});
Notifier.removeNotification('foo');
expect(view.$('.Notifier-inner').length).toBe(1);
expect(view.$('#bar').length).toBe(1);
expect(view.$('#foo').length).toBe(0);
});
it('should update icon properly', function () {
var model = Notifier.getNotification('foo');
model.updateStatus('loading');
expect(view.$('.Notifier-icon').length).toBe(1);
});
it('should update close button properly', function () {
var model = Notifier.getNotification('foo');
model.updateClosable(true);
expect(view.$('.js-close').length).toBe(1);
expect(view.$('.js-action').length).toBe(0);
});
it('should update button properly', function () {
var model = Notifier.getNotification('foo');
model.updateButton('OK');
expect(view.$('.js-close').length).toBe(0);
expect(view.$('.js-action').length).toBe(1);
});
it('should bind actions properly', function () {
var callback = {
fn: function () {}
};
spyOn(callback, 'fn');
var model = Notifier.getNotification('foo');
model.on('notification:close', callback.fn);
model.on('notification:action', callback.fn);
model.updateButton('OK');
view.$('.js-action').trigger('click');
expect(callback.fn).toHaveBeenCalled();
model.updateClosable(true);
view.$('.js-close').trigger('click');
expect(callback.fn).toHaveBeenCalled();
});
it('should remove view on close properly', function () {
var model = Notifier.getNotification('foo');
model.updateClosable(true);
view.$('.js-close').trigger('click');
expect(view.$('.Notifier-inner').length).toBe(0);
});
it('should autoclose on success', function () {
var model = Notifier.getNotification('foo');
model.updateStatus('error');
jasmine.clock().tick(Notifier.DEFAULT_DELAY + 1);
expect(view.$('.Notifier-inner').length).toBe(1);
model.updateClosable(true);
model.updateStatus('success');
jasmine.clock().tick(Notifier.DEFAULT_DELAY + 1);
expect(view.$('.Notifier-inner').length).toBe(0);
});
it('should not autoclose on success if autoclose is not enabled', function () {
Notifier.addNotification({
id: 'bar',
closable: true,
autoclosable: false
});
var model = Notifier.getNotification('bar');
model.updateStatus('error');
jasmine.clock().tick(Notifier.DEFAULT_DELAY + 1);
expect(view.$('.Notifier-inner').length).toBe(2);
model.updateClosable(true);
model.updateStatus('success');
jasmine.clock().tick(Notifier.DEFAULT_DELAY + 1);
expect(view.$('.Notifier-inner').length).toBe(2);
});
it('should not have any leaks', function () {
expect(view).toHaveNoLeaks();
});
});
@@ -0,0 +1,149 @@
var Notifier = require('builder/components/notifier/notifier.js');
var VisDefinitionModel = require('builder/data/vis-definition-model');
var ConfigModel = require('builder/data/config-model');
var Backbone = require('backbone');
describe('components/notifier/notifier', function () {
var editorModel;
beforeEach(function () {
editorModel = new Backbone.Model();
editorModel.isEditing = function () { return false; };
var configModel = new ConfigModel({
base_url: '/u/pepe'
});
this.visDefinitionModel = new VisDefinitionModel({
name: 'Foo Map',
privacy: 'PUBLIC',
updated_at: '2016-06-21T15:30:06+00:00',
type: 'derived'
}, {
configModel: configModel
});
Notifier.init({
editorModel: editorModel,
visDefinitionModel: this.visDefinitionModel
});
this.model = Notifier.addNotification({
id: 'whatever'
});
});
afterEach(function () {
Notifier.off();
});
it('should return the view properly', function () {
expect(Notifier.getView()).toBeDefined();
expect(Notifier.getCount()).toBeDefined();
});
it('should set collection properly', function () {
expect(this.model.collection).toBeDefined();
});
it('model should retrigger vis events', function () {
var spy = jasmine.createSpy('spy');
this.model.on('vis:reload', spy);
this.visDefinitionModel.trigger('vis:reload');
expect(spy).toHaveBeenCalled();
});
it('should render properly', function () {
expect(Notifier.getView().render().el).toBeDefined();
});
it('should return the proper model', function () {
var model = Notifier.addNotification({
id: 'foo'
});
expect(model.get('id')).toBe('foo');
expect(Notifier.getCollection().length).toBe(2);
});
it('should search model properly', function () {
var result = Notifier.getNotification('whatever');
expect(result).toBe(this.model);
var result2 = Notifier.getNotification(this.model);
expect(result2).toBe(this.model);
});
it('should have different ids', function () {
var n1 = Notifier.addNotification({
status: 'success',
info: 'First',
closable: true
});
var n2 = Notifier.addNotification({
status: 'error',
info: 'Second',
closable: true
});
expect(n1.get('id') !== n2.get('id')).toBe(true);
});
it('should remove two o more views created at the same time', function () {
var n1 = Notifier.addNotification({
status: 'success',
info: 'First',
closable: true
});
var n2 = Notifier.addNotification({
status: 'error',
info: 'Second',
closable: true
});
n1.collection.remove(n1);
n2.collection.remove(n2);
this.model.collection.remove(this.model);
expect(Notifier.getCollection().length).toBe(0);
});
it('should remove notification properly', function () {
var result = Notifier.getNotification('whatever');
Notifier.removeNotification(result);
expect(Notifier.getCollection().length).toBe(0);
});
describe('.getCount', function () {
it('should return the collection size', function () {
Notifier.addNotification({
status: 'success',
info: 'First',
closable: true
});
Notifier.addNotification({
status: 'error',
info: 'Second',
closable: true
});
expect(Notifier.getCount()).toBe(3);
});
});
describe('.addNotification', function () {
it('should call collection.addNotification', function () {
spyOn(this.model.collection, 'addNotification');
Notifier.addNotification({
status: 'success',
info: 'First',
closable: true
});
expect(this.model.collection.addNotification).toHaveBeenCalled();
});
});
});