refactor: Simplify logic for circles.

We now have a function get_user_circle_class
that returns one of these values:

    "user_circle_green"
    "user_circle_orange"
    "user_circle_empty"

And we put that in the templates.

And then CSS renders the circle of the appropriate
color.

The unit tests now explicitly capture whether
we are rendering the correct kind of circle.
This commit is contained in:
Steve Howell
2019-02-17 01:10:42 +00:00
committed by Tim Abbott
parent ba91f628c7
commit 1adcaad04a
11 changed files with 58 additions and 35 deletions

View File

@@ -607,7 +607,7 @@ run_test('insert_one_user_into_empty_list', () => {
clear_buddy_list();
activity.redraw_user(alice.user_id);
assert(appended_html.indexOf('data-user-id="1"') > 0);
assert(appended_html.indexOf('user_active') > 0);
assert(appended_html.indexOf('user_circle_green') > 0);
});
reset_setup();
@@ -622,11 +622,11 @@ run_test('insert_alice_then_fred', () => {
activity.redraw_user(alice.user_id);
assert(appended_html.indexOf('data-user-id="1"') > 0);
assert(appended_html.indexOf('user_active') > 0);
assert(appended_html.indexOf('user_circle_green') > 0);
activity.redraw_user(fred.user_id);
assert(appended_html.indexOf('data-user-id="2"') > 0);
assert(appended_html.indexOf('user_active') > 0);
assert(appended_html.indexOf('user_circle_green') > 0);
});
reset_setup();
@@ -641,7 +641,7 @@ run_test('insert_fred_then_alice_then_rename', () => {
activity.redraw_user(fred.user_id);
assert(appended_html.indexOf('data-user-id="2"') > 0);
assert(appended_html.indexOf('user_active') > 0);
assert(appended_html.indexOf('user_circle_green') > 0);
var fred_stub = $.create('fred-first');
buddy_list_add(fred.user_id, fred_stub);
@@ -653,7 +653,7 @@ run_test('insert_fred_then_alice_then_rename', () => {
activity.redraw_user(alice.user_id);
assert(inserted_html.indexOf('data-user-id="1"') > 0);
assert(inserted_html.indexOf('user_active') > 0);
assert(inserted_html.indexOf('user_circle_green') > 0);
// Next rename fred to Aaron.
const fred_with_new_name = {

View File

@@ -77,6 +77,20 @@ function activate_people() {
make_people();
activate_people();
run_test('user_circle', () => {
assert.equal(buddy_data.get_user_circle_class(selma.user_id), 'user_circle_green');
user_status.set_away(selma.user_id);
assert.equal(buddy_data.get_user_circle_class(selma.user_id), 'user_circle_empty');
user_status.revoke_away(selma.user_id);
assert.equal(buddy_data.get_user_circle_class(selma.user_id), 'user_circle_green');
assert.equal(buddy_data.get_user_circle_class(me.user_id), 'user_circle_green');
user_status.set_away(me.user_id);
assert.equal(buddy_data.get_user_circle_class(me.user_id), 'user_circle_empty');
user_status.revoke_away(me.user_id);
assert.equal(buddy_data.get_user_circle_class(me.user_id), 'user_circle_green');
});
run_test('buddy_status', () => {
assert.equal(buddy_data.buddy_status(selma.user_id), 'active');
user_status.set_away(selma.user_id);

View File

@@ -157,7 +157,7 @@ run_test('sender_hover', () => {
user_id: 42,
user_time: undefined,
user_type: i18n.t('Member'),
type: 'offline',
user_circle_class: 'user_circle_empty',
user_last_seen_time_status: 'translated: More than 2 weeks ago',
pm_with_uri: '#narrow/pm-with/42-alice',
sent_by_uri: '#narrow/sender/42-alice',

View File

@@ -1422,19 +1422,16 @@ run_test('user_group_info_popover_content', () => {
group_description: 'groupDescription',
members: [
{
presence_status: 'active',
full_name: 'Active Alice',
user_last_seen_time_status: 'time',
is_bot: false,
},
{
presence_status: 'offline',
full_name: 'Bot Bob',
user_last_seen_time_status: 'time',
is_bot: true,
},
{
presence_status: 'offline',
full_name: 'Inactive Imogen',
user_last_seen_time_status: 'time',
is_bot: false,
@@ -1445,8 +1442,6 @@ run_test('user_group_info_popover_content', () => {
var html = render('user_group_info_popover_content', args);
var allUsers = $(html).find("li");
assert.equal(allUsers[0].classList.contains("user_active"), true);
assert.equal(allUsers[2].classList.contains("user_offline"), true);
assert.equal($(allUsers[0]).text().trim(), 'Active Alice');
assert.equal($(allUsers[1]).text().trim(), 'Bot Bob');
assert.equal($(allUsers[2]).text().trim(), 'Inactive Imogen');