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