From 5d20c4b8fb7249d4890d20f168bfab7bc831c274 Mon Sep 17 00:00:00 2001 From: Rohitt Vashishtha Date: Fri, 19 Jul 2019 17:42:10 +0000 Subject: [PATCH] typeahead: Clear rendered stream html on stream rename. Previously, after a stream name, you could search for it using its new name but the typeahead would still display the old name. --- frontend_tests/node_tests/typeahead_helper.js | 27 +++++++++++++++++++ static/js/subs.js | 3 +++ static/js/typeahead_helper.js | 6 +++++ 3 files changed, 36 insertions(+) diff --git a/frontend_tests/node_tests/typeahead_helper.js b/frontend_tests/node_tests/typeahead_helper.js index 617002a084..19ec6e09a1 100644 --- a/frontend_tests/node_tests/typeahead_helper.js +++ b/frontend_tests/node_tests/typeahead_helper.js @@ -520,6 +520,33 @@ run_test('render_stream', () => { assert(rendered); }); +run_test('clear_rendered_stream', () => { + var rendered = false; + var stream = { + description: 'This is a description.', + stream_id: 44, + name: 'Stream To Be Cleared', + }; + global.stub_templates(function (template_name, args) { + assert.equal(template_name, 'typeahead_list_item'); + assert.equal(args.primary, stream.name); + assert.equal(args.secondary, stream.description); + rendered = true; + return 'typeahead-item-stub'; + }); + assert.equal(th.render_stream(stream), 'typeahead-item-stub'); + assert(rendered); + + rendered = false; + assert.equal(th.render_stream(stream), 'typeahead-item-stub'); + assert.equal(rendered, false); + + // Here rendered will be true as it is being rendered again. + th.clear_rendered_stream(stream.stream_id); + assert.equal(th.render_stream(stream), 'typeahead-item-stub'); + assert(rendered); +}); + run_test('render_emoji', () => { // Test render_emoji with normal emoji. var rendered = false; diff --git a/static/js/subs.js b/static/js/subs.js index e4ede418cc..ee726c1615 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -149,6 +149,9 @@ exports.update_stream_name = function (sub, new_name) { // Update the message feed. message_live_update.update_stream_name(stream_id, new_name); + + // Clear rendered typeahead cache + typeahead_helper.clear_rendered_stream(stream_id); }; exports.update_stream_description = function (sub, description, rendered_description) { diff --git a/static/js/typeahead_helper.js b/static/js/typeahead_helper.js index 1a72480c87..b4e4dc9a23 100644 --- a/static/js/typeahead_helper.js +++ b/static/js/typeahead_helper.js @@ -132,6 +132,12 @@ exports.render_person_or_user_group = function (item) { return typeahead_helper.render_person(item); }; +exports.clear_rendered_stream = function (stream_id) { + if (rendered.streams.has(stream_id)) { + rendered.streams.del(stream_id); + } +}; + exports.render_stream = function (stream) { var desc = stream.description; var short_desc = desc.substring(0, 35);