11import { AppDataVisibility , Context , PermissionLevel } from '@graasp/sdk' ;
22
3+ import type { CommentAppData } from '../../../src/config/appData' ;
34import {
45 buildCommentContainerDataCy ,
56 buildDataCy ,
@@ -25,6 +26,17 @@ const defaultAppData = [
2526const MESSAGE_INPUT = 'textarea[name="Message"]' ;
2627const SEND_BUTTON = '[name="Send message"]' ;
2728
29+ const goToConversation = ( appData : CommentAppData ) => {
30+ const txt = appData . data . content ;
31+ cy . contains ( 'tr' , txt . slice ( 0 , 10 ) )
32+ . find ( 'button[title="Open conversation"]' )
33+ . click ( ) ;
34+ } ;
35+
36+ const createConversation = ( ) => {
37+ cy . get ( 'button:contains("New conversation")' ) . click ( ) ;
38+ } ;
39+
2840describe ( 'Player View' , ( ) => {
2941 it ( 'Show messages and write a new one' , ( ) => {
3042 cy . setUpApi (
@@ -39,6 +51,9 @@ describe('Player View', () => {
3951 ) ;
4052 cy . visit ( '/' ) ;
4153
54+ // go to conversation
55+ goToConversation ( defaultAppData [ 0 ] ) ;
56+
4257 // expect previously saved app data
4358 const [ previousAppData ] = defaultAppData ;
4459 cy . get ( buildDataCy ( buildCommentContainerDataCy ( previousAppData . id ) ) ) . should (
@@ -76,6 +91,7 @@ describe('Player View', () => {
7691 } ,
7792 ) ;
7893 cy . visit ( '/' ) ;
94+ createConversation ( ) ;
7995
8096 // expect cue
8197 cy . get ( buildDataCy ( buildCommentContainerDataCy ( 'cue' ) ) ) . should (
@@ -102,32 +118,33 @@ describe('Player View', () => {
102118 } ) ;
103119
104120 it ( 'Show dates' , ( ) => {
121+ const appData = [
122+ {
123+ account : CURRENT_MEMBER ,
124+ createdAt : '2025-11-18T16:35:22.010Z' ,
125+ creator : CURRENT_MEMBER ,
126+ data : { content : 'A previously saved message' } ,
127+ id : '0' ,
128+ item : MOCK_SERVER_ITEM ,
129+ type : 'comment' ,
130+ updatedAt : '2025-11-18T16:35:22.010Z' ,
131+ visibility : AppDataVisibility . Member ,
132+ } ,
133+ {
134+ account : CURRENT_MEMBER ,
135+ createdAt : '2024-11-18T16:35:22.010Z' ,
136+ creator : CURRENT_MEMBER ,
137+ data : { content : 'A previously saved message' } ,
138+ id : '1' ,
139+ item : MOCK_SERVER_ITEM ,
140+ type : 'comment' ,
141+ updatedAt : '2025-11-18T16:35:22.010Z' ,
142+ visibility : AppDataVisibility . Member ,
143+ } ,
144+ ] ;
105145 cy . setUpApi (
106146 {
107- appData : [
108- {
109- account : CURRENT_MEMBER ,
110- createdAt : '2025-11-18T16:35:22.010Z' ,
111- creator : CURRENT_MEMBER ,
112- data : { content : 'A previously saved message' } ,
113- id : '0' ,
114- item : MOCK_SERVER_ITEM ,
115- type : 'comment' ,
116- updatedAt : '2025-11-18T16:35:22.010Z' ,
117- visibility : AppDataVisibility . Member ,
118- } ,
119- {
120- account : CURRENT_MEMBER ,
121- createdAt : '2024-11-18T16:35:22.010Z' ,
122- creator : CURRENT_MEMBER ,
123- data : { content : 'A previously saved message' } ,
124- id : '1' ,
125- item : MOCK_SERVER_ITEM ,
126- type : 'comment' ,
127- updatedAt : '2025-11-18T16:35:22.010Z' ,
128- visibility : AppDataVisibility . Member ,
129- } ,
130- ] ,
147+ appData,
131148 appSettings : [ MOCK_APP_SETTING ] ,
132149 } ,
133150 {
@@ -136,6 +153,8 @@ describe('Player View', () => {
136153 } ,
137154 ) ;
138155 cy . visit ( '/' ) ;
156+ // go to conversation
157+ goToConversation ( appData [ 0 ] ) ;
139158
140159 // expect dates
141160 cy . get ( '#root' ) . should ( 'contain' , 'November 18, 2024' ) ;
@@ -154,6 +173,7 @@ describe('Player View', () => {
154173 } ,
155174 ) ;
156175 cy . visit ( '/' ) ;
176+ createConversation ( ) ;
157177
158178 const [ suggestion ] = MOCK_APP_SETTING . data . starterSuggestions ;
159179
@@ -187,6 +207,7 @@ describe('Player View', () => {
187207 } ,
188208 ) ;
189209 cy . visit ( '/' ) ;
210+ createConversation ( ) ;
190211
191212 // type and send message with enter key
192213 const message = 'My message' ;
@@ -216,4 +237,109 @@ describe('Player View', () => {
216237 message1 ,
217238 ) ;
218239 } ) ;
240+
241+ it ( 'Show all conversations' , ( ) => {
242+ const appData = [
243+ // first conversation
244+ {
245+ account : CURRENT_MEMBER ,
246+ createdAt : '2026-11-18T16:35:22.010Z' ,
247+ creator : CURRENT_MEMBER ,
248+ data : {
249+ content : 'My conversation' ,
250+ conversationId : 'conversation-id-2' ,
251+ } ,
252+ id : '12' ,
253+ item : MOCK_SERVER_ITEM ,
254+ type : 'comment' ,
255+ updatedAt : '2026-11-18T16:35:22.010Z' ,
256+ visibility : AppDataVisibility . Member ,
257+ } ,
258+ // second, legacy conversation
259+ {
260+ account : CURRENT_MEMBER ,
261+ createdAt : '2025-10-18T16:35:22.010Z' ,
262+ creator : CURRENT_MEMBER ,
263+ data : { content : 'A previously saved message' } ,
264+ id : '0' ,
265+ item : MOCK_SERVER_ITEM ,
266+ type : 'comment' ,
267+ updatedAt : '2025-11-18T16:35:22.010Z' ,
268+ visibility : AppDataVisibility . Member ,
269+ } ,
270+ {
271+ account : CURRENT_MEMBER ,
272+ createdAt : '2024-01-18T16:35:22.010Z' ,
273+ creator : CURRENT_MEMBER ,
274+ data : { content : 'Another saved message' } ,
275+ id : '14' ,
276+ item : MOCK_SERVER_ITEM ,
277+ type : 'comment' ,
278+ updatedAt : '2025-11-18T17:35:22.010Z' ,
279+ visibility : AppDataVisibility . Member ,
280+ } ,
281+ // third conversation
282+ {
283+ account : CURRENT_MEMBER ,
284+ createdAt : '2023-11-18T16:35:22.010Z' ,
285+ creator : CURRENT_MEMBER ,
286+ data : {
287+ content : 'A question I asked' ,
288+ conversationId : 'conversation-id-1' ,
289+ } ,
290+ id : '13' ,
291+ item : MOCK_SERVER_ITEM ,
292+ type : 'comment' ,
293+ updatedAt : '2023-11-18T16:35:22.010Z' ,
294+ visibility : AppDataVisibility . Member ,
295+ } ,
296+ ] ;
297+ cy . setUpApi (
298+ {
299+ appData,
300+ appSettings : [ MOCK_APP_SETTING ] ,
301+ } ,
302+ {
303+ context : Context . Player ,
304+ permission : PermissionLevel . Write ,
305+ } ,
306+ ) ;
307+ cy . visit ( '/' ) ;
308+
309+ // should show 3 conversations ordered by creation date desc
310+ cy . get ( 'tr' ) . then ( ( rows ) => {
311+ expect ( rows ) . to . have . length ( 3 ) ;
312+
313+ expect ( rows [ 0 ] ) . to . contain ( appData [ 0 ] . data . content ) ;
314+ // content is cut because it is too long
315+ expect ( rows [ 1 ] ) . to . contain ( appData [ 1 ] . data . content . slice ( 0 , 10 ) ) ;
316+ expect ( rows [ 2 ] ) . to . contain ( appData [ 3 ] . data . content ) ;
317+ } ) ;
318+
319+ // go to first conversation and show one message
320+ goToConversation ( appData [ 0 ] ) ;
321+ // expect one user message only
322+ cy . get ( buildDataCy ( buildCommentContainerDataCy ( appData [ 0 ] . id ) ) ) . should (
323+ 'be.visible' ,
324+ ) ;
325+ cy . get ( buildDataCy ( buildCommentContainerDataCy ( appData [ 1 ] . id ) ) ) . should (
326+ 'not.exist' ,
327+ ) ;
328+
329+ // go back to conversations
330+ cy . get ( 'button:contains("Go back to conversations")' ) . click ( ) ;
331+
332+ // go to second legacy conversation
333+ goToConversation ( appData [ 1 ] ) ;
334+ // expect one user message only
335+ cy . get ( buildDataCy ( buildCommentContainerDataCy ( appData [ 1 ] . id ) ) ) . should (
336+ 'be.visible' ,
337+ ) ;
338+ cy . get ( buildDataCy ( buildCommentContainerDataCy ( appData [ 2 ] . id ) ) ) . should (
339+ 'be.visible' ,
340+ ) ;
341+ cy . get ( buildDataCy ( buildCommentContainerDataCy ( appData [ 3 ] . id ) ) ) . should (
342+ 'not.exist' ,
343+ ) ;
344+ } ) ;
219345} ) ;
0 commit comments