mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2026-10-15 00:49:05 +02:00
- Convert Backbone.Model to ES6 classes with get/set methods - Command model in commandModel.js - Error classes in errors.js - Convert Backbone.Collection to ES6 classes - CommitCollection, CommandCollection, BranchCollection, TagCollection - CommandBuffer with event support - Convert Backbone.View to ES6 classes - All view classes in views/*.js - Visual classes in visuals/*.js - Add custom EventEmitter to replace Backbone.Events - New eventEmitter.js with on/off/trigger/once/listenTo - Fix context binding: pass 'this' as third arg to on() - Fix off() filter logic for proper listener removal - Fix event context binding in Level class - Events bound with explicit context to access this.mainVis - Remove unnecessary bypass checks in minimizeGoal/resizeGoal/showGoal - Add comprehensive tests - eventEmitter.spec.js: 16 tests for event system - collections.spec.js: tests for converted collections - commandModel.spec.js: tests for Command class - errors.spec.js: tests for error classes
92 lines
3.0 KiB
JavaScript
92 lines
3.0 KiB
JavaScript
var collections = require('../src/js/models/collections');
|
|
var Command = require('../src/js/models/commandModel').Command;
|
|
|
|
describe('Collections', function() {
|
|
describe('CommandCollection', function() {
|
|
it('should create an empty collection', function() {
|
|
var col = new collections.CommandCollection();
|
|
expect(col.length).toBe(0);
|
|
});
|
|
|
|
it('should add items', function() {
|
|
var col = new collections.CommandCollection();
|
|
// Use 'git commit' which is a supported command
|
|
var cmd = new Command({rawStr: 'git commit'});
|
|
col.add(cmd);
|
|
expect(col.length).toBe(1);
|
|
});
|
|
|
|
it('should retrieve items by index with at()', function() {
|
|
var col = new collections.CommandCollection();
|
|
var cmd = new Command({rawStr: 'git commit'});
|
|
col.add(cmd);
|
|
expect(col.at(0)).toBe(cmd);
|
|
});
|
|
|
|
it('should support toArray()', function() {
|
|
var col = new collections.CommandCollection();
|
|
var cmd1 = new Command({rawStr: 'git commit'});
|
|
var cmd2 = new Command({rawStr: 'git checkout main'});
|
|
col.add(cmd1);
|
|
col.add(cmd2);
|
|
var arr = col.toArray();
|
|
expect(arr.length).toBe(2);
|
|
expect(arr[0]).toBe(cmd1);
|
|
expect(arr[1]).toBe(cmd2);
|
|
});
|
|
});
|
|
|
|
describe('CommitCollection', function() {
|
|
it('should create an empty collection', function() {
|
|
var col = new collections.CommitCollection();
|
|
expect(col.length).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe('BranchCollection', function() {
|
|
it('should create an empty collection', function() {
|
|
var col = new collections.BranchCollection();
|
|
expect(col.length).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe('TagCollection', function() {
|
|
it('should create an empty collection', function() {
|
|
var col = new collections.TagCollection();
|
|
expect(col.length).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe('CommandBuffer', function() {
|
|
it('should be created with a collection', function() {
|
|
var col = new collections.CommandCollection();
|
|
var buffer = new collections.CommandBuffer({collection: col});
|
|
expect(buffer).toBeTruthy();
|
|
});
|
|
|
|
it('should have an empty buffer initially', function() {
|
|
var col = new collections.CommandCollection();
|
|
var buffer = new collections.CommandBuffer({collection: col});
|
|
expect(buffer.buffer.length).toBe(0);
|
|
});
|
|
|
|
it('should add commands to buffer when collection receives add', function() {
|
|
var col = new collections.CommandCollection();
|
|
var buffer = new collections.CommandBuffer({collection: col});
|
|
var cmd = new Command({rawStr: 'git commit'});
|
|
col.add(cmd);
|
|
expect(buffer.buffer.length).toBe(1);
|
|
buffer.clear();
|
|
});
|
|
|
|
it('should clear timeout on clear()', function() {
|
|
var col = new collections.CommandCollection();
|
|
var buffer = new collections.CommandBuffer({collection: col});
|
|
buffer.setTimeout();
|
|
expect(buffer.timeout).toBeTruthy();
|
|
buffer.clear();
|
|
expect(buffer.timeout).toBe(null);
|
|
});
|
|
});
|
|
});
|