@@ -4,20 +4,23 @@ import { run } from '@ember/runloop';
4
4
import hbs from 'htmlbars-inline-precompile' ;
5
5
import PageObject from 'ember-cli-page-object' ;
6
6
import component from 'code-corps-ember/tests/pages/components/conversations/conversation-composer' ;
7
+ import { reject , resolve } from 'rsvp' ;
7
8
8
9
let page = PageObject . create ( component ) ;
9
10
10
11
function renderPage ( ) {
11
12
page . render ( hbs `
12
- {{conversations/conversation-composer body=body send =onSend}}
13
+ {{conversations/conversation-composer body=body onSend =onSend}}
13
14
` ) ;
14
15
}
15
16
16
17
moduleForComponent ( 'conversations/conversation-composer' , 'Integration | Component | conversations/conversation composer' , {
17
18
integration : true ,
18
19
beforeEach ( ) {
19
20
page . setContext ( this ) ;
20
- set ( this , 'onSend' , ( ) => { } ) ;
21
+ set ( this , 'onSend' , ( ) => {
22
+ return resolve ( ) ;
23
+ } ) ;
21
24
} ,
22
25
afterEach ( ) {
23
26
page . removeContext ( ) ;
@@ -43,6 +46,7 @@ test('sends out action and blanks out body when clicking submit', function(asser
43
46
set ( this , 'body' , 'foo' ) ;
44
47
set ( this , 'onSend' , ( body ) => {
45
48
assert . equal ( body , 'foo' , 'Correct value was sent with action.' ) ;
49
+ return resolve ( ) ;
46
50
} ) ;
47
51
48
52
renderPage ( ) ;
@@ -51,12 +55,28 @@ test('sends out action and blanks out body when clicking submit', function(asser
51
55
assert . equal ( page . submittableTextarea . value , '' , 'Body was blanked out.' ) ;
52
56
} ) ;
53
57
58
+ test ( 'resets the body when promise rejects on clicking submit' , async function ( assert ) {
59
+ assert . expect ( 3 ) ;
60
+
61
+ set ( this , 'body' , 'foo' ) ;
62
+ set ( this , 'onSend' , ( body ) => {
63
+ assert . equal ( body , 'foo' , 'Correct value was sent with action.' ) ;
64
+ return reject ( { body } ) ;
65
+ } ) ;
66
+
67
+ renderPage ( ) ;
68
+ assert . equal ( page . submittableTextarea . value , 'foo' , 'Body is rendered correctly.' ) ;
69
+ await page . submitButton . click ( ) ;
70
+ assert . equal ( page . submittableTextarea . value , 'foo' , 'Body was reset.' ) ;
71
+ } ) ;
72
+
54
73
test ( 'sends out action and blanks out body when hitting enter key' , function ( assert ) {
55
74
assert . expect ( 3 ) ;
56
75
57
76
set ( this , 'body' , 'foo' ) ;
58
77
set ( this , 'onSend' , ( body ) => {
59
78
assert . equal ( body , 'foo' , 'Correct value was sent with action.' ) ;
79
+ return resolve ( ) ;
60
80
} ) ;
61
81
62
82
renderPage ( ) ;
0 commit comments