hotspots: Change hotspots to have a name and a description.

This commit is contained in:
Rishi Gupta
2017-04-14 20:50:59 -07:00
committed by Tim Abbott
parent 28874cf26f
commit dbac262509
4 changed files with 35 additions and 38 deletions

View File

@@ -5,7 +5,7 @@ var exports = {};
exports.show = function (hotspot_list) { exports.show = function (hotspot_list) {
$('.hotspot').hide(); $('.hotspot').hide();
for (var i = 0; i < hotspot_list.length; i += 1) { for (var i = 0; i < hotspot_list.length; i += 1) {
$("#hotspot_".concat(hotspot_list[i])).show(); $("#hotspot_".concat(hotspot_list[i].name)).show();
} }
}; };
@@ -21,33 +21,18 @@ function mark_hotspot_as_read(hotspot) {
} }
$(function () { $(function () {
$("#hotspot_welcome").on('click', function (e) { $("#hotspot_click_to_reply").on('click', function (e) {
mark_hotspot_as_read("welcome"); mark_hotspot_as_read("click_to_reply");
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
}); });
$("#hotspot_streams").on('click', function (e) { $("#hotspot_new_topic_button").on('click', function (e) {
mark_hotspot_as_read("streams"); mark_hotspot_as_read("new_topic_button");
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
}); });
$("#hotspot_topics").on('click', function (e) { $("#hotspot_stream_settings").on('click', function (e) {
mark_hotspot_as_read("topics"); mark_hotspot_as_read("stream_settings");
e.preventDefault();
e.stopPropagation();
});
$("#hotspot_narrowing").on('click', function (e) {
mark_hotspot_as_read("narrowing");
e.preventDefault();
e.stopPropagation();
});
$("#hotspot_replying").on('click', function (e) {
mark_hotspot_as_read("replying");
e.preventDefault();
e.stopPropagation();
});
$("#hotspot_get_started").on('click', function (e) {
mark_hotspot_as_read("get_started");
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
}); });

View File

@@ -1,12 +1,17 @@
from zerver.models import UserProfile, UserHotspot from zerver.models import UserProfile, UserHotspot
from typing import List, Text from typing import List, Text, Dict
ALL_HOTSPOTS = {
'click_to_reply': 'Click anywhere on a message to reply.',
'new_topic_botton': 'Click the "New topic" button to start a new conversation.',
'stream_settings': 'Most discussion on Zulip happens in streams. Click here to create or join additional streams.',
}
ALL_HOTSPOTS = ['welcome', 'streams', 'topics', 'narrowing', 'replying', 'get_started']
def get_next_hotspots(user): def get_next_hotspots(user):
# type: (UserProfile) -> List[Text] # type: (UserProfile) -> List[Dict[str, Text]]
seen_hotspots = frozenset(UserHotspot.objects.filter(user=user).values_list('hotspot', flat=True)) seen_hotspots = frozenset(UserHotspot.objects.filter(user=user).values_list('hotspot', flat=True))
for hotspot in ALL_HOTSPOTS: for hotspot in ['click_to_reply', 'new_topic_botton', 'stream_settings']:
if hotspot not in seen_hotspots: if hotspot not in seen_hotspots:
return [hotspot] return [{'name': hotspot, 'description': ALL_HOTSPOTS[hotspot]}]
return [] return []

View File

@@ -1332,9 +1332,12 @@ class EventsRegisterTest(ZulipTestCase):
# type: () -> None # type: () -> None
schema_checker = self.check_events_dict([ schema_checker = self.check_events_dict([
('type', equals('hotspots')), ('type', equals('hotspots')),
('hotspots', check_list(check_string)), ('hotspots', check_list(check_dict_only([
('name', check_string),
('description', check_string),
]))),
]) ])
events = self.do_test(lambda: do_mark_hotspot_as_read(self.user_profile, 'welcome')) events = self.do_test(lambda: do_mark_hotspot_as_read(self.user_profile, 'click_to_reply'))
error = schema_checker('events[0]', events[0]) error = schema_checker('events[0]', events[0])
self.assert_on_error(error) self.assert_on_error(error)

View File

@@ -16,14 +16,18 @@ class TestGetNextHotspots(ZulipTestCase):
def test_first_hotspot(self): def test_first_hotspot(self):
# type: () -> None # type: () -> None
user = self.example_user('hamlet') user = self.example_user('hamlet')
self.assertEqual(get_next_hotspots(user), ['welcome']) hotspots = get_next_hotspots(user)
self.assertEqual(len(hotspots), 1)
self.assertEqual(hotspots[0]['name'], 'click_to_reply')
def test_some_done_some_not(self): def test_some_done_some_not(self):
# type: () -> None # type: () -> None
user = self.example_user('hamlet') user = self.example_user('hamlet')
do_mark_hotspot_as_read(user, 'welcome') do_mark_hotspot_as_read(user, 'click_to_reply')
do_mark_hotspot_as_read(user, 'topics') do_mark_hotspot_as_read(user, 'stream_settings')
self.assertEqual(get_next_hotspots(user), ['streams']) hotspots = get_next_hotspots(user)
self.assertEqual(len(hotspots), 1)
self.assertEqual(hotspots[0]['name'], 'new_topic_botton')
def test_all_done(self): def test_all_done(self):
# type: () -> None # type: () -> None
@@ -36,22 +40,22 @@ class TestHotspots(ZulipTestCase):
def test_do_mark_hotspot_as_read(self): def test_do_mark_hotspot_as_read(self):
# type: () -> None # type: () -> None
user = self.example_user('hamlet') user = self.example_user('hamlet')
do_mark_hotspot_as_read(user, 'streams') do_mark_hotspot_as_read(user, 'new_topic_button')
self.assertEqual(list(UserHotspot.objects.filter(user=user) self.assertEqual(list(UserHotspot.objects.filter(user=user)
.values_list('hotspot', flat=True)), ['streams']) .values_list('hotspot', flat=True)), ['new_topic_button'])
def test_hotspots_url_endpoint(self): def test_hotspots_url_endpoint(self):
# type: () -> None # type: () -> None
user = self.example_user('hamlet') user = self.example_user('hamlet')
self.login(user.email) self.login(user.email)
result = self.client_post('/json/users/me/hotspots', result = self.client_post('/json/users/me/hotspots',
{'hotspot': ujson.dumps('welcome')}) {'hotspot': ujson.dumps('click_to_reply')})
self.assert_json_success(result) self.assert_json_success(result)
self.assertEqual(list(UserHotspot.objects.filter(user=user) self.assertEqual(list(UserHotspot.objects.filter(user=user)
.values_list('hotspot', flat=True)), ['welcome']) .values_list('hotspot', flat=True)), ['click_to_reply'])
result = self.client_post('/json/users/me/hotspots', result = self.client_post('/json/users/me/hotspots',
{'hotspot': ujson.dumps('invalid')}) {'hotspot': ujson.dumps('invalid')})
self.assert_json_error(result, "Unknown hotspot: invalid") self.assert_json_error(result, "Unknown hotspot: invalid")
self.assertEqual(list(UserHotspot.objects.filter(user=user) self.assertEqual(list(UserHotspot.objects.filter(user=user)
.values_list('hotspot', flat=True)), ['welcome']) .values_list('hotspot', flat=True)), ['click_to_reply'])