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,20 @@
var CustomCarouselItemModel = require('builder/components/custom-carousel/custom-carousel-item-model');
var CustomCarouselCollection = require('builder/components/custom-carousel/custom-carousel-collection');
describe('components/custom-carousel/custom-carousel-collection', function () {
beforeEach(function () {
this.collection = new CustomCarouselCollection([
new CustomCarouselItemModel({ val: 'hi' }),
new CustomCarouselItemModel({ val: 'howdy' }),
new CustomCarouselItemModel({ val: 'hello' })
]);
});
it('should remove previous selected item when a new one is chosen', function () {
this.collection.at(1).set('selected', true);
expect(this.collection.where({ selected: true }).length).toBe(1);
this.collection.at(0).set('selected', true);
expect(this.collection.where({ selected: true }).length).toBe(1);
expect(this.collection.at(1).get('selected')).toBeFalsy();
});
});
@@ -0,0 +1,74 @@
var _ = require('underscore');
var CustomCarouselItemModel = require('builder/components/custom-carousel/custom-carousel-item-model');
var CustomCarouselItemView = require('builder/components/custom-carousel/custom-carousel-item-view');
describe('components/custom-carousel/custom-carousel-item-view', function () {
beforeEach(function () {
this.model = new CustomCarouselItemModel({
val: 'hello'
});
this.view = new CustomCarouselItemView({
model: this.model
});
this.view.render();
});
it('should render properly', function () {
expect(this.view.$('button').length).toBe(1);
});
it('should allow to add a className', function () {
var view = new CustomCarouselItemView({
model: this.model,
itemOptions: {
className: 'MyFabolousClassName'
}
});
view.render();
expect(view.$('button').hasClass('MyFabolousClassName')).toBeTruthy();
view.clean();
});
describe('hover', function () {
beforeEach(function () {
this.view.$el.trigger('mouseenter');
});
it('should add class when it is hovered', function () {
expect(this.model.get('highlighted')).toBeTruthy();
});
it('should remove class when it is unhovered', function () {
this.view.$el.trigger('mouseleave');
expect(this.model.get('highlighted')).toBeFalsy();
});
});
describe('with tooltip', function () {
describe('.render', function () {
it('should render properly', function () {
expect(this.model.set('tooltip', 'help'));
this.view.render();
expect(_.size(this.view._subviews)).toBe(1);
});
});
});
it('should set selected when it is clicked', function () {
expect(this.model.get('selected')).toBeFalsy();
this.view.$el.trigger('click');
expect(this.model.get('selected')).toBeTruthy();
expect(this.view.$el.hasClass('is-selected')).toBeTruthy();
});
it('should not have any leaks', function () {
expect(this.view).toHaveNoLeaks();
});
});
@@ -0,0 +1,76 @@
var CustomCarouselView = require('builder/components/custom-carousel/custom-carousel-view');
describe('components/custom-carousel/custom-carousel-view', function () {
beforeEach(function () {
this.view = new CustomCarouselView({
options: [
{ val: 'hello', selected: true },
{ val: 'howdy' },
{ val: 'hi' }
]
});
spyOn(this.view, '_bindScroll');
spyOn(this.view, '_checkShadows');
spyOn(this.view, '_checkScroll');
jasmine.clock().install();
this.view.render();
this.view.initScroll();
jasmine.clock().tick(100);
});
it('should allow to add a className for every list item', function () {
var view = new CustomCarouselView({
options: [
{ val: 'hello', selected: true },
{ val: 'howdy' },
{ val: 'hi' }
],
listItemOptions: {
className: 'MyFabolousClassName'
}
});
view.render();
expect(view.$('li').hasClass('MyFabolousClassName')).toBeTruthy();
view.clean();
});
it('should render properly', function () {
expect(this.view.$('li').length).toBe(3);
expect(this.view.$('.Carousel-shadow').length).toBe(2);
});
it('should bind scroll', function () {
expect(this.view._bindScroll).toHaveBeenCalled();
});
it('should check shadows', function () {
expect(this.view._checkShadows).toHaveBeenCalled();
});
afterEach(function () {
jasmine.clock().uninstall();
});
describe('bind', function () {
it('should check scroll when selected item changes', function () {
this.view.collection.at(1).set('selected', true);
expect(this.view._checkScroll).toHaveBeenCalled();
});
});
describe('unbind', function () {
it('should not check shadows after unbind', function () {
this.view._checkShadows.calls.reset();
this.view._unbindScroll();
this.view._listContainer().trigger('ps-scroll-x');
expect(this.view._checkShadows).not.toHaveBeenCalled();
});
});
it('should destroy custom scroll when view is removed', function () {
spyOn(this.view, '_destroyCustomScroll');
this.view.clean();
expect(this.view._destroyCustomScroll).toHaveBeenCalled();
});
});