1
0
Fork 0

add sinon for better testing

This commit is contained in:
Enoch Riese 2023-02-23 19:15:20 +02:00
parent 12ffb0a9c1
commit dc998d4e98
6 changed files with 128 additions and 11 deletions

View file

@ -9,7 +9,7 @@ PatternDraftQueue.prototype.start = function () {
}
PatternDraftQueue.prototype.addPart = function (partName) {
this.queue.push(partName)
if (!this.contains(partName)) this.queue.push(partName)
return this
}
@ -27,6 +27,10 @@ PatternDraftQueue.prototype.next = function () {
return next
}
PatternDraftQueue.prototype.contains = function (partName) {
return this.queue.indexOf(partName) !== -1
}
/**
* Resolves the draft order based on the configuation
*

View file

@ -67,8 +67,11 @@ export function Pattern(designConfig = {}) {
* It might be useful to not resolve immediately if a number of parts will be added over multiple calls
* @return {object} this - The Pattern instance
*/
Pattern.prototype.addPart = function (part, resolveImmediately = false) {
if (this.__configResolver.isPartValid(part) && this.designConfig.parts.indexOf(part) === -1) {
Pattern.prototype.addPart = function (part, resolveImmediately = true) {
if (
this.__configResolver.isPartValid(part) &&
!this.designConfig.parts.find((p) => p.name == part.name)
) {
this.designConfig.parts.push(part)
if (resolveImmediately) {
if (this.__configResolver.addPart(part) && typeof this.draftQueue !== 'undefined')