@@ -16,17 +16,8 @@ limitations under the License.
16
16
17
17
/// <reference types="cypress" />
18
18
19
- import type { EventType , MsgType , ISendEventResponse , IContent } from "matrix-js-sdk/src/matrix" ;
20
- import { SettingLevel } from "../../../src/settings/SettingLevel" ;
19
+ import type { MsgType , IContent } from "matrix-js-sdk/src/matrix" ;
21
20
import { HomeserverInstance } from "../../plugins/utils/homeserver" ;
22
- import Chainable = Cypress . Chainable ;
23
-
24
- const sendEvent = ( roomId : string ) : Chainable < ISendEventResponse > => {
25
- return cy . sendEvent ( roomId , null , "m.room.message" as EventType , {
26
- msgtype : "m.text" as MsgType ,
27
- body : "Message" ,
28
- } ) ;
29
- } ;
30
21
31
22
/** generate a message event which will take up some room on the page. */
32
23
function mkPadding ( n : number ) : IContent {
@@ -40,37 +31,13 @@ function mkPadding(n: number): IContent {
40
31
41
32
describe ( "Editing" , ( ) => {
42
33
let homeserver : HomeserverInstance ;
43
- let roomId : string ;
44
-
45
- // Edit "Message"
46
- const editLastMessage = ( edit : string ) => {
47
- cy . get ( ".mx_EventTile_last" ) . realHover ( ) . findByRole ( "button" , { name : "Edit" } ) . click ( ) ;
48
- cy . findByRole ( "textbox" , { name : "Edit message" } ) . type ( `{selectAll}{del}${ edit } {enter}` ) ;
49
- } ;
50
-
51
- const clickEditedMessage = ( edited : string ) => {
52
- // Assert that the message was edited
53
- cy . contains ( ".mx_EventTile" , edited )
54
- . should ( "exist" )
55
- . within ( ( ) => {
56
- // Click to display the message edit history dialog
57
- cy . contains ( ".mx_EventTile_edited" , "(edited)" ) . click ( ) ;
58
- } ) ;
59
- } ;
60
-
61
- const clickButtonViewSource = ( ) => {
62
- // Assert that "View Source" button is rendered and click it
63
- cy . get ( ".mx_EventTile .mx_EventTile_line" ) . realHover ( ) . findByRole ( "button" , { name : "View Source" } ) . click ( ) ;
64
- } ;
65
34
66
35
beforeEach ( ( ) => {
67
36
cy . startHomeserver ( "default" ) . then ( ( data ) => {
68
37
homeserver = data ;
69
38
cy . initTestUser ( homeserver , "Edith" ) . then ( ( ) => {
70
- cy . createRoom ( { name : "Test room" } ) . then ( ( _room1Id ) => {
71
- roomId = _room1Id ;
72
- } ) ,
73
- cy . injectAxe ( ) ;
39
+ cy . createRoom ( { name : "Test room" } ) ;
40
+ cy . injectAxe ( ) ;
74
41
} ) ;
75
42
} ) ;
76
43
} ) ;
@@ -79,224 +46,6 @@ describe("Editing", () => {
79
46
cy . stopHomeserver ( homeserver ) ;
80
47
} ) ;
81
48
82
- it ( "should render and interact with the message edit history dialog" , ( ) => {
83
- // Click the "Remove" button on the message edit history dialog
84
- const clickButtonRemove = ( ) => {
85
- cy . get ( ".mx_EventTile_line" ) . realHover ( ) . findByRole ( "button" , { name : "Remove" } ) . click ( ) ;
86
- } ;
87
-
88
- cy . visit ( "/#/room/" + roomId ) ;
89
-
90
- // Send "Message"
91
- sendEvent ( roomId ) ;
92
-
93
- cy . get ( ".mx_RoomView_MessageList" ) . within ( ( ) => {
94
- // Edit "Message" to "Massage"
95
- editLastMessage ( "Massage" ) ;
96
-
97
- // Assert that the edit label is visible
98
- cy . get ( ".mx_EventTile_edited" ) . should ( "be.visible" ) ;
99
-
100
- clickEditedMessage ( "Massage" ) ;
101
- } ) ;
102
-
103
- cy . get ( ".mx_Dialog" ) . within ( ( ) => {
104
- // Assert that the message edit history dialog is rendered
105
- cy . get ( ".mx_MessageEditHistoryDialog" ) . within ( ( ) => {
106
- // Assert CSS styles which are difficult or cannot be detected with snapshots are applied as expected
107
- cy . get ( "li" ) . should ( "have.css" , "clear" , "both" ) ;
108
- cy . get ( ".mx_EventTile .mx_MessageTimestamp" )
109
- . should ( "have.css" , "position" , "absolute" )
110
- . should ( "have.css" , "inset-inline-start" , "0px" )
111
- . should ( "have.css" , "text-align" , "center" ) ;
112
- // Assert that monospace characters can fill the content line as expected
113
- cy . get ( ".mx_EventTile .mx_EventTile_content" ) . should ( "have.css" , "margin-inline-end" , "0px" ) ;
114
-
115
- // Assert that zero block start padding is applied to mx_EventTile as expected
116
- // See: .mx_EventTile on _EventTile.pcss
117
- cy . get ( ".mx_EventTile" ) . should ( "have.css" , "padding-block-start" , "0px" ) ;
118
-
119
- // Assert that the date separator is rendered at the top
120
- cy . get ( "li:nth-child(1) .mx_TimelineSeparator" ) . within ( ( ) => {
121
- cy . get ( "h2" ) . within ( ( ) => {
122
- cy . findByText ( "today" ) . should ( "have.css" , "text-transform" , "capitalize" ) ;
123
- } ) ;
124
- } ) ;
125
-
126
- // Assert that the edited message is rendered under the date separator
127
- cy . get ( "li:nth-child(2) .mx_EventTile" ) . within ( ( ) => {
128
- // Assert that the edited message body consists of both deleted character and inserted character
129
- // Above the first "e" of "Message" was replaced with "a"
130
- cy . get ( ".mx_EventTile_content .mx_EventTile_body" ) . should ( "have.text" , "Meassage" ) ;
131
-
132
- cy . get ( ".mx_EventTile_content .mx_EventTile_body" ) . within ( ( ) => {
133
- cy . get ( ".mx_EditHistoryMessage_deletion" ) . within ( ( ) => {
134
- cy . findByText ( "e" ) ;
135
- } ) ;
136
- cy . get ( ".mx_EditHistoryMessage_insertion" ) . within ( ( ) => {
137
- cy . findByText ( "a" ) ;
138
- } ) ;
139
- } ) ;
140
- } ) ;
141
-
142
- // Assert that the original message is rendered at the bottom
143
- cy . get ( "li:nth-child(3) .mx_EventTile" ) . within ( ( ) => {
144
- cy . get ( ".mx_EventTile_content .mx_EventTile_body" ) . within ( ( ) => {
145
- cy . findByText ( "Message" ) ;
146
- } ) ;
147
- } ) ;
148
- } ) ;
149
- } ) ;
150
-
151
- // Exclude timestamps from a snapshot
152
- const percyCSS = ".mx_MessageTimestamp { visibility: hidden !important; }" ;
153
-
154
- // Take a snapshot of the dialog
155
- cy . get ( ".mx_Dialog_wrapper" ) . percySnapshotElement ( "Message edit history dialog" , { percyCSS } ) ;
156
-
157
- cy . get ( ".mx_Dialog" ) . within ( ( ) => {
158
- cy . get ( ".mx_MessageEditHistoryDialog li:nth-child(2) .mx_EventTile" ) . within ( ( ) => {
159
- cy . get ( ".mx_EventTile_content .mx_EventTile_body" ) . should ( "have.text" , "Meassage" ) ;
160
-
161
- // Click the "Remove" button again
162
- clickButtonRemove ( ) ;
163
- } ) ;
164
-
165
- // Do nothing and close the dialog to confirm that the message edit history dialog is rendered
166
- cy . get ( ".mx_TextInputDialog" ) . closeDialog ( ) ;
167
-
168
- // Assert that the message edit history dialog is rendered again after it was closed
169
- cy . get ( ".mx_MessageEditHistoryDialog li:nth-child(2) .mx_EventTile" ) . within ( ( ) => {
170
- cy . get ( ".mx_EventTile_content .mx_EventTile_body" ) . should ( "have.text" , "Meassage" ) ;
171
-
172
- // Click the "Remove" button again
173
- clickButtonRemove ( ) ;
174
- } ) ;
175
-
176
- // This time remove the message really
177
- cy . get ( ".mx_TextInputDialog" ) . within ( ( ) => {
178
- cy . findByRole ( "textbox" , { name : "Reason (optional)" } ) . type ( "This is a test." ) ; // Reason
179
- cy . findByRole ( "button" , { name : "Remove" } ) . click ( ) ;
180
- } ) ;
181
-
182
- // Assert that the message edit history dialog is rendered again
183
- cy . get ( ".mx_MessageEditHistoryDialog" ) . within ( ( ) => {
184
- // Assert that the date is rendered
185
- cy . get ( "li:nth-child(1) .mx_TimelineSeparator" ) . within ( ( ) => {
186
- cy . get ( "h2" ) . within ( ( ) => {
187
- cy . findByText ( "today" ) . should ( "have.css" , "text-transform" , "capitalize" ) ;
188
- } ) ;
189
- } ) ;
190
-
191
- // Assert that the original message is rendered under the date on the dialog
192
- cy . get ( "li:nth-child(2) .mx_EventTile" ) . within ( ( ) => {
193
- cy . get ( ".mx_EventTile_content .mx_EventTile_body" ) . within ( ( ) => {
194
- cy . findByText ( "Message" ) ;
195
- } ) ;
196
- } ) ;
197
-
198
- // Assert that the edited message is gone
199
- cy . contains ( ".mx_EventTile_content .mx_EventTile_body" , "Meassage" ) . should ( "not.exist" ) ;
200
-
201
- cy . closeDialog ( ) ;
202
- } ) ;
203
- } ) ;
204
-
205
- // Assert that the main timeline is rendered
206
- cy . get ( ".mx_RoomView_MessageList" ) . within ( ( ) => {
207
- cy . get ( ".mx_EventTile_last .mx_RedactedBody" ) . within ( ( ) => {
208
- // Assert that the placeholder is rendered
209
- cy . findByText ( "Message deleted" ) ;
210
- } ) ;
211
- } ) ;
212
- } ) ;
213
-
214
- it ( "should render 'View Source' button in developer mode on the message edit history dialog" , ( ) => {
215
- cy . visit ( "/#/room/" + roomId ) ;
216
-
217
- // Send "Message"
218
- sendEvent ( roomId ) ;
219
-
220
- cy . get ( ".mx_RoomView_MessageList" ) . within ( ( ) => {
221
- // Edit "Message" to "Massage"
222
- editLastMessage ( "Massage" ) ;
223
-
224
- // Assert that the edit label is visible
225
- cy . get ( ".mx_EventTile_edited" ) . should ( "be.visible" ) ;
226
-
227
- clickEditedMessage ( "Massage" ) ;
228
- } ) ;
229
-
230
- cy . get ( ".mx_Dialog" ) . within ( ( ) => {
231
- // Assert that the original message is rendered
232
- cy . get ( ".mx_MessageEditHistoryDialog li:nth-child(3)" ) . within ( ( ) => {
233
- // Assert that "View Source" is not rendered
234
- cy . get ( ".mx_EventTile .mx_EventTile_line" )
235
- . realHover ( )
236
- . findByRole ( "button" , { name : "View Source" } )
237
- . should ( "not.exist" ) ;
238
- } ) ;
239
-
240
- cy . closeDialog ( ) ;
241
- } ) ;
242
-
243
- // Enable developer mode
244
- cy . setSettingValue ( "developerMode" , null , SettingLevel . ACCOUNT , true ) ;
245
-
246
- cy . get ( ".mx_RoomView_MessageList" ) . within ( ( ) => {
247
- clickEditedMessage ( "Massage" ) ;
248
- } ) ;
249
-
250
- cy . get ( ".mx_Dialog" ) . within ( ( ) => {
251
- // Assert that the edited message is rendered
252
- cy . get ( ".mx_MessageEditHistoryDialog li:nth-child(2)" ) . within ( ( ) => {
253
- // Assert that "Remove" button for the original message is rendered
254
- cy . get ( ".mx_EventTile .mx_EventTile_line" ) . realHover ( ) . findByRole ( "button" , { name : "Remove" } ) ;
255
-
256
- clickButtonViewSource ( ) ;
257
- } ) ;
258
-
259
- // Assert that view source dialog is rendered and close the dialog
260
- cy . get ( ".mx_ViewSource" ) . closeDialog ( ) ;
261
-
262
- // Assert that the original message is rendered
263
- cy . get ( ".mx_MessageEditHistoryDialog li:nth-child(3)" ) . within ( ( ) => {
264
- // Assert that "Remove" button for the original message does not exist
265
- cy . get ( ".mx_EventTile .mx_EventTile_line" )
266
- . realHover ( )
267
- . findByRole ( "button" , { name : "Remove" } )
268
- . should ( "not.exist" ) ;
269
-
270
- clickButtonViewSource ( ) ;
271
- } ) ;
272
-
273
- // Assert that view source dialog is rendered and close the dialog
274
- cy . get ( ".mx_ViewSource" ) . closeDialog ( ) ;
275
- } ) ;
276
- } ) ;
277
-
278
- it ( "should close the composer when clicking save after making a change and undoing it" , ( ) => {
279
- cy . visit ( "/#/room/" + roomId ) ;
280
-
281
- sendEvent ( roomId ) ;
282
-
283
- // Edit message
284
- cy . get ( ".mx_RoomView_body .mx_EventTile" ) . within ( ( ) => {
285
- cy . findByText ( "Message" ) ;
286
- cy . get ( ".mx_EventTile_line" ) . realHover ( ) . findByRole ( "button" , { name : "Edit" } ) . click ( ) . checkA11y ( ) ;
287
- cy . get ( ".mx_EventTile_line" )
288
- . findByRole ( "textbox" , { name : "Edit message" } )
289
- . type ( "Foo{backspace}{backspace}{backspace}{enter}" )
290
- . checkA11y ( ) ;
291
- } ) ;
292
- cy . get ( ".mx_RoomView_body .mx_EventTile[data-scroll-tokens]" ) . within ( ( ) => {
293
- cy . findByText ( "Message" ) ;
294
- } ) ;
295
-
296
- // Assert that the edit composer has gone away
297
- cy . findByRole ( "textbox" , { name : "Edit message" } ) . should ( "not.exist" ) ;
298
- } ) ;
299
-
300
49
it ( "should correctly display events which are edited, where we lack the edit event" , ( ) => {
301
50
// This tests the behaviour when a message has been edited some time after it has been sent, and we
302
51
// jump back in room history to view the event, but do not have the actual edit event.
0 commit comments