2024-10-09 00:25:41 +02:00
|
|
|
import assert from "node:assert/strict";
|
2020-07-30 13:08:45 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
import type {Page} from "puppeteer";
|
2020-07-30 13:08:45 +02:00
|
|
|
|
2023-02-22 23:04:11 +01:00
|
|
|
import * as common from "./lib/common";
|
2020-07-30 13:08:45 +02:00
|
|
|
|
|
|
|
const message = "test star";
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function stars_count(page: Page): Promise<number> {
|
2024-01-17 07:53:40 +01:00
|
|
|
return (await page.$$(".message-list .zulip-icon-star-filled:not(.empty-star)")).length;
|
2020-07-30 13:08:45 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function toggle_test_star_message(page: Page): Promise<void> {
|
2021-03-27 04:40:48 +01:00
|
|
|
const messagebox = await page.waitForSelector(
|
2024-01-17 07:53:40 +01:00
|
|
|
`xpath/(//*[${common.has_class_x("message-list")}]//*[${common.has_class_x(
|
2021-03-27 04:40:48 +01:00
|
|
|
"message_content",
|
|
|
|
)} and normalize-space()="${message}"])[last()]/ancestor::*[${common.has_class_x(
|
|
|
|
"messagebox",
|
|
|
|
)}]`,
|
|
|
|
{visible: true},
|
|
|
|
);
|
|
|
|
assert.ok(messagebox !== null);
|
|
|
|
await messagebox.hover();
|
|
|
|
|
|
|
|
const star_icon = await messagebox.waitForSelector(".star", {visible: true});
|
|
|
|
assert.ok(star_icon !== null);
|
|
|
|
await star_icon.click();
|
2020-07-30 13:08:45 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_narrow_to_starred_messages(page: Page): Promise<void> {
|
2023-10-10 21:00:28 +02:00
|
|
|
await page.click('#left-sidebar-navigation-list a[href^="#narrow/is/starred"]');
|
2024-01-17 07:53:40 +01:00
|
|
|
const message_list_id = await common.get_current_msg_list_id(page, true);
|
|
|
|
await common.check_messages_sent(page, message_list_id, [["Verona > stars", [message]]]);
|
2020-07-30 13:08:45 +02:00
|
|
|
|
2024-04-02 13:10:48 +02:00
|
|
|
// Go back to the combined feed view.
|
2023-10-11 19:08:42 +02:00
|
|
|
await page.click("#left-sidebar-navigation-list .top_left_all_messages");
|
2024-05-10 19:30:33 +02:00
|
|
|
const combined_feed_id = await common.get_current_msg_list_id(page, true);
|
|
|
|
await page.waitForSelector(
|
|
|
|
`.message-list[data-message-list-id='${combined_feed_id}'] .message_row`,
|
|
|
|
{visible: true},
|
|
|
|
);
|
2020-07-30 13:08:45 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function stars_test(page: Page): Promise<void> {
|
2020-07-30 13:08:45 +02:00
|
|
|
await common.log_in(page);
|
2023-10-11 19:08:42 +02:00
|
|
|
await page.click("#left-sidebar-navigation-list .top_left_all_messages");
|
2024-03-06 13:12:08 +01:00
|
|
|
let message_list_id = await common.get_current_msg_list_id(page, true);
|
2024-01-17 07:53:40 +01:00
|
|
|
await page.waitForSelector(
|
|
|
|
`.message-list[data-message-list-id='${message_list_id}'] .message_row`,
|
|
|
|
{visible: true},
|
|
|
|
);
|
|
|
|
// Assert that there is only one message list.
|
|
|
|
assert.equal((await page.$$(".message-list")).length, 1);
|
2020-07-30 13:08:45 +02:00
|
|
|
await common.send_message(page, "stream", {
|
2023-08-04 06:46:35 +02:00
|
|
|
stream_name: "Verona",
|
2020-07-30 13:08:45 +02:00
|
|
|
topic: "stars",
|
|
|
|
content: message,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(await stars_count(page), 0, "Unexpected already starred message(s).");
|
|
|
|
|
|
|
|
await toggle_test_star_message(page);
|
2024-03-06 13:12:08 +01:00
|
|
|
await page.click("#left-sidebar-navigation-list .top_left_all_messages");
|
2024-10-07 10:09:46 +02:00
|
|
|
message_list_id = await common.get_current_msg_list_id(page, false);
|
2024-01-17 07:53:40 +01:00
|
|
|
await page.waitForSelector(
|
|
|
|
`.message-list[data-message-list-id='${message_list_id}'] .zulip-icon-star-filled`,
|
|
|
|
{visible: true},
|
|
|
|
);
|
2020-08-05 00:51:39 +02:00
|
|
|
assert.strictEqual(
|
|
|
|
await stars_count(page),
|
|
|
|
1,
|
|
|
|
"Failed to ensure 1 starred message after change.",
|
|
|
|
);
|
2020-07-30 13:08:45 +02:00
|
|
|
|
|
|
|
await test_narrow_to_starred_messages(page);
|
2020-08-05 00:51:39 +02:00
|
|
|
assert.strictEqual(
|
|
|
|
await stars_count(page),
|
|
|
|
1,
|
|
|
|
"Message star disappeared after switching views.",
|
|
|
|
);
|
2020-07-30 13:08:45 +02:00
|
|
|
|
|
|
|
await toggle_test_star_message(page);
|
|
|
|
assert.strictEqual(await stars_count(page), 0, "Message was not unstarred correctly.");
|
|
|
|
}
|
|
|
|
|
|
|
|
common.run_test(stars_test);
|