var common = require('../casper_lib/common.js').common; function enter_mention_in_composer(str, item) { casper.then(function () { casper.test.info('Start typing @all'); casper.evaluate(function (str, item) { // Set the value and then send a bogus keyup event to trigger // the typeahead. $('#new_message_content') .focus() .val(str) .trigger($.Event('keyup', { which: 0 })); // Trigger the typeahead. // Reaching into the guts of Bootstrap Typeahead like this is not // great, but I found it very hard to do it any other way. var tah = $('#new_message_content').data().typeahead; tah.mouseenter({ currentTarget: $('.typeahead:visible li:contains("'+item+'")')[0] }); tah.select(); }, {str: str, item: item}); }); } ///////////////////////////////////////////////////// common.start_and_log_in(); casper.verbonse = true; casper.waitForSelector('#new_message_content', function () { casper.test.info('compose box visible'); casper.page.sendEvent('keypress', "c"); // brings up the compose box }); casper.then(function () { casper.fill('form[action^="/json/messages"]', { stream: 'Verona', subject: 'Test mention all' }); }); enter_mention_in_composer('@all', 'all'); casper.waitForText("Are you sure you want to message all", function () { casper.test.info('Warning message appears when mentioning @all'); casper.test.assertSelectorHasText('.compose-all-everyone', 'Are you sure you want to message all'); }); casper.then( function () { casper.test.info('Click Send Button'); casper.click('#compose-send-button'); }); casper.waitForText("Please remove @all", function () { casper.test.info('Error message appears when attempting to send a message without acknowledging the @all mention warning'); casper.test.assertSelectorHasText('#error-msg', "Please remove @all / @everyone or acknowledge that you will be spamming everyone!"); }); casper.waitForSelector('.compose-all-everyone-confirm', function () { casper.click('.compose-all-everyone-confirm'); }, function () { casper.test.error('Could not click confirm button.'); }); casper.waitWhileVisible('.compose-all-everyone-confirm', function () { casper.test.info('Check that error messages are gone.'); casper.test.assertNotVisible('.compose-all-everyone-msg'); casper.test.assertNotVisible('#error-msg'); }); casper.then( function () { casper.test.info('Click Send Button'); casper.click('#compose-send-button'); }); casper.then( function () { common.expected_messages('zhome', ['Verona > Test mention all'], ["
@all
"] ); }); common.then_log_out(); casper.run(function () { casper.test.done(); });