-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add change between scenes test
- Loading branch information
fletcherist
committed
Aug 14, 2018
1 parent
e259ada
commit c3860e9
Showing
8 changed files
with
83 additions
and
24 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
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,6 +1,7 @@ | ||
import { IStageСompere } from './compere'; | ||
import { IStageCompere } from './compere'; | ||
import { ISessionContext } from '../session/sessionContext'; | ||
|
||
export interface IStageContext extends ISessionContext { | ||
readonly compere: IStageСompere; | ||
readonly enter: IStageCompere['enter']; | ||
readonly leave: IStageCompere['leave']; | ||
} |
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,19 +1,61 @@ | ||
import { Alice, Scene, Stage } from '../dist/'; | ||
import { request, getRandomText } from './testUtils'; | ||
import { Alice, Scene, Stage, sessionMiddleware, Reply } from '../dist/'; | ||
import { request, getRandomText, delay } from './testUtils'; | ||
|
||
describe('alice scenes', () => { | ||
let alice = null; | ||
let randomText = ''; | ||
let stage = null; | ||
let randomText = ''; | ||
beforeEach(() => { | ||
alice = new Alice(); | ||
randomText = getRandomText(); | ||
stage = new Stage(); | ||
randomText = getRandomText(); | ||
}); | ||
|
||
test('create new scene', () => { | ||
const scene = new Scene('name'); | ||
test('create new scene', async done => { | ||
const scene = new Scene('bar'); | ||
scene.any(ctx => ({ text: randomText })); | ||
stage.addScene(scene); | ||
// alice.use(sessionMiddleware()); | ||
alice.use(stage.getMiddleware()); | ||
alice.any(async ctx => { | ||
ctx.enter('bar'); | ||
return { text: 'foo' }; | ||
}); | ||
// handling first request, leading to the scene "bar" | ||
let data = await alice.handleRequest(request('hey!')); | ||
expect(data.response.text).toBe('foo'); | ||
// now looking for an answer from scene | ||
data = await alice.handleRequest(request('hey!')); | ||
expect(data.response.text).toBe(randomText); | ||
done(); | ||
}); | ||
|
||
test('switch between scenes', async done => { | ||
const scene1 = new Scene('1'); | ||
scene1.any(ctx => { | ||
ctx.enter('2'); | ||
return { text: 'scene1' }; | ||
}); | ||
const scene2 = new Scene('2'); | ||
scene2.any(async ctx => { | ||
ctx.leave(); | ||
return { text: 'scene2' }; | ||
}); | ||
stage.addScene(scene1); | ||
stage.addScene(scene2); | ||
alice.use(stage.getMiddleware()); | ||
alice.any(async ctx => { | ||
ctx.enter('1'); | ||
return { text: 'alice' }; | ||
}); | ||
let data = await alice.handleRequest(request('baz')); | ||
expect(data.response.text).toBe('alice'); | ||
done(); | ||
data = await alice.handleRequest(request('.')); | ||
expect(data.response.text).toBe('scene1'); | ||
data = await alice.handleRequest(request('.')); | ||
expect(data.response.text).toBe('scene2'); | ||
data = await alice.handleRequest(request('.')); | ||
expect(data.response.text).toBe('alice'); | ||
}); | ||
}); |
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