@@ -164,7 +164,7 @@ test.describe('#sendMessages', () => {
164
164
) ;
165
165
} ) ;
166
166
167
- test ( 'should send with cell content' , async ( { page } ) => {
167
+ test ( 'should send with code cell content' , async ( { page } ) => {
168
168
const cellContent = 'a = 1\nprint(f"a={a}")' ;
169
169
const chatPanel = await openChat ( page , FILENAME ) ;
170
170
const messages = chatPanel . locator ( '.jp-chat-messages-container' ) ;
@@ -189,14 +189,56 @@ test.describe('#sendMessages', () => {
189
189
await expect ( sendWithSelection ) . toBeEnabled ( ) ;
190
190
await expect ( sendWithSelection ) . toContainText ( 'Code from 1 active cell' ) ;
191
191
await sendWithSelection . click ( ) ;
192
+ await expect ( messages ! . locator ( '.jp-chat-message' ) ) . toHaveCount ( 1 ) ;
193
+
194
+ // It seems that the markdown renderer adds a new line, but the '\n' inserter when
195
+ // pressing Enter above is trimmed.
196
+ const rendered = messages . locator (
197
+ '.jp-chat-message .jp-chat-rendered-markdown'
198
+ ) ;
199
+ await expect ( rendered ) . toHaveText ( `${ MSG_CONTENT } \n${ cellContent } \n` ) ;
192
200
201
+ // Code should have python language class.
202
+ await expect ( rendered . locator ( 'code' ) ) . toHaveClass ( 'language-python' ) ;
203
+ } ) ;
204
+
205
+ test ( 'should send with markdown cell content' , async ( { page } ) => {
206
+ const cellContent = 'markdown content' ;
207
+ const chatPanel = await openChat ( page , FILENAME ) ;
208
+ const messages = chatPanel . locator ( '.jp-chat-messages-container' ) ;
209
+ const input = chatPanel
210
+ . locator ( '.jp-chat-input-container' )
211
+ . getByRole ( 'combobox' ) ;
212
+ const openerButton = chatPanel . locator (
213
+ '.jp-chat-input-container .jp-chat-send-include-opener'
214
+ ) ;
215
+ const sendWithSelection = page . locator ( '.jp-chat-send-include' ) ;
216
+
217
+ const notebook = await page . notebook . createNew ( ) ;
218
+ // write content in the first cell after changing it to markdown.
219
+ const cell = ( await page . notebook . getCellLocator ( 0 ) ) ! ;
220
+ await page . notebook . setCellType ( 0 , 'markdown' ) ;
221
+ await cell . getByRole ( 'textbox' ) . pressSequentially ( cellContent ) ;
222
+
223
+ await splitMainArea ( page , notebook ! ) ;
224
+
225
+ await input . pressSequentially ( MSG_CONTENT ) ;
226
+ await openerButton . click ( ) ;
227
+ await expect ( sendWithSelection ) . toBeVisible ( ) ;
228
+ await expect ( sendWithSelection ) . toBeEnabled ( ) ;
229
+ await expect ( sendWithSelection ) . toContainText ( 'Code from 1 active cell' ) ;
230
+ await sendWithSelection . click ( ) ;
193
231
await expect ( messages ! . locator ( '.jp-chat-message' ) ) . toHaveCount ( 1 ) ;
194
232
195
233
// It seems that the markdown renderer adds a new line, but the '\n' inserter when
196
234
// pressing Enter above is trimmed.
197
- await expect (
198
- messages . locator ( '.jp-chat-message .jp-chat-rendered-markdown' )
199
- ) . toHaveText ( `${ MSG_CONTENT } \n${ cellContent } \n` ) ;
235
+ const rendered = messages . locator (
236
+ '.jp-chat-message .jp-chat-rendered-markdown'
237
+ ) ;
238
+ await expect ( rendered ) . toHaveText ( `${ MSG_CONTENT } \n${ cellContent } \n` ) ;
239
+
240
+ // Code should not have python language class since it come from a markdown cell.
241
+ await expect ( rendered . locator ( 'code' ) ) . toHaveClass ( '' ) ;
200
242
} ) ;
201
243
202
244
test ( 'should send with text selection' , async ( { page } ) => {
@@ -243,8 +285,12 @@ test.describe('#sendMessages', () => {
243
285
244
286
// It seems that the markdown renderer adds a new line, but the '\n' inserter when
245
287
// pressing Enter above is trimmed.
246
- await expect (
247
- messages . locator ( '.jp-chat-message .jp-chat-rendered-markdown' )
248
- ) . toHaveText ( `${ MSG_CONTENT } \nprint\n` ) ;
288
+ const rendered = messages . locator (
289
+ '.jp-chat-message .jp-chat-rendered-markdown'
290
+ ) ;
291
+ await expect ( rendered ) . toHaveText ( `${ MSG_CONTENT } \nprint\n` ) ;
292
+
293
+ // Code should have python or ipython language class.
294
+ await expect ( rendered . locator ( 'code' ) ) . toHaveClass ( / l a n g u a g e - [ i ] ? p y t h o n / ) ;
249
295
} ) ;
250
296
} ) ;
0 commit comments