builder.producePartA();
const product = builder.getProduct();
chai_1.expect(product).to.deep.equal({
parts: ['PartA1'],
});
chai_1.expect(builder.getProduct()).to.deep.equal({
parts: [],
});
builder.producePartA();
builder.producePartC();
const product = builder.getProduct();
chai_1.expect(product).to.deep.equal({
parts: ['PartA1', 'PartC1'],
});
product.listParts();
chai_1.expect(this.logStub).to.have.been.calledOnceWithExactly('Product parts: PartA1, PartC1\n');
director.buildMinimalViableProduct();
const product = builder.getProduct();
chai_1.expect(product).to.deep.equal({
parts: ['PartA1'],
});
product.listParts();
chai_1.expect(this.logStub).to.have.been.calledOnceWithExactly('Product parts: PartA1\n');
director.buildFullFeaturedProduct();
const product = builder.getProduct();
chai_1.expect(product).to.deep.equal({
parts: ['PartA1', 'PartB1', 'PartC1'],
});
product.listParts();
chai_1.expect(this.logStub).to.have.been.calledOnceWithExactly('Product parts: PartA1, PartB1, PartC1\n');
if (context.timeout)
this.timeout(context.timeout);
return run.call(this);
if (context.timeout)
this.timeout(context.timeout);
return run.call(this);
this.component.display();
chai_1.expect(this.logStub).to.have.been.calledWith('');
this.component.accept(new iterator_visitor_1.HTMLDisplayVisitor());
this.component.display();
chai_1.expect(this.logStub).to.have.been.calledWith(`<html><body><ul>
<li>${wordsArr[0]}</li>
<li>${wordsArr[1]}</li>
<li>${wordsArr[2]}</li>
<li>${wordsArr[3]}</li>
</ul></body></html>`);
this.component.accept(new iterator_visitor_1.HTMLReverseDisplayVisitor());
this.component.display();
chai_1.expect(this.logStub).to.have.been.calledWith(`<html><body><ul>
<li>${wordsArr[3]}</li>
<li>${wordsArr[2]}</li>
<li>${wordsArr[1]}</li>
<li>${wordsArr[0]}</li>
</ul></body></html>`);
this.component.accept(new iterator_visitor_1.JSONDisplayVisitor());
this.component.display();
chai_1.expect(this.logStub).to.have.been.calledWith(`{"items":["${wordsArr[0]}","${wordsArr[1]}","${wordsArr[2]}","${wordsArr[3]}"]}`);
chai_1.expect(this.words.getItems()).to.deep.equal([]);
addFour(this.words);
chai_1.expect(this.words.getItems()).to.deep.equal(wordsArr);
chai_1.expect(this.words.getCount()).to.equal(0);
addFour(this.words);
chai_1.expect(this.words.getCount()).to.equal(4);
addFour(this.words);
const iterator = this.words.getIterator();
const collection = [];
while (iterator.valid()) {
iterator.next();
collection.push(iterator.valid());
}
chai_1.expect(collection).to.deep.equal([true, true, true, false]);
addFour(this.words);
const reverseIterator = this.words.getReverseIterator();
const collection = [];
while (reverseIterator.valid()) {
reverseIterator.next();
collection.push(reverseIterator.valid());
}
chai_1.expect(collection).to.deep.equal([true, true, true, false]);
const iterator = this.words.getIterator();
let collection = [];
while (iterator.valid()) {
collection.push(iterator.next());
}
chai_1.expect(collection.length).to.equal(0);
addFour(this.words);
collection = [];
while (iterator.valid()) {
collection.push(iterator.next());
}
chai_1.expect(collection).to.deep.equal(wordsArr);
addFour(this.words);
const reverseIterator = this.words.getReverseIterator();
const collection = [];
while (reverseIterator.valid()) {
collection.push(reverseIterator.next());
}
chai_1.expect(collection).to.deep.equal(reversedWordsArr);
addFour(this.words);
const iterator = this.words.getIterator();
chai_1.expect(iterator.current()).to.equal(wordsArr[0]);
iterator.next();
chai_1.expect(iterator.current()).to.equal(wordsArr[1]);
iterator.next();
chai_1.expect(iterator.current()).to.equal(wordsArr[2]);
iterator.next();
chai_1.expect(iterator.current()).to.equal(wordsArr[3]);
addFour(this.words);
const iterator = this.words.getIterator();
chai_1.expect(iterator.key()).to.equal(0);
iterator.next();
chai_1.expect(iterator.key()).to.equal(1);
iterator.next();
chai_1.expect(iterator.key()).to.equal(2);
iterator.next();
chai_1.expect(iterator.key()).to.equal(3);
addFour(this.words);
const iterator = this.words.getIterator();
// move to end of collection
while (iterator.valid()) {
iterator.next();
}
chai_1.expect(iterator.valid()).to.be.false;
iterator.rewind();
chai_1.expect(iterator.current()).to.equal(wordsArr[0]);
addFour(this.words);
const reverseIterator = this.words.getReverseIterator();
// move to beginning of collection
while (reverseIterator.valid()) {
reverseIterator.next();
}
chai_1.expect(reverseIterator.valid()).to.be.false;
reverseIterator.rewind();
chai_1.expect(reverseIterator.current()).to.equal(wordsArr[3]);
this.subject.notify();
chai_1.expect(this.logStub).to.have.been.calledOnceWithExactly('Subject: Notifying observers...');
this.subject.attach(this.observerA);
this.subject.attach(this.observerA);
chai_1.expect(this.logStub).to.have.callCount(2);
chai_1.expect(utils_test_1.getArgsForCall(this.logStub, 0)).to.deep.equal([
'Subject: Attached an observer.',
]);
chai_1.expect(utils_test_1.getArgsForCall(this.logStub, 1)).to.deep.equal([
'Subject: Observer has been attached already.',
]);
this.subject.attach(this.observerA);
this.subject.notify();
chai_1.expect(this.logStub).to.have.callCount(3);
chai_1.expect(utils_test_1.getArgsForCall(this.logStub, 0)).to.deep.equal([
'Subject: Attached an observer.',
]);
chai_1.expect(utils_test_1.getArgsForCall(this.logStub, 1)).to.deep.equal([
'Subject: Notifying observers...',
]);
chai_1.expect(utils_test_1.getArgsForCall(this.logStub, 2)).to.deep.equal([
'ConcreteObserverA: Reacted to the event.',
]);
this.subject.attach(this.observerA);
this.subject.attach(this.observerB);
this.subject.notify();
chai_1.expect(this.logStub).to.have.callCount(5);
chai_1.expect(utils_test_1.getArgsForCall(this.logStub, 0)).to.deep.equal([
'Subject: Attached an observer.',
]);
chai_1.expect(utils_test_1.getArgsForCall(this.logStub, 1)).to.deep.equal([
'Subject: Attached an observer.',
]);
chai_1.expect(utils_test_1.getArgsForCall(this.logStub, 2)).to.deep.equal([
'Subject: Notifying observers...',
]);
chai_1.expect(utils_test_1.getArgsForCall(this.logStub, 3)).to.deep.equal([
'ConcreteObserverA: Reacted to the event.',
]);
chai_1.expect(utils_test_1.getArgsForCall(this.logStub, 4)).to.deep.equal([
'ConcreteObserverB: Reacted to the event.',
]);
this.subject.attach(this.observerA);
this.subject.someBusinessLogic();
chai_1.expect(this.logStub).to.have.callCount(4);
chai_1.expect(this.logStub).to.have.been.calledWith("\nSubject: I'm doing something important.");
chai_1.expect(this.logStub).to.have.been.calledWith('Subject: My state has just changed to: 11');
this.subject.attach(this.observerA);
this.subject.detach(this.observerA);
chai_1.expect(this.logStub).to.have.been.calledWith('Subject: Detached an observer.');
this.subject.attach(this.observerA);
this.subject.detach(this.observerB);
chai_1.expect(this.logStub).to.have.been.calledWith('Subject: Nonexistent observer.');
this.subject.attach(this.observerA);
this.subject.notify();
chai_1.expect(this.logStub).to.have.callCount(3);
chai_1.expect(this.logStub).to.have.been.calledWith('ConcreteObserverA: Reacted to the event.');
this.subject.attach(this.observerA);
this.subject.someBusinessLogic();
this.subject.notify();
chai_1.expect(this.logStub).not.to.have.been.calledWith('ConcreteObserverA: Reacted to the event.');
this.subject.attach(this.observerB);
this.subject.notify();
chai_1.expect(this.logStub).to.have.callCount(3);
chai_1.expect(this.logStub).to.have.been.calledWith('ConcreteObserverB: Reacted to the event.');
this.subject.attach(this.observerB);
this.subject.someBusinessLogic();
this.subject.notify();
chai_1.expect(this.logStub).to.have.callCount(7);
chai_1.expect(this.logStub).to.have.been.calledWith('ConcreteObserverB: Reacted to the event.');
this.mathRandomStub.returns(1 / 11);
this.subject.attach(this.observerB);
this.subject.someBusinessLogic();
this.subject.notify();
chai_1.expect(this.logStub).to.have.callCount(5);
chai_1.expect(this.logStub).not.to.have.been.calledWith('ConcreteObserverB: Reacted to the event.');
const visitor1 = new visitor_1.ConcreteVisitor1();
visitor_1.acceptVisitorForAll(components, visitor1);
chai_1.expect(this.logStub).to.have.been.calledTwice;
chai_1.expect(utils_test_1.getArgsForCall(this.logStub, 0)).to.deep.equal([
'A + ConcreteVisitor1',
]);
chai_1.expect(utils_test_1.getArgsForCall(this.logStub, 1)).to.deep.equal([
'B + ConcreteVisitor1',
]);
const visitor2 = new visitor_1.ConcreteVisitor2();
visitor_1.acceptVisitorForAll(components, visitor2);
chai_1.expect(this.logStub).to.have.been.calledTwice;
chai_1.expect(utils_test_1.getArgsForCall(this.logStub, 0)).to.deep.equal([
'A + ConcreteVisitor2',
]);
chai_1.expect(utils_test_1.getArgsForCall(this.logStub, 1)).to.deep.equal([
'B + ConcreteVisitor2',
]);