-
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.
Adding more processes and debugging deserialization
- Loading branch information
1 parent
fbe98c8
commit 2d78069
Showing
7 changed files
with
161 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {Idea} from "../Idea"; | ||
import {BotProcess, BotStatus} from "../DaVinciBot"; | ||
import {AddIdeaProcess} from "./AddIdeaProcess"; | ||
|
||
// TODO processes should be able to handleInput in a standard form where | ||
// different options are either a number or a case-insensitive string. | ||
// There should also be a standard form for outputting these options as is done | ||
// below | ||
|
||
// TODO should process descriptions be markdown-enabled? With options available | ||
// on getOutput() to either ignore or parse formatting into another form the | ||
// client chooses | ||
|
||
export class PlanIdeaProcess extends BotProcess | ||
{ | ||
start(): void { | ||
this.status = BotStatus.HasOutput; | ||
} | ||
|
||
getOutput(): string { | ||
this.status = BotStatus.NeedsInput; | ||
return `Planning for idea ${this.rootIdea.name}: | ||
1. [Break] this idea into smaller ideas. | ||
2. Define a [time] estimate for this idea. | ||
3. [Describe] this idea. (Current description: ${this.rootIdea.description}) | ||
4. [quit] | ||
`; | ||
|
||
} | ||
|
||
handleInput(input:string) { | ||
this.status = BotStatus.HasOutput; | ||
switch (input.toLowerCase()) { | ||
case '1': | ||
case 'break': | ||
this.bot.startProcess(new AddIdeaProcess(this.bot, this.rootIdea)); | ||
break; | ||
case '2': | ||
case 'time': | ||
// TODO start a TimeIdeaProcess on rootIdea | ||
break; | ||
case '3': | ||
case 'describe': | ||
// TODO start an add description process on rootIdea | ||
break; | ||
case '4': | ||
case 'quit': | ||
this.status = BotStatus.Idle; | ||
break; | ||
} | ||
} | ||
} |
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,50 @@ | ||
import {Idea} from "../Idea"; | ||
import {BotProcess, BotStatus} from "../DaVinciBot"; | ||
import {PlanIdeaProcess} from "./PlanIdeaProcess"; | ||
|
||
export class WorkOnIdeaProcess extends BotProcess | ||
{ | ||
start(): void { | ||
this.status = BotStatus.HasOutput; | ||
} | ||
|
||
getOutput(): string { | ||
this.status = BotStatus.NeedsInput; | ||
return `Working on idea ${this.rootIdea.name}: | ||
1. Mark this idea [done]. | ||
2. Work on this idea's [parts] | ||
3. [Delete] this idea | ||
4. [Plan] this idea. | ||
5. [quit] | ||
`; | ||
} | ||
|
||
handleInput(input:string) { | ||
this.status = BotStatus.HasOutput; | ||
switch (input.toLowerCase()) { | ||
case '1': | ||
case 'done': | ||
this.rootIdea.progress = 1; | ||
this.status = BotStatus.Idle; | ||
break; | ||
case '2': | ||
case 'parts': | ||
for (let i = this.rootIdea.children.length - 1; i >= 0; --i) { | ||
this.bot.startProcess(new WorkOnIdeaProcess(this.bot, this.rootIdea.children[i])); | ||
} | ||
break; | ||
case '3': | ||
case 'delete': | ||
// TODO delete this idea from its root | ||
break; | ||
case '4': | ||
case 'plan': | ||
this.bot.startProcess(new PlanIdeaProcess(this.bot, this.rootIdea)); | ||
case '5': | ||
case 'quit': | ||
this.status = BotStatus.Idle; | ||
break; | ||
} | ||
} | ||
|
||
} |
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,33 @@ | ||
'use strict'; | ||
|
||
var expect = require('chai').expect; | ||
var idea = require('../dist/Idea.js'); | ||
var davincibot = require('../dist/DaVinciBot.js'); | ||
var addIdeaProcess = require('../dist/processes/AddIdeaProcess.js'); | ||
var serialization = require('../dist/processes/Serialization.js'); | ||
|
||
describe('Serialization test', () => { | ||
var bot = new davincibot.DaVinciBot(); | ||
var rootIdea = new idea.Idea(); | ||
bot.startProcess(new addIdeaProcess.AddIdeaProcess(bot, rootIdea)); | ||
bot.getOutput(); | ||
bot.handleInput('test1'); | ||
bot.handleInput('test2'); | ||
bot.handleInput('test3'); | ||
bot.handleInput('quit'); | ||
|
||
|
||
bot.startProcess(new serialization.SaveFileProcess(bot, rootIdea)); | ||
bot.handleInput('.serial-test-1.json'); | ||
|
||
var newRootIdea = new idea.Idea(); | ||
bot.startProcess(new serialization.LoadFileProcess(bot, newRootIdea)); | ||
bot.handleInput('.serial-test-1.json'); | ||
|
||
it('Should preserve the Idea names after deserialization', () => { | ||
expect(newRootIdea.children[0].name).to.equal('test1'); | ||
expect(newRootIdea.children[1].name).to.equal('test2'); | ||
expect(newRootIdea.children[2].name).to.equal('test3'); | ||
}); | ||
|
||
}); |