From 74f40a0a5828fcd82ea4d28467278bd6b624fa9d Mon Sep 17 00:00:00 2001 From: Aditya Bansal Date: Thu, 29 Jun 2017 18:01:26 +0530 Subject: [PATCH] compose.js: Add node test coverage for report_as_received() function. --- frontend_tests/node_tests/compose.js | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js index e760d0a85c..e6508e1693 100644 --- a/frontend_tests/node_tests/compose.js +++ b/frontend_tests/node_tests/compose.js @@ -287,6 +287,36 @@ people.add(bob); assert.deepEqual(compose.send_times_data[13], { rendered_content_disparity: true }); }()); +(function test_report_as_received() { + var msg = { + id: 12, + sent_by_me: true, + }; + var set_timeout_called = false; + global.patch_builtin('setTimeout', function (func, delay) { + assert.equal(delay, 0); + func(); + set_timeout_called = true; + }); + compose.send_times_data[12].locally_echoed = true; + channel.post = function (payload) { + assert.equal(payload.url, '/json/report_send_time'); + assert.equal(typeof(payload.data.time), 'string'); + assert(payload.data.locally_echoed); + assert(!payload.data.rendered_content_disparity); + }; + compose.report_as_received(msg); + assert.equal(typeof(compose.send_times_data[12].received), 'object'); + assert.equal(typeof(compose.send_times_data[12].displayed), 'object'); + assert(set_timeout_called); + + delete compose.send_times_data[13]; + msg.id = 13; + compose.report_as_received(msg); + assert.equal(typeof(compose.send_times_data[13].received), 'object'); + assert.equal(typeof(compose.send_times_data[13].displayed), 'object'); +}()); + (function test_set_focused_recipient() { var sub = { stream_id: 101,