From 7363851561396d2518b62b34b718190cba3958ef Mon Sep 17 00:00:00 2001 From: Kevin Mehall Date: Tue, 11 Jun 2013 17:08:11 -0400 Subject: [PATCH] Add casper tests to check that the subject/stream/recipient fields are populated when replying (imported from commit 7a0337467c6e7a1ed3118e07d2b4ad904719e093) --- zephyr/tests/frontend/common.js | 11 ++++++++ zephyr/tests/frontend/tests/03-compose.js | 33 ++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/zephyr/tests/frontend/common.js b/zephyr/tests/frontend/common.js index 657e21b5e7..a020060d42 100644 --- a/zephyr/tests/frontend/common.js +++ b/zephyr/tests/frontend/common.js @@ -88,6 +88,17 @@ exports.enable_page_console = function () { }); }; +exports.check_form = function (form_selector, expected, test_name) { + var values = casper.getFormValues(form_selector); + var k; + for (k in expected) { + if (expected.hasOwnProperty(k)) { + casper.test.assertEqual(values[k], expected[k], + test_name ? (test_name + ": " + k) : undefined); + } + } +}; + exports.send_message = function (type, params) { casper.waitForSelector('#new_message_content', function () { if(type === "stream") { diff --git a/zephyr/tests/frontend/tests/03-compose.js b/zephyr/tests/frontend/tests/03-compose.js index 9bcba3cec8..3cf04c7a65 100644 --- a/zephyr/tests/frontend/tests/03-compose.js +++ b/zephyr/tests/frontend/tests/03-compose.js @@ -2,18 +2,49 @@ var common = require('../common.js').common; common.start_and_log_in(); +// Send a message to try replying to +common.send_message('stream', { + stream: 'Verona', + subject: 'Reply test', + content: "We reply to this message" +}); +common.send_message('private', { + recipient: "cordelia@humbughq.com", + content: "And reply to this message" +}); +casper.waitForText("And reply to this message"); + casper.then(function () { // TODO: test correct events have fired // Test opening the compose box from the left side buttons + casper.click('body'); casper.page.sendEvent('keypress', "c"); casper.test.assertVisible('#compose', 'Compose box appears after clicking side stream button'); casper.test.assertVisible('#stream', 'Stream input box visible'); + common.check_form('#send_message_form', {stream: '', subject: ''}, "Stream empty on new compose"); casper.click('body'); casper.page.sendEvent('keypress', "C"); casper.test.assertVisible('#private_message_recipient', 'Switching from stream compose to PM compose'); + common.check_form('#send_message_form', {recipient: ''}, "Recipient empty on new PM"); casper.click('body'); casper.page.sendEvent('keypress', 'c'); casper.test.assertVisible('#stream', 'Switching from PM compose to stream compose'); + common.check_form('#send_message_form', {stream: '', subject: ''}, "Stream empty on new compose"); + + // Check that when you reply to a message it pre-populates the stream and subject fields + casper.click('body'); + casper.clickLabel("We reply to this message"); + casper.test.assertVisible('#stream', 'Stream input box visible on reply'); + common.check_form('#send_message_form', {stream: "Verona", subject: "Reply test"}, "Stream populated after reply by click"); + // Or recipient field + casper.click('body'); + casper.clickLabel("And reply to this message"); + common.check_form('#send_message_form', {recipient: "cordelia@humbughq.com"}, "Recipient populated after PM click"); + + common.keypress(27); //escape + casper.page.sendEvent('keypress', 'k'); + casper.page.sendEvent('keypress', 'r'); + common.check_form('#send_message_form', {stream: "Verona", subject: "Reply test"}, "Stream populated after reply with `r`"); // Test "closing" the compose box casper.click('body'); @@ -34,5 +65,5 @@ casper.then(function () { common.then_log_out(); casper.run(function () { - casper.test.done(6); + casper.test.done(17); });