2017-02-09 09:42:27 +01:00
|
|
|
var common = require('../casper_lib/common.js').common;
|
|
|
|
|
2018-01-11 13:32:25 +01:00
|
|
|
function heading(heading_str) {
|
|
|
|
casper.then(function () {
|
|
|
|
casper.test.info(heading_str);
|
|
|
|
});
|
|
|
|
}
|
2017-12-27 23:12:52 +01:00
|
|
|
|
2017-02-09 09:42:27 +01:00
|
|
|
common.start_and_log_in();
|
|
|
|
|
|
|
|
// For clarity these should be different than what 08-edit uses, until
|
|
|
|
// we find a more robust way to manage DB state between tests.
|
|
|
|
var content1 = 'admin: edit test message 1';
|
|
|
|
var content2 = 'admin: edit test message 2';
|
|
|
|
|
|
|
|
// send two messages
|
|
|
|
common.then_send_message('stream', {
|
|
|
|
stream: 'Verona',
|
|
|
|
subject: 'edits',
|
|
|
|
content: content1,
|
|
|
|
});
|
|
|
|
common.then_send_message('stream', {
|
|
|
|
stream: 'Verona',
|
|
|
|
subject: 'edits',
|
|
|
|
content: content2,
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2017-06-07 10:25:06 +02:00
|
|
|
casper.waitForSelectorText('#zhome .message_row', content1);
|
|
|
|
casper.waitForSelectorText('#zhome .message_row', content2);
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// wait for message to be sent
|
2017-11-21 00:54:47 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitFor(function () {
|
|
|
|
return casper.evaluate(function () {
|
|
|
|
return !current_msg_list.last().locally_echoed;
|
|
|
|
});
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// edit the last message just sent
|
|
|
|
casper.then(function () {
|
|
|
|
casper.evaluate(function () {
|
|
|
|
var msg = $('#zhome .message_row:last');
|
|
|
|
msg.find('.info').click();
|
|
|
|
$('.popover_edit_message').click();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var edited_value = 'admin tests: test edit';
|
|
|
|
|
2017-11-21 00:54:47 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible(".message_edit_content", function () {
|
|
|
|
casper.evaluate(function (edited_value) {
|
|
|
|
var msg = $('#zhome .message_row:last');
|
|
|
|
msg.find('.message_edit_content').val(edited_value);
|
|
|
|
msg.find('.message_edit_save').click();
|
|
|
|
}, edited_value);
|
|
|
|
});
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
|
|
|
// check that the message was indeed edited
|
|
|
|
casper.waitWhileVisible("textarea.message_edit_content", function () {
|
|
|
|
casper.test.assertSelectorHasText(".last_message .message_content", edited_value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// go to admin page
|
2017-12-28 00:08:58 +01:00
|
|
|
common.then_click('#settings-dropdown');
|
|
|
|
common.then_click('a[href^="#organization"]');
|
2017-02-09 09:42:27 +01:00
|
|
|
|
2017-11-21 00:54:47 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitForSelector('#settings_overlay_container.show', function () {
|
|
|
|
casper.test.info('Organization page is active');
|
|
|
|
casper.test.assertUrlMatch(/^http:\/\/[^/]+\/#organization/, 'URL suggests we are on organization page');
|
|
|
|
});
|
2017-05-18 14:06:57 +02:00
|
|
|
});
|
|
|
|
|
2018-04-02 11:18:40 +02:00
|
|
|
function submit_edit_limit_changed() {
|
|
|
|
casper.test.assertSelectorHasText('#org-submit-msg-editing', "Save");
|
|
|
|
casper.click('#org-submit-msg-editing');
|
|
|
|
}
|
|
|
|
|
2018-01-11 13:32:25 +01:00
|
|
|
// DEACTIVATE
|
|
|
|
|
|
|
|
heading("DEACTIVATE");
|
2017-12-28 00:08:58 +01:00
|
|
|
common.then_click("li[data-section='organization-settings']");
|
|
|
|
|
|
|
|
// deactivate "allow message editing"
|
2018-04-02 11:18:40 +02:00
|
|
|
casper.then(function () {
|
|
|
|
casper.test.info("Changing message edit limit setting");
|
|
|
|
casper.waitUntilVisible("#id_realm_msg_edit_limit_setting", function () {
|
|
|
|
casper.evaluate(function () {
|
|
|
|
$("#id_realm_msg_edit_limit_setting").val("never").change();
|
|
|
|
});
|
|
|
|
submit_edit_limit_changed();
|
|
|
|
});
|
|
|
|
});
|
2017-12-27 23:12:52 +01:00
|
|
|
|
2017-02-09 09:42:27 +01:00
|
|
|
casper.then(function () {
|
2018-03-14 23:45:42 +01:00
|
|
|
casper.waitUntilVisible('#org-submit-msg-editing[data-status="saved"]', function () {
|
|
|
|
casper.test.assertSelectorHasText('#org-submit-msg-editing',
|
|
|
|
'Saved');
|
2017-02-09 09:42:27 +01:00
|
|
|
casper.test.assertEval(function () {
|
2018-04-02 11:18:40 +02:00
|
|
|
return (document.querySelector('#id_realm_msg_edit_limit_setting').value === "never");
|
|
|
|
}, 'Message editing Setting disabled');
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// go back to home page
|
|
|
|
casper.then(function () {
|
2016-12-03 01:12:52 +01:00
|
|
|
casper.click('.settings-header .exit');
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
|
|
|
|
2018-01-11 13:32:25 +01:00
|
|
|
// VIEW SOURCE
|
|
|
|
|
|
|
|
heading("VIEW SOURCE");
|
2017-03-08 13:57:42 +01:00
|
|
|
// Check that edit link has changed to "View source" in the popover menu
|
2017-02-09 09:42:27 +01:00
|
|
|
// TODO: also check that the edit icon no longer appears next to the message
|
2017-11-23 07:06:19 +01:00
|
|
|
casper.then(function () {
|
|
|
|
// This somehow makes the "View source" test deterministic. It seems that
|
|
|
|
// we are waiting on a wrong condition somewhere.
|
|
|
|
casper.wait(1000);
|
|
|
|
});
|
|
|
|
|
2017-02-09 09:42:27 +01:00
|
|
|
casper.then(function () {
|
2017-02-10 08:04:01 +01:00
|
|
|
casper.waitUntilVisible('.message_row');
|
2017-02-09 09:42:27 +01:00
|
|
|
// Note that this could have a false positive, e.g. if all the messages aren't
|
|
|
|
// loaded yet. See Issue #1243
|
|
|
|
casper.evaluate(function () {
|
|
|
|
var msg = $('#zhome .message_row:last');
|
|
|
|
msg.find('.info').click();
|
|
|
|
});
|
|
|
|
casper.waitUntilVisible('.popover_edit_message', function () {
|
2017-03-08 13:57:42 +01:00
|
|
|
casper.test.assertSelectorHasText('.popover_edit_message', 'View source');
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
|
|
|
casper.evaluate(function () {
|
|
|
|
var msg = $('#zhome .message_row:last');
|
|
|
|
msg.find('.info').click();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-01-11 13:32:25 +01:00
|
|
|
// REACTIVATE
|
|
|
|
|
|
|
|
heading("REACTIVATE");
|
|
|
|
|
2017-02-09 09:42:27 +01:00
|
|
|
// go back to admin page, and reactivate "allow message editing"
|
2017-12-28 00:08:58 +01:00
|
|
|
common.then_click('#settings-dropdown');
|
|
|
|
common.then_click('a[href^="#organization"]');
|
|
|
|
common.then_click("li[data-section='organization-settings']");
|
2018-04-02 11:18:40 +02:00
|
|
|
|
|
|
|
casper.then(function () {
|
|
|
|
casper.test.info("Changing message edit limit setting");
|
|
|
|
casper.waitUntilVisible("#id_realm_msg_edit_limit_setting", function () {
|
|
|
|
casper.evaluate(function () {
|
|
|
|
$("#id_realm_msg_edit_limit_setting").val("upto_ten_min").change();
|
|
|
|
});
|
|
|
|
submit_edit_limit_changed();
|
|
|
|
});
|
|
|
|
});
|
2017-11-21 01:18:02 +01:00
|
|
|
|
|
|
|
casper.then(function () {
|
2018-03-14 23:45:42 +01:00
|
|
|
casper.waitUntilVisible('#org-submit-msg-editing[data-status="saved"]', function () {
|
|
|
|
casper.test.assertSelectorHasText('#org-submit-msg-editing',
|
|
|
|
'Saved');
|
2017-11-21 01:18:02 +01:00
|
|
|
casper.test.assertEval(function () {
|
2018-04-02 11:18:40 +02:00
|
|
|
return (document.querySelector('#id_realm_msg_edit_limit_setting').value === "upto_ten_min");
|
|
|
|
}, 'Allow message editing Setting re-activated and set to 10 minutes');
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-02 11:18:40 +02:00
|
|
|
// SET LIMIT TO 1 WEEK
|
|
|
|
heading("LIMIT TO 1 WEEK");
|
2017-02-09 09:42:27 +01:00
|
|
|
|
2017-11-21 00:54:47 +01:00
|
|
|
casper.then(function () {
|
2018-04-02 11:18:40 +02:00
|
|
|
casper.test.info("Changing message edit limit setting");
|
|
|
|
casper.waitUntilVisible("#id_realm_msg_edit_limit_setting", function () {
|
2017-11-21 00:54:47 +01:00
|
|
|
casper.evaluate(function () {
|
2018-04-02 11:18:40 +02:00
|
|
|
$("#id_realm_msg_edit_limit_setting").val("upto_one_week").change();
|
2017-11-21 00:54:47 +01:00
|
|
|
});
|
2018-04-02 11:18:40 +02:00
|
|
|
submit_edit_limit_changed();
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2018-03-14 23:45:42 +01:00
|
|
|
casper.waitUntilVisible('#org-submit-msg-editing[data-status="saved"]', function () {
|
|
|
|
casper.test.assertSelectorHasText('#org-submit-msg-editing',
|
|
|
|
'Saved');
|
2017-02-09 09:42:27 +01:00
|
|
|
casper.test.assertEval(function () {
|
2018-04-02 11:18:40 +02:00
|
|
|
return (document.querySelector('#id_realm_msg_edit_limit_setting').value === "upto_one_week");
|
|
|
|
}, 'Message edit limit set to one week');
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-02 11:18:40 +02:00
|
|
|
// SET LIMIT TO 0
|
|
|
|
heading("NO LIMIT");
|
2018-01-11 13:32:25 +01:00
|
|
|
|
2018-04-02 11:18:40 +02:00
|
|
|
casper.then(function () {
|
|
|
|
casper.test.info("Changing message edit limit setting");
|
|
|
|
casper.waitUntilVisible("#id_realm_msg_edit_limit_setting", function () {
|
|
|
|
casper.evaluate(function () {
|
|
|
|
$("#id_realm_msg_edit_limit_setting").val("any_time").change();
|
|
|
|
});
|
|
|
|
submit_edit_limit_changed();
|
|
|
|
});
|
|
|
|
});
|
2017-12-27 23:25:14 +01:00
|
|
|
|
2017-02-09 09:42:27 +01:00
|
|
|
casper.then(function () {
|
2018-03-14 23:45:42 +01:00
|
|
|
casper.waitUntilVisible('#org-submit-msg-editing[data-status="saved"]', function () {
|
|
|
|
casper.test.assertSelectorHasText('#org-submit-msg-editing',
|
|
|
|
'Saved');
|
2017-02-09 09:42:27 +01:00
|
|
|
casper.test.assertEval(function () {
|
2018-04-02 11:18:40 +02:00
|
|
|
return (document.querySelector('#id_realm_msg_edit_limit_setting').value === "any_time");
|
|
|
|
}, 'Message can be edited any time');
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-02 11:18:40 +02:00
|
|
|
// CUSTOM LIMIT
|
|
|
|
heading("CUSTOM LIMIT");
|
2018-01-11 13:32:25 +01:00
|
|
|
|
2017-02-09 09:42:27 +01:00
|
|
|
casper.then(function () {
|
2018-04-02 11:18:40 +02:00
|
|
|
casper.test.info("Changing message edit limit setting");
|
|
|
|
casper.waitUntilVisible("#id_realm_msg_edit_limit_setting", function () {
|
|
|
|
casper.evaluate(function () {
|
|
|
|
$("#id_realm_msg_edit_limit_setting").val("custom_limit").change();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
casper.waitUntilVisible('#id_realm_message_content_edit_limit_minutes', function () {
|
2017-02-09 09:42:27 +01:00
|
|
|
casper.evaluate(function () {
|
2018-04-02 11:18:40 +02:00
|
|
|
$('#id_realm_message_content_edit_limit_minutes').val("100");
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
2018-04-02 11:18:40 +02:00
|
|
|
submit_edit_limit_changed();
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2018-03-14 23:45:42 +01:00
|
|
|
casper.waitUntilVisible('#org-submit-msg-editing[data-status="saved"]', function () {
|
|
|
|
casper.test.assertSelectorHasText('#org-submit-msg-editing',
|
|
|
|
'Saved');
|
2017-02-09 09:42:27 +01:00
|
|
|
casper.test.assertEval(function () {
|
2018-04-02 11:18:40 +02:00
|
|
|
return $('#id_realm_msg_edit_limit_setting').val() === "custom_limit";
|
|
|
|
}, 'Custom message edit limit set');
|
2017-02-09 09:42:27 +01:00
|
|
|
casper.test.assertEval(function () {
|
2018-04-02 11:18:40 +02:00
|
|
|
return $('#id_realm_message_content_edit_limit_minutes').val() === "100";
|
|
|
|
}, 'Message edit limit set to 100 minutes');
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-02 11:18:40 +02:00
|
|
|
// INVALID LIMIT
|
|
|
|
heading("INVALID LIMIT");
|
2018-01-11 13:32:25 +01:00
|
|
|
|
2017-02-09 09:42:27 +01:00
|
|
|
casper.then(function () {
|
2018-04-02 11:18:40 +02:00
|
|
|
casper.test.info("Changing message edit limit setting");
|
|
|
|
casper.waitUntilVisible("#id_realm_msg_edit_limit_setting", function () {
|
2017-02-09 09:42:27 +01:00
|
|
|
casper.evaluate(function () {
|
2018-04-02 11:18:40 +02:00
|
|
|
$("#id_realm_msg_edit_limit_setting").val("custom_limit").change();
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
|
|
|
});
|
2018-04-02 11:18:40 +02:00
|
|
|
casper.waitUntilVisible('#id_realm_message_content_edit_limit_minutes', function () {
|
|
|
|
casper.evaluate(function () {
|
|
|
|
$('#id_realm_message_content_edit_limit_minutes').val("-100");
|
|
|
|
});
|
|
|
|
submit_edit_limit_changed();
|
|
|
|
});
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2018-04-02 11:18:40 +02:00
|
|
|
casper.waitUntilVisible('.admin-realm-failed-change-status', function () {
|
2018-03-14 23:45:42 +01:00
|
|
|
casper.test.assertSelectorHasText('#org-submit-msg-editing',
|
2018-04-02 11:18:40 +02:00
|
|
|
'Save');
|
2017-02-09 09:42:27 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
common.then_log_out();
|
|
|
|
|
|
|
|
casper.run(function () {
|
|
|
|
casper.test.done();
|
|
|
|
});
|