-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ChangesType and Changes models and test coverage for them
- Loading branch information
Showing
7 changed files
with
205 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
var ChangeType = require('./type'), | ||
Changes = function () { | ||
this._docs = new ChangeType('docs'); | ||
this._pages = new ChangeType('pages'); | ||
this._libraries = new ChangeType('libraries'); | ||
}; | ||
|
||
Changes.prototype = { | ||
_docs: undefined, | ||
_pages: undefined, | ||
_libraries: undefined, | ||
|
||
/** | ||
* Returns modified state of changes | ||
* @returns {*|Boolean} | ||
*/ | ||
areModified: function () { | ||
return this.docs.areModified() || this.pages.areModified() || this.libraries.areModified(); | ||
}, | ||
|
||
/** | ||
* Returns documentation changes | ||
* @returns {Array<ChangeType>} | ||
*/ | ||
get docs() { | ||
return this._docs; | ||
}, | ||
|
||
/** | ||
* Returns page changes | ||
* @returns {Array<ChangeType>} | ||
*/ | ||
get pages() { | ||
return this._pages; | ||
}, | ||
|
||
/** | ||
* Returns library changes | ||
* @returns {Array<ChangeType>} | ||
*/ | ||
get libraries() { | ||
return this._libraries; | ||
} | ||
}; | ||
|
||
module.exports = Changes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
var ChangeType = function (type) { | ||
this._type = type; | ||
this._added = []; | ||
this._modified = []; | ||
this._removed = []; | ||
}; | ||
|
||
ChangeType.prototype = { | ||
_type: undefined, | ||
_added: undefined, | ||
_modified: undefined, | ||
_removed: undefined, | ||
|
||
/** | ||
* Verify if data of given type were modified | ||
* @returns {Boolean} | ||
*/ | ||
areModified: function () { | ||
return this._added.length || this._modified.length || this._removed.length; | ||
}, | ||
|
||
/** | ||
* Add new items to added group | ||
* @param {Object} item | ||
* @returns {ChangeType} | ||
*/ | ||
addAdded: function (item) { | ||
this._added.push(item); | ||
return this; | ||
}, | ||
|
||
/** | ||
* Add new items to modified group | ||
* @param {Object} item | ||
* @returns {ChangeType} | ||
*/ | ||
addModified: function (item) { | ||
this._modified.push(item); | ||
return this; | ||
}, | ||
|
||
/** | ||
* Add new items to removed group | ||
* @param {Object} item | ||
* @returns {ChangeType} | ||
*/ | ||
addRemoved: function (item) { | ||
this._removed.push(item); | ||
return this; | ||
}, | ||
|
||
/** | ||
* Returns items of added group | ||
* @returns {*} | ||
*/ | ||
get added() { | ||
return this._added; | ||
}, | ||
|
||
/** | ||
* Returns items of modified group | ||
* @returns {*} | ||
*/ | ||
get modified() { | ||
return this._modified; | ||
}, | ||
|
||
/** | ||
* Returns items of removed group | ||
* @returns {*} | ||
*/ | ||
get removed() { | ||
return this._removed; | ||
} | ||
}; | ||
|
||
module.exports = ChangeType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
require('./scripts/send-model'); | ||
require('./model/changes/type'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var ChangesType = require('../../../src/model/changes/type'), | ||
Changes = require('../../../src/model/changes'); | ||
|
||
describe('model/changes', function () { | ||
it('should be initialized successfully', function () { | ||
new Changes(); | ||
}); | ||
|
||
it('should have docs changes model', function () { | ||
var changes = new Changes(); | ||
changes.should.have.property('docs'); | ||
changes.docs.should.be.instanceof(ChangesType); | ||
}); | ||
|
||
it('should have pages changes model', function () { | ||
var changes = new Changes(); | ||
changes.should.have.property('pages'); | ||
changes.pages.should.be.instanceof(ChangesType); | ||
}); | ||
|
||
it('should have libraries changes model', function () { | ||
var changes = new Changes(); | ||
changes.should.have.property('libraries'); | ||
changes.libraries.should.be.instanceof(ChangesType); | ||
}); | ||
|
||
it('should not be in modified state', function () { | ||
var changes = new Changes(); | ||
changes.areModified().should.not.be.ok; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var ChangesType = require('../../../src/model/changes/type'); | ||
|
||
describe('model/changes/type', function () { | ||
it('should be initialized successfully by given type', function () { | ||
var ct = new ChangesType('pages'); | ||
ct._type.should.equal('pages'); | ||
}); | ||
|
||
it('should not be in modified state', function () { | ||
var ct = new ChangesType('pages'); | ||
ct.areModified().should.not.be.ok; | ||
}); | ||
|
||
it('should have added empty collection', function () { | ||
var ct = new ChangesType('pages'); | ||
ct.added.should.be.instanceof(Array).and.have.length(0); | ||
}); | ||
|
||
it('should have modified empty collection', function () { | ||
var ct = new ChangesType('pages'); | ||
ct.modified.should.be.instanceof(Array).and.have.length(0); | ||
}); | ||
|
||
it('should have removed empty collection', function () { | ||
var ct = new ChangesType('pages'); | ||
ct.removed.should.be.instanceof(Array).and.have.length(0); | ||
}); | ||
|
||
it('should add new added items', function () { | ||
var ct = new ChangesType('pages'); | ||
ct.addAdded('url1'); | ||
ct.added.should.have.length(1); | ||
ct.areModified().should.be.ok; | ||
}); | ||
|
||
it('should add new modified items', function () { | ||
var ct = new ChangesType('pages'); | ||
ct.addModified('url1'); | ||
ct.modified.should.have.length(1); | ||
ct.areModified().should.be.ok; | ||
}); | ||
|
||
it('should add new removed items', function () { | ||
var ct = new ChangesType('pages'); | ||
ct.addRemoved('url1'); | ||
ct.removed.should.have.length(1); | ||
ct.areModified().should.be.ok; | ||
}); | ||
}); |