Skip to content

Commit 6ee150d

Browse files
committed
Revert "chore: remove almost all tests"
This reverts commit 33d7963.
1 parent 5d2d605 commit 6ee150d

7 files changed

+574
-0
lines changed

e2e/attachment-sizing.test.ts

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as dotenv from 'dotenv';
2+
import { expect } from '@playwright/test';
3+
4+
import selectors from './user/selectors';
5+
import { test } from './user/test';
6+
7+
import ChannelPreview from './user/components/ChannelPreview';
8+
import MessageList from './user/components/MessageList/MessageList';
9+
10+
dotenv.config();
11+
dotenv.config({ path: `.env.local` });
12+
13+
const CHANNEL_NAME = 'attachment-sizing' as const;
14+
const user1Id = process.env.E2E_TEST_USER_1;
15+
const USER1_CHAT_VIEW_CLASSNAME = `.${user1Id}`;
16+
17+
test.describe('add height to video and image attachments', () => {
18+
test.beforeEach(async ({ controller, user }) => {
19+
await controller.openStory('attachment-sizing--user1', selectors.channelPreviewButton);
20+
await user.clicks(ChannelPreview).text(CHANNEL_NAME);
21+
});
22+
23+
test('should add height for video attachments', async ({ page, user }) => {
24+
const videoElementsLocator = page.locator('[data-testid="video-wrapper"]');
25+
const result = await videoElementsLocator.evaluateAll<boolean>(
26+
(videoElements) =>
27+
videoElements.length > 0 &&
28+
videoElements.every((element) => getComputedStyle(element).height.includes('px')),
29+
);
30+
31+
expect(result).toBeTruthy();
32+
await user
33+
.sees(MessageList)
34+
.isScrolledToBottom(`${USER1_CHAT_VIEW_CLASSNAME} ${selectors.messageListContainer}`);
35+
});
36+
37+
test('should add height for single image attachments', async ({ page, user }) => {
38+
const imageElementsLocator = page.locator('[data-testid="image-test"]');
39+
const result = await imageElementsLocator.evaluateAll(
40+
(imageElements) =>
41+
imageElements.length > 0 &&
42+
imageElements.every((element) => getComputedStyle(element).height.includes('px')),
43+
);
44+
45+
expect(result).toBe(true);
46+
await user
47+
.sees(MessageList)
48+
.isScrolledToBottom(`${USER1_CHAT_VIEW_CLASSNAME} ${selectors.messageListContainer}`);
49+
});
50+
});

e2e/autocomplete-mention.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* eslint-disable jest/no-done-callback */
2+
/* eslint-disable jest/require-top-level-describe */
3+
import { expect } from '@playwright/test';
4+
5+
import { test } from './user/test';
6+
import { getMessageInput } from './user/components/MessageInput';
7+
import selectors from './user/selectors';
8+
9+
import AutocompleteSuggestionItem from './user/components/AutocompleteSuggestionList';
10+
import MessageInput from './user/components/MessageInput';
11+
12+
const MENTION_TRIGGER = '@';
13+
14+
test.describe('autocomplete a mention', () => {
15+
test('should fill in textarea with username', async ({ controller, page, user }) => {
16+
await controller.openStory('hello--basic-setup', selectors.messageInput);
17+
18+
await user.typesTo(MessageInput).text(MENTION_TRIGGER);
19+
20+
const autocompleteSuggestionItem = await user.clicks(AutocompleteSuggestionItem).nth(1);
21+
const textContent = await autocompleteSuggestionItem.textContent();
22+
23+
await expect(getMessageInput(page)).toContainText(`${MENTION_TRIGGER}${textContent}`);
24+
});
25+
});

e2e/edit-message.test.ts

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/* eslint-disable jest/expect-expect */
2+
/* eslint-disable jest/no-done-callback */
3+
/* eslint-disable jest/require-top-level-describe */
4+
import selectors from './user/selectors';
5+
import { test } from './user/test';
6+
7+
import Attachment from './user/components/Attachment/Attachment';
8+
import EditMessageForm from './user/components/EditMessageForm/EditMessageForm';
9+
import MessageInput from './user/components/MessageInput';
10+
import MessageActionsBox from './user/components/MessageActions/MessageActionsBox';
11+
12+
test.describe('edit text message', () => {
13+
test.beforeEach(async ({ controller, page }) => {
14+
await controller.openStory('edit-message--user1', selectors.buttonAddMessage);
15+
await controller.clearChannel();
16+
17+
await Promise.all([page.waitForSelector(selectors.attachmentCard), controller.sendMessage()]);
18+
});
19+
20+
test('message has 3 attachments (2 cards and 1 gallery)', ({ user }) => {
21+
user.sees(Attachment.Card).count(2);
22+
user.sees(Attachment.Gallery).count(1);
23+
});
24+
25+
test('message has 2 attachments (1 card and 1 gallery) after updating text', async ({
26+
page,
27+
user,
28+
}) => {
29+
await user.clicks(MessageActionsBox).editMessage('', 0);
30+
31+
await user.typesTo(MessageInput).text('jest: https://jestjs.io/docs/cli');
32+
33+
await Promise.all([
34+
page.waitForResponse((r) => r.url().includes('/message') && r.ok()),
35+
page.waitForSelector(`${selectors.attachmentCard} >> text=jestjs.io`),
36+
user.clicks(EditMessageForm).send(),
37+
]);
38+
39+
user.sees(Attachment.Card).count(1);
40+
user.sees(Attachment.Gallery).count(1);
41+
});
42+
43+
test('gallery attachment changes to image attachment after removing one image attachment', async ({
44+
page,
45+
user,
46+
}) => {
47+
await user.clicks(MessageActionsBox).editMessage('', 0);
48+
49+
await user.clicks(EditMessageForm).removeAttachment(0);
50+
51+
await Promise.all([
52+
page.waitForResponse((r) => r.url().includes('/message') && r.ok()),
53+
page.waitForSelector(selectors.attachmentImage),
54+
user.clicks(EditMessageForm).send(),
55+
]);
56+
57+
user.sees(Attachment.Card).count(2);
58+
user.sees(Attachment.Gallery).count(0);
59+
user.sees(Attachment.Image).count(3);
60+
});
61+
62+
test('message has only 1 attachment after removing all of the links from the message', async ({
63+
page,
64+
user,
65+
}) => {
66+
await user.clicks(MessageActionsBox).editMessage('', 0);
67+
68+
await user.typesTo(MessageInput).text('no links');
69+
70+
await Promise.all([
71+
page.waitForResponse((r) => r.url().includes('/message') && r.ok()),
72+
user.clicks(EditMessageForm).send(),
73+
]);
74+
75+
user.sees(Attachment.Card).count(0);
76+
user.sees(Attachment.Gallery).count(1);
77+
});
78+
79+
test('edit button does nothing if there are no attachments and text input is empty', async ({
80+
page,
81+
user,
82+
}) => {
83+
await user.clicks(MessageActionsBox).editMessage('', 0);
84+
85+
await user.typesTo(MessageInput).text('');
86+
87+
// remove all attachments
88+
const locator = page.locator(selectors.buttonCancelUpload);
89+
const count = await locator.count();
90+
for (let i = 0; i < count; ++i) {
91+
await user.clicks(EditMessageForm).removeAttachment(0);
92+
}
93+
94+
await Promise.all([
95+
page.waitForSelector(selectors.modalOpen),
96+
user.clicks(EditMessageForm).send(),
97+
]);
98+
99+
user.sees(Attachment.Card).count(2);
100+
user.sees(Attachment.Gallery).count(1);
101+
});
102+
});

e2e/jump-to-message.test.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* eslint-disable jest/expect-expect */
2+
/* eslint-disable jest/no-done-callback */
3+
/* eslint-disable jest/require-top-level-describe */
4+
import { expect } from '@playwright/test';
5+
import { test } from './user/test';
6+
7+
import Message from './user/components/Message/MessageSimple';
8+
import QuotedMessage from './user/components/Message/QuotedMessage';
9+
10+
const suiteArray = [
11+
['virtualized', 'jump-to-message--jump-in-virtualized-message-list'],
12+
['regular', 'jump-to-message--jump-in-regular-message-list'],
13+
];
14+
15+
const controlsButtonSelector = 'data-testid=jump-to-message';
16+
const onPageLoadWaitForMessage149 = 'data-testid=message-text-inner-wrapper >> text=Message 149';
17+
18+
suiteArray.forEach(([mode, story]) => {
19+
test.describe(`jump to message - ${mode}`, () => {
20+
test.beforeEach(async ({ controller }) => {
21+
await controller.openStory(story, onPageLoadWaitForMessage149);
22+
});
23+
24+
test(`${mode} jumps to message 29 and then back to bottom`, async ({ page, user }) => {
25+
const message29 = await user.sees(Message).not.displayed('Message 29');
26+
await page.click(controlsButtonSelector);
27+
await expect(message29).toBeVisible();
28+
});
29+
30+
test(`${mode} jumps to quoted message`, async ({ user }) => {
31+
const text = 'Message 20';
32+
await user.clicks(QuotedMessage).nth(text);
33+
await user.sees(Message).displayed(text);
34+
});
35+
});
36+
});

e2e/mark-read.test.ts

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* eslint-disable jest/expect-expect */
2+
/* eslint-disable jest/no-done-callback */
3+
/* eslint-disable jest/require-top-level-describe */
4+
import { test } from './user/test';
5+
import selectors from './user/selectors';
6+
7+
import ChannelPreview from './user/components/ChannelPreview';
8+
9+
const onPageLoadWaitForSelector = selectors.channelPreviewButton;
10+
11+
test.describe('mark read', () => {
12+
test.beforeEach(async ({ controller, page, user: user1 }) => {
13+
await controller.openStory('mark-read--user1', onPageLoadWaitForSelector);
14+
15+
const channelListItems = page.locator(`${selectors.channelList} > *`);
16+
const listCount = await channelListItems.count();
17+
18+
for (let i = 1; i <= listCount; ++i) {
19+
await Promise.all([
20+
page.waitForSelector(`${selectors.channelHeader} >> text=mr-channel-${i}`),
21+
user1.clicks(ChannelPreview).text(`mr-channel-${i}`),
22+
]);
23+
await controller.clearChannel();
24+
await controller.sendMessage();
25+
}
26+
27+
await controller.openStory('mark-read--user2', onPageLoadWaitForSelector);
28+
});
29+
30+
test('unread count in "mr-channel-1" channel is 1', async ({ user: user2 }) => {
31+
await user2.sees(ChannelPreview)('mr-channel-1').not.read();
32+
});
33+
34+
test('unread count changes to 0 after setting "mr-channel-1" channel as active', async ({
35+
user: user2,
36+
}) => {
37+
await user2.clicks(ChannelPreview).text(`mr-channel-1`);
38+
await user2.sees(ChannelPreview)('mr-channel-1').read();
39+
});
40+
41+
test('unread count stays 0 after switching channels', async ({ user: user2 }) => {
42+
await user2.clicks(ChannelPreview).text(`mr-channel-1`);
43+
await user2.clicks(ChannelPreview).text(`mr-channel-2`);
44+
45+
await user2.sees(ChannelPreview)('mr-channel-1').read();
46+
await user2.sees(ChannelPreview)('mr-channel-2').read();
47+
});
48+
49+
test('unread count stays 0 after switching channels and reloading page', async ({
50+
controller,
51+
page,
52+
user: user2,
53+
}) => {
54+
await Promise.all([
55+
page.waitForSelector('.str-chat__main-panel >> text=mr-channel-1'),
56+
user2.clicks(ChannelPreview).text(`mr-channel-1`),
57+
]);
58+
59+
await Promise.all([
60+
page.waitForResponse((r) => r.url().includes('/mr-channel-2/read') && r.ok()),
61+
user2.clicks(ChannelPreview).text(`mr-channel-2`),
62+
]);
63+
64+
await controller.reloadPage(onPageLoadWaitForSelector);
65+
await user2.sees(ChannelPreview)('mr-channel-2').read();
66+
});
67+
});

0 commit comments

Comments
 (0)