2021-02-20 05:52:06 +01:00
|
|
|
import {strict as assert} from "assert";
|
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
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
import common from "../puppeteer_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> {
|
2020-07-30 13:08:45 +02:00
|
|
|
return await page.evaluate(() => $("#zhome .fa-star:not(.empty-star)").length);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function toggle_test_star_message(page: Page): Promise<void> {
|
|
|
|
await page.evaluate((message: string) => {
|
2021-02-03 23:23:32 +01:00
|
|
|
const msg = $(`.message_content:contains("${CSS.escape(message)}"):visible`).last();
|
2020-07-30 13:08:45 +02:00
|
|
|
if (msg.length !== 1) {
|
2020-09-24 07:50:36 +02:00
|
|
|
throw new Error("cannot find test star message");
|
2020-07-30 13:08:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const star_icon = msg.closest(".messagebox").find(".star");
|
|
|
|
if (star_icon.length !== 1) {
|
2020-09-24 07:50:36 +02:00
|
|
|
throw new Error("cannot find star icon");
|
2020-07-30 13:08:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
star_icon.trigger("click");
|
|
|
|
}, message);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_narrow_to_starred_messages(page: Page): Promise<void> {
|
2020-07-30 13:08:45 +02:00
|
|
|
await page.click('a[href^="#narrow/is/starred"]');
|
2020-08-30 15:43:14 +02:00
|
|
|
await common.check_messages_sent(page, "zfilt", [["Verona > stars", [message]]]);
|
2020-07-30 13:08:45 +02:00
|
|
|
|
|
|
|
// Go back to all messages narrow.
|
|
|
|
await page.keyboard.press("Escape");
|
|
|
|
await page.waitForSelector("#zhome .message_row", {visible: true});
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
await common.send_message(page, "stream", {
|
|
|
|
stream: "Verona",
|
|
|
|
topic: "stars",
|
|
|
|
content: message,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(await stars_count(page), 0, "Unexpected already starred message(s).");
|
|
|
|
|
|
|
|
await toggle_test_star_message(page);
|
|
|
|
await page.waitForSelector("#zhome .fa-star", {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);
|