11import data from '../../shared/testing/data' ;
22
3- const thread = data . threads [ 0 ] ;
4- const community = data . communities . find (
5- community => community . id === thread . communityId
3+ const user = data . users . find ( user => user . username === 'brian' ) ;
4+ const directMessages = data . usersDirectMessageThreads . filter (
5+ udm => udm . userId === user . id
66) ;
7- const author = data . users . find ( user => user . id === thread . creatorId ) ;
87
98describe ( '/messages/new' , ( ) => {
109 beforeEach ( ( ) => {
11- cy . auth ( author . id ) . then ( ( ) => cy . visit ( '/messages/new' ) ) ;
10+ cy . auth ( user . id ) . then ( ( ) => cy . visit ( '/messages/new' ) ) ;
1211 } ) ;
1312
1413 it ( 'should allow to continue composing message incase of crash or reload' , ( ) => {
@@ -22,3 +21,140 @@ describe('/messages/new', () => {
2221 cy . get ( '[contenteditable="true"]' ) . contains ( newMessage ) ;
2322 } ) ;
2423} ) ;
24+
25+ describe ( '/messages' , ( ) => {
26+ beforeEach ( ( ) => {
27+ cy . auth ( user . id ) . then ( ( ) => cy . visit ( '/messages' ) ) ;
28+ } ) ;
29+
30+ it ( 'should load list of direct messages' , ( ) => {
31+ cy . contains ( 'Max Stoiber and Bryn Jackson' ) . should ( 'be.visible' ) ;
32+ cy . contains ( 'A fifth one' ) . should ( 'be.visible' ) ;
33+
34+ cy . contains ( 'Previous member' ) . should ( 'be.visible' ) ;
35+ cy . contains ( 'No messages yet...' ) . should ( 'be.visible' ) ;
36+
37+ cy . get ( '[data-cy="unread-dm-list-item"]' ) . should ( $p => {
38+ expect ( $p ) . to . have . length ( 1 ) ;
39+ } ) ;
40+ cy . get ( '[data-cy="dm-list-item"]' ) . should ( $p => {
41+ expect ( $p ) . to . have . length ( 1 ) ;
42+ } ) ;
43+ } ) ;
44+
45+ it ( 'should open conversation composer' , ( ) => {
46+ cy . get ( '[data-cy="compose-dm"]' )
47+ . should ( 'be.visible' )
48+ . click ( ) ;
49+ cy . url ( ) . should ( 'eq' , 'http://localhost:3000/messages/new' ) ;
50+ } ) ;
51+
52+ it ( 'should select an individual conversation' , ( ) => {
53+ cy . contains ( 'Max Stoiber and Bryn Jackson' )
54+ . should ( 'be.visible' )
55+ . click ( ) ;
56+ cy . get ( '[data-cy="dm-header"]' ) . should ( 'be.visible' ) ;
57+ cy . get ( '[data-cy="dm-header"]' ) . contains ( 'Max Stoiber, Bryn Jackson' ) ;
58+ cy . get ( '[data-cy="message"]' ) . should ( $p => {
59+ expect ( $p ) . to . have . length ( 5 ) ;
60+ } ) ;
61+ } ) ;
62+
63+ it ( 'should switch conversations' , ( ) => {
64+ cy . contains ( 'Max Stoiber and Bryn Jackson' )
65+ . should ( 'be.visible' )
66+ . click ( ) ;
67+ cy . get ( '[data-cy="dm-header"]' ) . should ( 'be.visible' ) ;
68+ cy . get ( '[data-cy="dm-header"]' ) . contains ( 'Max Stoiber, Bryn Jackson' ) ;
69+ cy . get ( '[data-cy="message"]' ) . should ( $p => {
70+ expect ( $p ) . to . have . length ( 5 ) ;
71+ } ) ;
72+
73+ cy . contains ( 'Previous member' )
74+ . should ( 'be.visible' )
75+ . click ( ) ;
76+ cy . get ( '[data-cy="dm-header"]' ) . should ( 'be.visible' ) ;
77+ cy . get ( '[data-cy="dm-header"]' ) . contains ( 'Previous member' ) ;
78+ cy . get ( '[data-cy="message"]' ) . should ( $p => {
79+ expect ( $p ) . to . have . length ( 0 ) ;
80+ } ) ;
81+ } ) ;
82+
83+ it ( 'should send a message in a conversation' , ( ) => {
84+ cy . contains ( 'Previous member' )
85+ . should ( 'be.visible' )
86+ . click ( ) ;
87+
88+ const newMessage = 'A new message!' ;
89+ cy . get ( '[contenteditable="true"]' ) . type ( newMessage ) ;
90+ cy . get ( '[data-cy="chat-input-send-button"]' ) . click ( ) ;
91+ cy . get ( '[contenteditable="true"]' ) . type ( '' ) ;
92+ cy . contains ( newMessage ) ;
93+
94+ cy . get ( '[data-cy="unread-dm-list-item"]' ) . should ( $p => {
95+ expect ( $p ) . to . have . length ( 0 ) ;
96+ } ) ;
97+
98+ cy . get ( '[data-cy="dm-list-item"]' ) . should ( $p => {
99+ expect ( $p ) . to . have . length ( 2 ) ;
100+ } ) ;
101+
102+ cy . wait ( 2000 ) ;
103+
104+ cy . get ( '[data-cy="dm-list-item"]' )
105+ . first ( )
106+ . contains ( 'Previous member' ) ;
107+ } ) ;
108+ } ) ;
109+
110+ describe ( 'messages tab badge count' , ( ) => {
111+ beforeEach ( ( ) => {
112+ cy . auth ( user . id ) . then ( ( ) => cy . visit ( '/' ) ) ;
113+ } ) ;
114+
115+ it ( 'should show a badge for unread direct messages' , ( ) => {
116+ cy . get ( '[data-cy="unread-badge-1"]' ) . should ( 'be.visible' ) ;
117+ } ) ;
118+
119+ it ( 'should clear the badge when messages tab clicked' , ( ) => {
120+ cy . get ( '[data-cy="unread-badge-1"]' ) . should ( 'be.visible' ) ;
121+ cy . get ( '[data-cy="navbar-messages"]' ) . click ( ) ;
122+ cy . get ( '[data-cy="dm-list-item"]' ) . should ( $p => {
123+ expect ( $p ) . to . have . length ( 1 ) ;
124+ } ) ;
125+ cy . get ( '[data-cy="unread-dm-list-item"]' ) . should ( $p => {
126+ expect ( $p ) . to . have . length ( 1 ) ;
127+ } ) ;
128+ cy . get ( '[data-cy="unread-badge-0"]' ) . should ( 'be.visible' ) ;
129+ } ) ;
130+
131+ it ( 'should not show an unread badge after leaving messages tab' , ( ) => {
132+ cy . get ( '[data-cy="unread-badge-1"]' ) . should ( 'be.visible' ) ;
133+ cy . get ( '[data-cy="navbar-messages"]' ) . click ( ) ;
134+ cy . get ( '[data-cy="dm-list-item"]' ) . should ( $p => {
135+ expect ( $p ) . to . have . length ( 1 ) ;
136+ } ) ;
137+ cy . get ( '[data-cy="unread-dm-list-item"]' ) . should ( $p => {
138+ expect ( $p ) . to . have . length ( 1 ) ;
139+ } ) ;
140+ cy . get ( '[data-cy="unread-badge-0"]' ) . should ( 'be.visible' ) ;
141+ cy . get ( '[data-cy="navbar-home"]' ) . click ( ) ;
142+ cy . get ( '[data-cy="unread-badge-0"]' ) . should ( 'be.visible' ) ;
143+ } ) ;
144+ } ) ;
145+
146+ describe ( 'clearing messages tab' , ( ) => {
147+ beforeEach ( ( ) => {
148+ cy . auth ( user . id ) . then ( ( ) => cy . visit ( '/messages' ) ) ;
149+ } ) ;
150+
151+ it ( 'should clear the badge when landing directly on /messages' , ( ) => {
152+ cy . get ( '[data-cy="dm-list-item"]' ) . should ( $p => {
153+ expect ( $p ) . to . have . length ( 1 ) ;
154+ } ) ;
155+ cy . get ( '[data-cy="unread-dm-list-item"]' ) . should ( $p => {
156+ expect ( $p ) . to . have . length ( 1 ) ;
157+ } ) ;
158+ cy . get ( '[data-cy="unread-badge-0"]' ) . should ( 'be.visible' ) ;
159+ } ) ;
160+ } ) ;
0 commit comments