@@ -9,7 +9,7 @@ const hour = 3600 * 1000;
99function createConversations ( count , project , user ) {
1010 return [ ...Array ( count ) ] . map ( ( ) => {
1111 let message = server . create ( 'message' , { project } ) ;
12- return server . create ( 'conversation' , { message, user } ) ;
12+ return server . create ( 'conversation' , { message, user } , 'withConversationParts' ) ;
1313 } ) ;
1414}
1515
@@ -88,8 +88,9 @@ test('Project admin can view list of conversations', async function(assert) {
8888} ) ;
8989
9090test ( 'Project admin can view single conversations' , async function ( assert ) {
91- assert . expect ( 1 ) ;
91+ assert . expect ( 5 ) ;
9292
93+ let store = this . application . __container__ . lookup ( 'service:store' ) ;
9394 let { project, user } = server . create ( 'project-user' , { role : 'admin' } ) ;
9495 authenticateSession ( this . application , { user_id : user . id } ) ;
9596
@@ -100,9 +101,19 @@ test('Project admin can view single conversations', async function(assert) {
100101 project : project . slug
101102 } ) ;
102103
103- page . conversations ( 1 ) . click ( ) ;
104+ await page . conversations ( 1 ) . click ( ) ;
104105
105- assert . equal ( currentRouteName ( ) , 'project.conversations.conversation' ) ;
106+ andThen ( ( ) => {
107+ assert . equal ( currentRouteName ( ) , 'project.conversations.conversation' ) ;
108+
109+ let conversation = store . peekRecord ( 'conversation' , server . db . conversations [ 1 ] . id ) ;
110+ let firstPart = conversation . get ( 'sortedConversationParts' ) . get ( 'firstObject' ) ;
111+ let lastPart = conversation . get ( 'sortedConversationParts' ) . get ( 'lastObject' ) ;
112+ assert . equal ( page . conversationThread . conversationParts ( ) . count , 11 , 'Message head and conversation parts rendered' ) ;
113+ assert . equal ( page . conversationThread . conversationParts ( 1 ) . body . text , firstPart . get ( 'body' ) , 'first conversation part is rendered correctly' ) ;
114+ assert . equal ( page . conversationThread . conversationParts ( 10 ) . body . text , lastPart . get ( 'body' ) , 'last conversation part is rendered correctly' ) ;
115+ assert . ok ( firstPart . get ( 'insertedAt' ) < lastPart . get ( 'insertedAt' ) , 'conversations are sorted correctly' ) ;
116+ } ) ;
106117} ) ;
107118
108119test ( 'System is notified of new conversation part' , async function ( assert ) {
@@ -120,17 +131,17 @@ test('System is notified of new conversation part', async function(assert) {
120131
121132 page . conversations ( 0 ) . click ( ) ;
122133
123- assert . equal ( page . conversationThread . conversationParts ( ) . count , 1 , 'Just the message head is rendered.' ) ;
134+ assert . equal ( page . conversationThread . conversationParts ( ) . count , 11 , 'Just the message head and conversation parts is rendered.' ) ;
124135 server . create ( 'conversation-part' , { conversation } ) ;
125136
126- assert . equal ( page . conversationThread . conversationParts ( ) . count , 1 , 'No notification yet, so new part was not rendered.' ) ;
137+ assert . equal ( page . conversationThread . conversationParts ( ) . count , 11 , 'No notification yet, so new part was not rendered.' ) ;
127138 let conversationChannelService = this . application . __container__ . lookup ( 'service:conversation-channel' ) ;
128139 let socket = get ( conversationChannelService , 'socket.socket' ) ;
129140 let [ channel ] = socket . channels ;
130141 channel . trigger ( 'new:conversation-part' , { } ) ;
131142
132143 andThen ( ( ) => {
133- assert . equal ( page . conversationThread . conversationParts ( ) . count , 2 , 'Notification was sent. New part is rendered.' ) ;
144+ assert . equal ( page . conversationThread . conversationParts ( ) . count , 12 , 'Notification was sent. New part is rendered.' ) ;
134145 } ) ;
135146} ) ;
136147
0 commit comments