@@ -4,6 +4,8 @@ import moduleForAcceptance from 'code-corps-ember/tests/helpers/module-for-accep
44import { authenticateSession } from 'code-corps-ember/tests/helpers/ember-simple-auth' ;
55import page from 'code-corps-ember/tests/pages/project/conversations' ;
66
7+ const hour = 3600 * 1000 ;
8+
79function createConversations ( count , project , user ) {
810 return [ ...Array ( count ) ] . map ( ( ) => {
911 let message = server . create ( 'message' , { project } ) ;
@@ -45,12 +47,22 @@ test('Page requires current user to be admin', function(assert) {
4547} ) ;
4648
4749test ( 'Project admin can view list of conversations' , function ( assert ) {
48- assert . expect ( 1 ) ;
50+ assert . expect ( 2 ) ;
4951
5052 let { project, user } = server . create ( 'project-user' , { role : 'admin' } ) ;
5153 authenticateSession ( this . application , { user_id : user . id } ) ;
5254
53- createConversations ( 3 , project , user ) ;
55+ let [ message1 , message2 , message3 ] = server . createList ( 'message' , 3 , { project } ) ;
56+
57+ let [ date1 , date2 , date3 ] = [
58+ Date . now ( ) ,
59+ Date . now ( ) - 5 * hour ,
60+ Date . now ( ) - 1 * hour
61+ ] ;
62+
63+ server . create ( 'conversation' , { message : message1 , user, updatedAt : date1 } ) ;
64+ server . create ( 'conversation' , { message : message2 , user, updatedAt : date2 } ) ;
65+ server . create ( 'conversation' , { message : message3 , user, updatedAt : date3 } ) ;
5466
5567 page . visit ( {
5668 organization : project . organization . slug ,
@@ -59,6 +71,23 @@ test('Project admin can view list of conversations', function(assert) {
5971
6072 andThen ( ( ) => {
6173 assert . equal ( page . conversations ( ) . count , 3 , 'Conversations are rendered' ) ;
74+ let renderedTimeStampOrder = [
75+ page . conversations ( 0 ) . updatedAt . text ,
76+ page . conversations ( 1 ) . updatedAt . text ,
77+ page . conversations ( 2 ) . updatedAt . text
78+ ] ;
79+
80+ let expectedTimeStampOrder = [
81+ 'a few seconds ago' ,
82+ 'an hour ago' ,
83+ '5 hours ago'
84+ ] ;
85+
86+ assert . deepEqual (
87+ renderedTimeStampOrder ,
88+ expectedTimeStampOrder ,
89+ 'Items are rendered in correct order with properly formatted timestamps.'
90+ ) ;
6291 } ) ;
6392} ) ;
6493
0 commit comments