7
7
* Example of [Jest](https://jestjs.io/docs/getting-started) unit tests
8
8
*/
9
9
10
- import { ChatModel , IChatModel } from '../model' ;
11
- import { IChatMessage } from '../types' ;
10
+ import { AbstractChatModel , IChatModel } from '../model' ;
11
+ import { IChatMessage , INewMessage } from '../types' ;
12
+
13
+ class MyChatModel extends AbstractChatModel {
14
+ sendMessage ( message : INewMessage ) : Promise < boolean | void > | boolean | void {
15
+ // No-op
16
+ }
17
+ }
12
18
13
19
describe ( 'test chat model' , ( ) => {
14
20
describe ( 'model instantiation' , ( ) => {
15
- it ( 'should create a ChatModel ' , ( ) => {
16
- const model = new ChatModel ( ) ;
17
- expect ( model ) . toBeInstanceOf ( ChatModel ) ;
21
+ it ( 'should create an AbstractChatModel ' , ( ) => {
22
+ const model = new MyChatModel ( ) ;
23
+ expect ( model ) . toBeInstanceOf ( AbstractChatModel ) ;
18
24
} ) ;
19
25
20
- it ( 'should dispose a ChatModel ' , ( ) => {
21
- const model = new ChatModel ( ) ;
26
+ it ( 'should dispose an AbstractChatModel ' , ( ) => {
27
+ const model = new MyChatModel ( ) ;
22
28
model . dispose ( ) ;
23
29
expect ( model . isDisposed ) . toBeTruthy ( ) ;
24
30
} ) ;
25
31
} ) ;
26
32
27
33
describe ( 'incoming message' , ( ) => {
28
- class TestChat extends ChatModel {
34
+ class TestChat extends AbstractChatModel {
29
35
protected formatChatMessage ( message : IChatMessage ) : IChatMessage {
30
36
message . body = 'formatted msg' ;
31
37
return message ;
32
38
}
39
+ sendMessage (
40
+ message : INewMessage
41
+ ) : Promise < boolean | void > | boolean | void {
42
+ // No-op
43
+ }
33
44
}
34
45
35
46
let model : IChatModel ;
@@ -47,7 +58,7 @@ describe('test chat model', () => {
47
58
} ) ;
48
59
49
60
it ( 'should signal incoming message' , ( ) => {
50
- model = new ChatModel ( ) ;
61
+ model = new MyChatModel ( ) ;
51
62
model . messagesUpdated . connect ( ( sender : IChatModel ) => {
52
63
expect ( sender ) . toBe ( model ) ;
53
64
messages = model . messages ;
@@ -72,12 +83,12 @@ describe('test chat model', () => {
72
83
73
84
describe ( 'model config' , ( ) => {
74
85
it ( 'should have empty config' , ( ) => {
75
- const model = new ChatModel ( ) ;
86
+ const model = new MyChatModel ( ) ;
76
87
expect ( model . config . sendWithShiftEnter ) . toBeUndefined ( ) ;
77
88
} ) ;
78
89
79
90
it ( 'should allow config' , ( ) => {
80
- const model = new ChatModel ( { config : { sendWithShiftEnter : true } } ) ;
91
+ const model = new MyChatModel ( { config : { sendWithShiftEnter : true } } ) ;
81
92
expect ( model . config . sendWithShiftEnter ) . toBeTruthy ( ) ;
82
93
} ) ;
83
94
} ) ;
0 commit comments