Skip to content

Commit fc81cbb

Browse files
committed
fix promise not fullfiled by conditional state in e2e test
1 parent 44b69f3 commit fc81cbb

File tree

2 files changed

+55
-51
lines changed

2 files changed

+55
-51
lines changed

apps/meteor/tests/e2e/messaging.spec.ts

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -94,51 +94,6 @@ test.describe('Messaging', () => {
9494
});
9595
});
9696

97-
test('should edit messages', async ({ page }) => {
98-
await poHomeChannel.sidenav.openChat(targetChannel);
99-
100-
await test.step('focus on the second message', async () => {
101-
await page.keyboard.press('ArrowUp');
102-
103-
expect(await poHomeChannel.composer.inputValue()).toBe('msg2');
104-
});
105-
106-
await test.step('send edited message', async () => {
107-
const editPromise = page.waitForResponse(
108-
(response) =>
109-
/api\/v1\/method.call\/updateMessage/.test(response.url()) &&
110-
response.status() === 200 &&
111-
response.request().method() === 'POST',
112-
);
113-
114-
await poHomeChannel.content.sendMessage('edited msg2', false);
115-
await editPromise;
116-
117-
await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('edited msg2');
118-
});
119-
120-
await test.step('stress test on message editions', async () => {
121-
const editPromise = page.waitForResponse(
122-
(response) =>
123-
/api\/v1\/method.call\/updateMessage/.test(response.url()) &&
124-
response.status() === 200 &&
125-
response.request().method() === 'POST',
126-
);
127-
128-
for (const element of ['edited msg2 a', 'edited msg2 b', 'edited msg2 c', 'edited msg2 d', 'edited msg2 e']) {
129-
// eslint-disable-next-line no-await-in-loop
130-
await page.keyboard.press('ArrowUp');
131-
// eslint-disable-next-line no-await-in-loop
132-
await poHomeChannel.content.sendMessage(element, false);
133-
}
134-
135-
await editPromise;
136-
const toastError = await poToastBar.waitForError();
137-
138-
expect(toastError).toBe(true);
139-
});
140-
});
141-
14297
test('should navigate properly on the user card', async ({ page }) => {
14398
await poHomeChannel.sidenav.openChat(targetChannel);
14499

@@ -206,6 +161,53 @@ test.describe('Messaging', () => {
206161
});
207162
});
208163

164+
test.describe.serial('Message edition', () => {
165+
test('should edit messages', async ({ page }) => {
166+
await poHomeChannel.sidenav.openChat(targetChannel);
167+
168+
await test.step('focus on the second message', async () => {
169+
await page.keyboard.press('ArrowUp');
170+
171+
expect(await poHomeChannel.composer.inputValue()).toBe('msg2');
172+
});
173+
174+
await test.step('send edited message', async () => {
175+
const editPromise = page.waitForResponse(
176+
(response) =>
177+
/api\/v1\/method.call\/updateMessage/.test(response.url()) &&
178+
response.status() === 200 &&
179+
response.request().method() === 'POST',
180+
);
181+
182+
await poHomeChannel.content.sendMessage('edited msg2', false);
183+
await editPromise;
184+
185+
await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('edited msg2');
186+
});
187+
188+
await test.step('stress test on message editions', async () => {
189+
const editPromise = page.waitForResponse(
190+
(response) =>
191+
/api\/v1\/method.call\/updateMessage/.test(response.url()) &&
192+
response.status() === 200 &&
193+
response.request().method() === 'POST',
194+
);
195+
196+
for (const element of ['edited msg2 a', 'edited msg2 b', 'edited msg2 c', 'edited msg2 d', 'edited msg2 e']) {
197+
// eslint-disable-next-line no-await-in-loop
198+
await page.keyboard.press('ArrowUp');
199+
// eslint-disable-next-line no-await-in-loop
200+
await poHomeChannel.content.sendMessage(element, false);
201+
}
202+
203+
await editPromise;
204+
const toastError = await poToastBar.waitForError();
205+
206+
expect(toastError).toBe(true);
207+
});
208+
});
209+
});
210+
209211
test.describe('Message by "chat.postMessage" API method', () => {
210212
test('expect show a message', async ({ api }) => {
211213
const messageText = faker.lorem.sentence();

apps/meteor/tests/e2e/page-objects/fragments/home-content.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,23 @@ export class HomeContent {
9090
await this.page.waitForSelector('[name="msg"]:not([disabled])');
9191
await this.page.locator('[name="msg"]').fill(text);
9292

93-
const responsePromise = this.page.waitForResponse(
94-
(response) =>
95-
/api\/v1\/method.call\/sendMessage/.test(response.url()) && response.status() === 200 && response.request().method() === 'POST',
96-
);
93+
if (enforce) {
94+
const responsePromise = this.page.waitForResponse(
95+
(response) =>
96+
/api\/v1\/method.call\/sendMessage/.test(response.url()) && response.status() === 200 && response.request().method() === 'POST',
97+
);
9798

98-
await this.page.getByRole('button', { name: 'Send', exact: true }).click();
99+
await this.page.getByRole('button', { name: 'Send', exact: true }).click();
99100

100-
if (enforce) {
101101
const response = await (await responsePromise).json();
102102

103103
const mid = JSON.parse(response.message).result._id;
104104
const messageLocator = this.getMessageById(mid);
105105

106106
await expect(messageLocator).toBeVisible();
107107
await expect(messageLocator).not.toHaveClass('rcx-message--pending');
108+
} else {
109+
await this.page.getByRole('button', { name: 'Send', exact: true }).click();
108110
}
109111
}
110112

0 commit comments

Comments
 (0)