Skip to content

Commit c8f1744

Browse files
committed
Add a test for the setting
1 parent 59eda76 commit c8f1744

File tree

1 file changed

+95
-5
lines changed

1 file changed

+95
-5
lines changed

ui-tests/tests/ui-config.spec.ts

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { User } from '@jupyterlab/services';
1313
import { UUID } from '@lumino/coreutils';
1414

15-
import { openChat, openSettings, sendMessage, USER } from './test-utils';
15+
import { openChat, openSettings, USER } from './test-utils';
1616

1717
const FILENAME = 'my-chat.chat';
1818
const MSG_CONTENT = 'Hello World!';
@@ -46,15 +46,20 @@ test.describe('#settings', () => {
4646

4747
test('should have default settings values', async ({ page }) => {
4848
const settings = await openSettings(page);
49-
const sendWithShiftEnter = settings?.getByRole('checkbox', {
49+
const sendWithShiftEnter = settings.getByRole('checkbox', {
5050
name: 'sendWithShiftEnter'
5151
});
52-
expect(sendWithShiftEnter!).not.toBeChecked();
52+
expect(sendWithShiftEnter).not.toBeChecked();
5353

54-
const stackMessages = settings?.getByRole('checkbox', {
54+
const stackMessages = settings.getByRole('checkbox', {
5555
name: 'stackMessages'
5656
});
57-
expect(stackMessages!).toBeChecked();
57+
expect(stackMessages).toBeChecked();
58+
59+
const showDeleted = settings.getByRole('checkbox', {
60+
name: 'showDeleted'
61+
});
62+
expect(showDeleted).not.toBeChecked();
5863
});
5964
});
6065

@@ -316,3 +321,88 @@ test.describe('#typingNotification', () => {
316321
expect(result?.[1] !== result?.[2]);
317322
});
318323
});
324+
325+
test.describe('#showDeletedMessages', () => {
326+
const msg1 = {
327+
type: 'msg',
328+
id: UUID.uuid4(),
329+
sender: USERNAME,
330+
body: '',
331+
time: 1714116341,
332+
deleted: true
333+
};
334+
const msg2 = {
335+
type: 'msg',
336+
id: UUID.uuid4(),
337+
sender: USERNAME,
338+
body: 'Message not deleted',
339+
time: 1714116341
340+
};
341+
const chatContent = {
342+
messages: [msg1, msg2],
343+
users: {}
344+
};
345+
346+
test.beforeEach(async ({ page }) => {
347+
// Create a chat file with content
348+
await page.filebrowser.contents.uploadContent(
349+
JSON.stringify(chatContent),
350+
'text',
351+
FILENAME
352+
);
353+
});
354+
355+
test.afterEach(async ({ page }) => {
356+
if (await page.filebrowser.contents.fileExists(FILENAME)) {
357+
await page.filebrowser.contents.deleteFile(FILENAME);
358+
}
359+
});
360+
361+
test('Should toggle the deleted message visibility', async ({ page }) => {
362+
const chatPanel = await openChat(page, FILENAME);
363+
const messages = chatPanel.locator('.jp-chat-message');
364+
await expect(messages).toHaveCount(1);
365+
366+
/**
367+
* Checking the checkbox should display the deleted message.
368+
*/
369+
const settings = await openSettings(page);
370+
const showDeleted = settings?.getByRole('checkbox', {
371+
name: 'showDeleted'
372+
});
373+
374+
await showDeleted.check();
375+
376+
// wait for the settings to be saved
377+
await expect(page.activity.getTabLocator('Settings')).toHaveAttribute(
378+
'class',
379+
/jp-mod-dirty/
380+
);
381+
await expect(page.activity.getTabLocator('Settings')).not.toHaveAttribute(
382+
'class',
383+
/jp-mod-dirty/
384+
);
385+
386+
await page.activity.activateTab(FILENAME);
387+
await expect(messages).toHaveCount(2);
388+
389+
/**
390+
* Unchecking the checkbox should hide the deleted message.
391+
*/
392+
await page.activity.activateTab('Settings');
393+
await showDeleted.uncheck();
394+
395+
// wait for the settings to be saved
396+
await expect(page.activity.getTabLocator('Settings')).toHaveAttribute(
397+
'class',
398+
/jp-mod-dirty/
399+
);
400+
await expect(page.activity.getTabLocator('Settings')).not.toHaveAttribute(
401+
'class',
402+
/jp-mod-dirty/
403+
);
404+
405+
await page.activity.activateTab(FILENAME);
406+
await expect(messages).toHaveCount(1);
407+
});
408+
});

0 commit comments

Comments
 (0)