Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
22 changed files
with
227 additions
and
70 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
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
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,11 +1,10 @@ | ||
import { Calculator } from '@serenity-js-examples/calculator-app'; | ||
import { Actor } from '@serenity-js/core'; | ||
import { Cast } from '@serenity-js/core/lib/stage'; | ||
import { Actor, DressingRoom } from '@serenity-js/core'; | ||
|
||
import { InteractDirectly } from './abilities'; | ||
|
||
export class Actors implements Cast { | ||
actor(name: string) { | ||
return Actor.named(name).whoCan(InteractDirectly.with(new Calculator())); | ||
export class Actors implements DressingRoom { | ||
prepare(actor: Actor): Actor { | ||
return actor.whoCan(InteractDirectly.with(new Calculator())); | ||
} | ||
} |
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
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,8 @@ | ||
import { Actor, Interaction } from '@serenity-js/core'; | ||
import { InteractDirectly } from '../abilities'; | ||
|
||
export const RequestANewCalculation = () => | ||
Interaction.where(`#actor requests a new calculation`, | ||
(actor: Actor) => { | ||
InteractDirectly.as(actor).requestANewCalculationId(); | ||
}); |
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,2 +1,3 @@ | ||
export * from './EnterOperand'; | ||
export * from './RequestANewCalculation'; | ||
export * from './UseOperator'; |
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
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
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
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,106 @@ | ||
import sinon = require('sinon'); | ||
import { ActivityFinished, ActivityStarts, DomainEvent, TestRunnerDetected } from '../src/events'; | ||
import { Name } from '../src/model'; | ||
import { Actor, Interaction } from '../src/screenplay'; | ||
import { Serenity } from '../src/Serenity'; | ||
import { Clock, DressingRoom, Stage, StageCrewMember } from '../src/stage'; | ||
import { expect } from './expect'; | ||
|
||
describe('Serenity', () => { | ||
|
||
it(`constructs a Stage and connects it with a provided DressingRoom`, () => { | ||
|
||
const prepareSpy = sinon.spy(); | ||
|
||
// no-op actors with no special Abilities | ||
class Extras implements DressingRoom { | ||
prepare(actor: Actor): Actor { | ||
prepareSpy(actor); | ||
return actor; | ||
} | ||
} | ||
|
||
const serenity = new Serenity(new Clock()); | ||
|
||
const stage = serenity.callToStageFor(new Extras()); | ||
|
||
const Joe = stage.theActorCalled('Joe'); | ||
|
||
expect(prepareSpy).to.have.been.calledOnce; // tslint:disable-line:no-unused-expression | ||
expect(prepareSpy.getCall(0).args[0]).to.equal(Joe); | ||
}); | ||
|
||
it(`enables propagation of DomainEvents triggered by Actors' Activities and StageCrewMembers`, () => { | ||
|
||
class Extras implements DressingRoom { | ||
prepare(actor: Actor): Actor { | ||
return actor; | ||
} | ||
} | ||
|
||
const PerformSomeInteraction = () => Interaction.where(`#actor performs some interaction`, actor => { | ||
return void 0; | ||
}); | ||
|
||
const frozenClock = new Clock(() => new Date('1983-07-03')); | ||
const serenity = new Serenity(frozenClock); | ||
const listener = new Listener<ActivityStarts | ActivityFinished>(); | ||
|
||
serenity.setTheStage(listener); | ||
|
||
const theStage = serenity.callToStageFor(new Extras()); | ||
const Joe = theStage.theActorCalled('Joe'); | ||
|
||
return Joe.attemptsTo( | ||
PerformSomeInteraction(), | ||
). | ||
then(() => serenity.waitForNextCue()). | ||
then(() => { | ||
expect(listener.events).to.have.lengthOf(2); | ||
|
||
expect(listener.events[0]).to.be.instanceOf(ActivityStarts); | ||
expect(listener.events[0].value.name.value).to.equal(`Joe performs some interaction`); | ||
|
||
expect(listener.events[1]).to.be.instanceOf(ActivityFinished); | ||
expect(listener.events[1].value.name.value).to.equal(`Joe performs some interaction`); | ||
}); | ||
}); | ||
|
||
it(`allows for external parties, such as test runner adapters, to announce DomainEvents`, () => { | ||
|
||
const frozenClock = new Clock(() => new Date('1983-07-03')); | ||
const serenity = new Serenity(frozenClock); | ||
const listener = new Listener<TestRunnerDetected>(); | ||
|
||
const testRunnerName = new Name('mocha'); | ||
|
||
serenity.setTheStage(listener); | ||
|
||
serenity.announce(new TestRunnerDetected(testRunnerName, serenity.currentTime())); | ||
|
||
return serenity.waitForNextCue(). | ||
then(() => { | ||
expect(listener.events).to.have.lengthOf(1); | ||
|
||
expect(listener.events[0]).to.be.instanceOf(TestRunnerDetected); | ||
expect(listener.events[0].value).to.equal(testRunnerName); | ||
}); | ||
}); | ||
|
||
class Listener<Event_Type extends DomainEvent> implements StageCrewMember { | ||
public readonly events: Event_Type[] = []; | ||
|
||
constructor(private stage: Stage = null) { | ||
} | ||
|
||
assignedTo(stage: Stage): StageCrewMember { | ||
this.stage = stage; | ||
|
||
return this; | ||
} | ||
|
||
notifyOf(event: Event_Type): void { | ||
this.events.push(event); | ||
} | ||
} | ||
}); |
Oops, something went wrong.