2020-07-15 01:29:15 +02:00
|
|
|
var common = require("../casper_lib/common.js");
|
2017-02-22 02:34:05 +01:00
|
|
|
|
|
|
|
function waitWhileDraftsVisible(then) {
|
|
|
|
casper.waitFor(function () {
|
|
|
|
return casper.evaluate(function () {
|
2020-07-15 00:34:28 +02:00
|
|
|
return $("#draft_overlay").length === 0 || $("#draft_overlay").css("opacity") === "0";
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
|
|
|
}, then);
|
|
|
|
}
|
|
|
|
|
|
|
|
function waitUntilDraftsVisible(then) {
|
|
|
|
casper.waitFor(function () {
|
|
|
|
return casper.evaluate(function () {
|
2020-07-15 00:34:28 +02:00
|
|
|
return $("#draft_overlay").length === 1 && $("#draft_overlay").css("opacity") === "1";
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
|
|
|
}, then);
|
|
|
|
}
|
|
|
|
|
|
|
|
common.start_and_log_in();
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Drafts page");
|
2017-02-22 02:34:05 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitUntilVisible(".drafts-link", function () {
|
|
|
|
casper.click(".drafts-link");
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertUrlMatch(/^http:\/\/[^/]+\/#drafts/, "URL suggests we are on drafts page");
|
2017-02-22 02:34:05 +01:00
|
|
|
waitUntilDraftsVisible(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.assertExists("#draft_overlay", "Drafts page is active");
|
|
|
|
casper.test.assertSelectorHasText(".no-drafts", "No drafts.");
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.click("#draft_overlay .exit");
|
2017-02-22 02:34:05 +01:00
|
|
|
waitWhileDraftsVisible();
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Creating Stream Message Draft");
|
|
|
|
casper.click("body");
|
|
|
|
casper.page.sendEvent("keypress", "c");
|
|
|
|
casper.waitUntilVisible("#stream-message", function () {
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.fill(
|
|
|
|
"form#send_message_form",
|
|
|
|
{
|
|
|
|
stream_message_recipient_stream: "all",
|
|
|
|
stream_message_recipient_topic: "tests",
|
|
|
|
content: "Test Stream Message",
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
2017-02-22 02:34:05 +01:00
|
|
|
casper.click("#compose_close");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Creating Private Message Draft");
|
|
|
|
casper.click("body");
|
|
|
|
casper.page.sendEvent("keypress", "x");
|
|
|
|
casper.waitUntilVisible("#private-message", function () {
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.fill(
|
|
|
|
"form#send_message_form",
|
|
|
|
{
|
|
|
|
content: "Test Private Message",
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
common.pm_recipient.set("cordelia@zulip.com, hamlet@zulip.com");
|
2017-02-22 02:34:05 +01:00
|
|
|
casper.click("#compose_close");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 03:34:55 +01:00
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Opening Markdown Preview");
|
|
|
|
casper.waitUntilVisible("#left_bar_compose_stream_button_big", function () {
|
|
|
|
casper.click("#left_bar_compose_stream_button_big");
|
2017-12-19 03:34:55 +01:00
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitUntilVisible("#markdown_preview", function () {
|
|
|
|
casper.click("#markdown_preview");
|
2017-12-19 03:34:55 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-22 02:34:05 +01:00
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitUntilVisible(".drafts-link", function () {
|
|
|
|
casper.click(".drafts-link");
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
|
|
|
waitUntilDraftsVisible(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.assertElementCount(".draft-row", 2, "Drafts loaded");
|
2017-02-22 02:34:05 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.assertSelectorHasText(".draft-row .message_header_stream .stream_label", "all");
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertSelectorHasText(
|
|
|
|
".draft-row .message_header_stream .stream_topic",
|
|
|
|
"tests"
|
|
|
|
);
|
|
|
|
casper.test.assertTextExists(
|
|
|
|
"Test Stream Message",
|
|
|
|
"Stream draft contains message content"
|
|
|
|
);
|
2017-02-22 02:34:05 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertSelectorHasText(
|
|
|
|
".draft-row .message_header_private_message .stream_label",
|
|
|
|
"You and Cordelia Lear, King Hamlet"
|
|
|
|
);
|
|
|
|
casper.test.assertTextExists(
|
|
|
|
"Test Private Message",
|
|
|
|
"Private draft contains message content"
|
|
|
|
);
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Restoring Stream Message Draft");
|
2017-02-22 02:34:05 +01:00
|
|
|
casper.click("#drafts_table .message_row:not(.private-message) .restore-draft");
|
|
|
|
waitWhileDraftsVisible(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.assertVisible("#stream-message", "Stream Message Box Restored");
|
|
|
|
casper.test.assertNotVisible("#preview_message_area", "Preview Was Hidden");
|
2020-07-15 00:34:28 +02:00
|
|
|
common.check_form(
|
|
|
|
"form#send_message_form",
|
|
|
|
{
|
|
|
|
stream_message_recipient_stream: "all",
|
|
|
|
stream_message_recipient_topic: "tests",
|
|
|
|
content: "Test Stream Message",
|
|
|
|
},
|
|
|
|
"Stream message box filled with draft content"
|
|
|
|
);
|
|
|
|
casper.test.assertSelectorHasText(
|
|
|
|
"title",
|
|
|
|
"tests - Zulip Dev - Zulip",
|
|
|
|
"Narrowed to topic"
|
|
|
|
);
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Editing Stream Message Draft");
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.fill(
|
|
|
|
"form#send_message_form",
|
|
|
|
{
|
|
|
|
stream_message_recipient_stream: "all",
|
|
|
|
stream_message_recipient_topic: "tests",
|
|
|
|
content: "Updated Stream Message",
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
2017-02-22 02:34:05 +01:00
|
|
|
casper.click("#compose_close");
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitUntilVisible(".drafts-link", function () {
|
|
|
|
casper.click(".drafts-link");
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
|
|
|
waitUntilDraftsVisible(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.assertSelectorHasText(".draft-row .message_header_stream .stream_label", "all");
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertSelectorHasText(
|
|
|
|
".draft-row .message_header_stream .stream_topic",
|
|
|
|
"tests"
|
|
|
|
);
|
|
|
|
casper.test.assertTextExists(
|
|
|
|
"Updated Stream Message",
|
|
|
|
"Stream draft contains message content"
|
|
|
|
);
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Restoring Private Message Draft");
|
2017-02-22 02:34:05 +01:00
|
|
|
casper.click("#drafts_table .message_row.private-message .restore-draft");
|
|
|
|
waitWhileDraftsVisible(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.assertVisible("#private-message", "Private Message Box Restored");
|
2020-07-15 00:34:28 +02:00
|
|
|
common.check_form(
|
|
|
|
"form#send_message_form",
|
|
|
|
{
|
|
|
|
content: "Test Private Message",
|
|
|
|
},
|
|
|
|
"Private message box filled with draft content"
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
common.pm_recipient.expect("cordelia@zulip.com,hamlet@zulip.com");
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertSelectorHasText(
|
|
|
|
"title",
|
|
|
|
"Cordelia Lear, King Hamlet - Zulip Dev - Zulip",
|
|
|
|
"Narrowed to huddle"
|
|
|
|
);
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
|
|
|
casper.click("#compose_close");
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitUntilVisible(".drafts-link", function () {
|
|
|
|
casper.click(".drafts-link");
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Deleting Draft");
|
2017-02-22 02:34:05 +01:00
|
|
|
casper.click("#drafts_table .message_row.private-message .delete-draft");
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.assertElementCount(".draft-row", 1, "Draft deleted");
|
2017-02-22 02:34:05 +01:00
|
|
|
casper.test.assertDoesntExist("#drafts_table .message_row.private-message");
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Saving Draft by Reloading");
|
|
|
|
casper.click("#draft_overlay .exit");
|
2017-02-22 02:34:05 +01:00
|
|
|
waitWhileDraftsVisible(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.click("body");
|
|
|
|
casper.page.sendEvent("keypress", "x");
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitUntilVisible("#private-message", function () {
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.fill(
|
|
|
|
"form#send_message_form",
|
|
|
|
{
|
|
|
|
content: "Test Private Message",
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
common.pm_recipient.set("cordelia@zulip.com");
|
2017-03-18 01:37:20 +01:00
|
|
|
});
|
|
|
|
casper.reload();
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Finished reloading; now opening drafts again");
|
2017-06-24 23:36:27 +02:00
|
|
|
// Reloading into a narrow opens compose box automatically
|
2017-07-04 23:37:02 +02:00
|
|
|
|
|
|
|
casper.waitUntilVisible("#compose_close", function () {
|
|
|
|
casper.click("#compose_close");
|
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitUntilVisible(".drafts-link", function () {
|
|
|
|
casper.click(".drafts-link");
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
2017-03-18 01:37:20 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Checking drafts survived the reload");
|
2017-02-22 02:34:05 +01:00
|
|
|
waitUntilDraftsVisible(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.assertElementCount(".draft-row", 2, "Drafts loaded");
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertSelectorHasText(
|
|
|
|
".draft-row .message_header_private_message .stream_label",
|
|
|
|
"You and Cordelia Lear"
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.assertTextExists("Test Private Message");
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Deleting Draft after Sending Message");
|
2017-02-22 02:34:05 +01:00
|
|
|
casper.click("#drafts_table .message_row.private-message .restore-draft");
|
|
|
|
waitWhileDraftsVisible(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.assertVisible("#private-message");
|
2017-06-24 21:31:43 +02:00
|
|
|
casper.click("#enter_sends");
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitUntilVisible("#compose-send-button", function () {
|
|
|
|
casper.click("#compose-send-button");
|
2017-06-24 21:31:43 +02:00
|
|
|
});
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
|
|
|
// This tests the second drafts link in the compose area
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitUntilVisible(".compose_table .drafts-link", function () {
|
|
|
|
casper.click(".compose_table .drafts-link");
|
2017-02-22 02:34:05 +01:00
|
|
|
});
|
|
|
|
waitUntilDraftsVisible(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.assertElementCount(".draft-row", 1, "Drafts loaded");
|
2017-02-22 02:34:05 +01:00
|
|
|
casper.test.assertDoesntExist("#drafts_table .message_row.private-message");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
common.then_log_out();
|
|
|
|
|
|
|
|
casper.run(function () {
|
|
|
|
casper.test.done();
|
|
|
|
});
|