Skip to content

Commit

Permalink
Merge pull request #324 from billba/master
Browse files Browse the repository at this point in the history
Shell tests
  • Loading branch information
billba authored Feb 3, 2017
2 parents 4fd8d96 + 7e67886 commit a3157bf
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class Chat extends React.Component<ChatProps, {}> {
this.store.dispatch<FormatAction>({ type: 'Set_Format_Options', options: props.formatOptions });

if (props.sendTyping)
this.store.dispatch<ShellAction>({ type: 'Set_Send_Typing' });
this.store.dispatch<ShellAction>({ type: 'Set_Send_Typing', sendTyping: props.sendTyping });
}

private handleIncomingActivity(activity: Activity) {
Expand Down
5 changes: 3 additions & 2 deletions src/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export type ShellAction = {
type: 'Update_Input',
input: string
} | {
type: 'Set_Send_Typing'
type: 'Set_Send_Typing',
sendTyping: boolean
} | {
type: 'Send_Message',
activity: Activity
Expand Down Expand Up @@ -45,7 +46,7 @@ export const shell: Reducer<ShellState> = (
case 'Set_Send_Typing':
return {
... state,
sendTyping: true
sendTyping: action.sendTyping
};

default:
Expand Down
2 changes: 1 addition & 1 deletion test/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const chai = require('chai');
const expect = chai.expect;
const history = require('../built/Store.js').history;
const { history } = require('../built/Store.js');

chai.use(require('chai-subset'));

Expand Down
45 changes: 45 additions & 0 deletions test/shell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use strict";

const chai = require('chai');
const expect = chai.expect;
const { shell } = require('../built/Store.js');

chai.use(require('chai-subset'));

describe("shell", () => {
it("should start with an empty input", () => {
expect(shell(undefined, { type: undefined })).to.containSubset({
input: ''
});
});
it("should update when it's intitially updated", () => {
expect(shell(undefined, { type: 'Update_Input', input: 'foo' })).to.containSubset({
input: 'foo'
});
});
it("should update when it's subsequently updated", () => {
expect(shell({ input: 'foo' }, { type: 'Update_Input', input: 'bar' })).to.containSubset({
input: 'bar'
});
});
it("should clear when a message is sent", () => {
expect(shell({ input: 'foo' }, { type: 'Send_Message' })).to.containSubset({
input: ''
});
});
it("should default to not sending typing", () => {
expect(shell(undefined, { type: undefined })).to.containSubset({
sendTyping: false
});
});
it("should update sendTyping to true", () => {
expect(shell(undefined, { type: 'Set_Send_Typing', sendTyping: true })).to.containSubset({
sendTyping: true
});
});
it("should update sendTyping to false", () => {
expect(shell(undefined, { type: 'Set_Send_Typing', sendTyping: false })).to.containSubset({
sendTyping: false
});
});
});

0 comments on commit a3157bf

Please sign in to comment.