@@ -4,20 +4,23 @@ import { run } from '@ember/runloop';
44import hbs from 'htmlbars-inline-precompile' ;
55import PageObject from 'ember-cli-page-object' ;
66import component from 'code-corps-ember/tests/pages/components/conversations/conversation-composer' ;
7+ import { reject , resolve } from 'rsvp' ;
78
89let page = PageObject . create ( component ) ;
910
1011function renderPage ( ) {
1112 page . render ( hbs `
12- {{conversations/conversation-composer body=body send =onSend}}
13+ {{conversations/conversation-composer body=body onSend =onSend}}
1314 ` ) ;
1415}
1516
1617moduleForComponent ( 'conversations/conversation-composer' , 'Integration | Component | conversations/conversation composer' , {
1718 integration : true ,
1819 beforeEach ( ) {
1920 page . setContext ( this ) ;
20- set ( this , 'onSend' , ( ) => { } ) ;
21+ set ( this , 'onSend' , ( ) => {
22+ return resolve ( ) ;
23+ } ) ;
2124 } ,
2225 afterEach ( ) {
2326 page . removeContext ( ) ;
@@ -43,6 +46,7 @@ test('sends out action and blanks out body when clicking submit', function(asser
4346 set ( this , 'body' , 'foo' ) ;
4447 set ( this , 'onSend' , ( body ) => {
4548 assert . equal ( body , 'foo' , 'Correct value was sent with action.' ) ;
49+ return resolve ( ) ;
4650 } ) ;
4751
4852 renderPage ( ) ;
@@ -51,12 +55,28 @@ test('sends out action and blanks out body when clicking submit', function(asser
5155 assert . equal ( page . submittableTextarea . value , '' , 'Body was blanked out.' ) ;
5256} ) ;
5357
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+
5473test ( 'sends out action and blanks out body when hitting enter key' , function ( assert ) {
5574 assert . expect ( 3 ) ;
5675
5776 set ( this , 'body' , 'foo' ) ;
5877 set ( this , 'onSend' , ( body ) => {
5978 assert . equal ( body , 'foo' , 'Correct value was sent with action.' ) ;
79+ return resolve ( ) ;
6080 } ) ;
6181
6282 renderPage ( ) ;
0 commit comments