1+ import { faker } from '@faker-js/faker' ;
2+
13import { Users } from './fixtures/userStates' ;
24import { HomeChannel , Utils } from './page-objects' ;
35import { ExportMessagesTab } from './page-objects/fragments/export-messages-tab' ;
4- import { createTargetChannel } from './utils' ;
6+ import { createTargetChannel , deleteChannel } from './utils' ;
57import { test , expect } from './utils/test' ;
68
79test . use ( { storageState : Users . admin . state } ) ;
810
9- test . describe . serial ( 'export-messages' , ( ) => {
11+ const uniqueMessage = ( ) : string => `msg-${ faker . string . uuid ( ) } ` ;
12+
13+ test . describe ( 'export-messages' , ( ) => {
1014 let poHomeChannel : HomeChannel ;
1115 let poUtils : Utils ;
1216 let targetChannel : string ;
@@ -22,6 +26,13 @@ test.describe.serial('export-messages', () => {
2226 await page . goto ( '/home' ) ;
2327 } ) ;
2428
29+ test . afterAll ( async ( { api } ) => {
30+ await Promise . all ( [
31+ api . post ( '/users.setPreferences' , { userId : 'rocketchat.internal.admin.test' , data : { hideFlexTab : false } } ) ,
32+ deleteChannel ( api , targetChannel ) ,
33+ ] ) ;
34+ } ) ;
35+
2536 test ( 'should all export methods be available in targetChannel' , async ( { page } ) => {
2637 const exportMessagesTab = new ExportMessagesTab ( page ) ;
2738
@@ -66,15 +77,16 @@ test.describe.serial('export-messages', () => {
6677
6778 test ( 'should display an error when trying to send email without filling to users or to additional emails' , async ( { page } ) => {
6879 const exportMessagesTab = new ExportMessagesTab ( page ) ;
80+ const testMessage = uniqueMessage ( ) ;
6981
7082 await poHomeChannel . sidenav . openChat ( targetChannel ) ;
71- await poHomeChannel . content . sendMessage ( 'hello world' ) ;
83+ await poHomeChannel . content . sendMessage ( testMessage ) ;
7284 await poHomeChannel . tabs . kebab . click ( { force : true } ) ;
7385 await poHomeChannel . tabs . btnExportMessages . click ( ) ;
7486
7587 await expect ( poHomeChannel . btnContextualbarClose ) . toBeVisible ( ) ;
7688
77- await poHomeChannel . content . getMessageByText ( 'hello world' ) . click ( ) ;
89+ await poHomeChannel . content . getMessageByText ( testMessage ) . click ( ) ;
7890 await exportMessagesTab . send ( ) ;
7991
8092 await expect (
@@ -96,14 +108,68 @@ test.describe.serial('export-messages', () => {
96108 } ) ;
97109
98110 test ( 'should be able to send messages after closing export messages' , async ( ) => {
111+ const message1 = uniqueMessage ( ) ;
112+ const message2 = uniqueMessage ( ) ;
113+
99114 await poHomeChannel . sidenav . openChat ( targetChannel ) ;
115+ await poHomeChannel . content . sendMessage ( message1 ) ;
100116 await poHomeChannel . tabs . kebab . click ( { force : true } ) ;
101117 await poHomeChannel . tabs . btnExportMessages . click ( ) ;
102118
103- await poHomeChannel . content . getMessageByText ( 'hello world' ) . click ( ) ;
119+ await poHomeChannel . content . getMessageByText ( message1 ) . click ( ) ;
104120 await poHomeChannel . btnContextualbarClose . click ( ) ;
105- await poHomeChannel . content . sendMessage ( 'hello export' ) ;
121+ await poHomeChannel . content . sendMessage ( message2 ) ;
122+
123+ await expect ( poHomeChannel . content . getMessageByText ( message2 ) ) . toBeVisible ( ) ;
124+ } ) ;
125+
126+ test ( 'should be able to select a single message to export' , async ( { page } ) => {
127+ const exportMessagesTab = new ExportMessagesTab ( page ) ;
128+ const message1 = uniqueMessage ( ) ;
129+ const message2 = uniqueMessage ( ) ;
130+
131+ await poHomeChannel . sidenav . openChat ( targetChannel ) ;
132+ await poHomeChannel . content . sendMessage ( message1 ) ;
133+ await poHomeChannel . content . sendMessage ( message2 ) ;
134+
135+ await poHomeChannel . tabs . kebab . click ( { force : true } ) ;
136+ await poHomeChannel . tabs . btnExportMessages . click ( ) ;
137+ await expect ( exportMessagesTab . dialog ) . toBeVisible ( ) ;
138+
139+ await poHomeChannel . content . getMessageByText ( message1 ) . click ( ) ;
140+
141+ await expect ( exportMessagesTab . getMessageCheckbox ( message1 ) ) . toBeChecked ( ) ;
142+ await expect ( exportMessagesTab . getMessageCheckbox ( message2 ) ) . not . toBeChecked ( ) ;
143+ await expect ( exportMessagesTab . clearSelectionButton ) . toBeEnabled ( ) ;
144+
145+ await expect ( exportMessagesTab . sendButton ) . toBeEnabled ( ) ;
146+ } ) ;
147+
148+ // TODO: Fix this test - the test is failing because when selecting the message, the import messages tab becomes not visible
149+ // and the message is not selected.
150+ test . fail ( 'should be able to select a single message to export with hide contextual bar preference enabled' , async ( { page, api } ) => {
151+ await api . post ( '/users.setPreferences' , {
152+ userId : 'rocketchat.internal.admin.test' ,
153+ data : { hideFlexTab : true } ,
154+ } ) ;
155+ const message1 = uniqueMessage ( ) ;
156+ const message2 = uniqueMessage ( ) ;
157+
158+ const exportMessagesTab = new ExportMessagesTab ( page ) ;
159+
160+ await poHomeChannel . sidenav . openChat ( targetChannel ) ;
161+ await poHomeChannel . content . sendMessage ( message1 ) ;
162+ await poHomeChannel . content . sendMessage ( message2 ) ;
163+
164+ await poHomeChannel . tabs . kebab . click ( { force : true } ) ;
165+ await poHomeChannel . tabs . btnExportMessages . click ( ) ;
166+
167+ await expect ( exportMessagesTab . dialog ) . toBeVisible ( ) ;
168+ await poHomeChannel . content . getMessageByText ( message1 ) . click ( ) ;
169+
170+ await expect ( exportMessagesTab . getMessageCheckbox ( message1 ) ) . toBeChecked ( ) ;
171+ await expect ( exportMessagesTab . clearSelectionButton ) . toBeEnabled ( ) ;
106172
107- await expect ( poHomeChannel . content . getMessageByText ( 'hello export' ) ) . toBeVisible ( ) ;
173+ await expect ( exportMessagesTab . sendButton ) . toBeEnabled ( ) ;
108174 } ) ;
109175} ) ;
0 commit comments