|
2 | 2 |
|
3 | 3 | import deepFreeze from 'deep-freeze';
|
4 | 4 |
|
| 5 | +import Immutable from 'immutable'; |
5 | 6 | import * as eg from '../../__tests__/lib/exampleData';
|
6 | 7 | import { PRESENCE_RESPONSE, EVENT_PRESENCE } from '../../actionConstants';
|
7 | 8 | import {
|
8 | 9 | reducer as presenceReducer,
|
9 | 10 | getAggregatedPresence,
|
10 |
| - userLastActiveAsRelativeTimeString, |
11 | 11 | statusFromPresence,
|
12 | 12 | statusFromPresenceAndUserStatus,
|
| 13 | + getUserLastActiveAsRelativeTimeString, |
13 | 14 | } from '../presenceModel';
|
14 | 15 | import { makePresenceState } from './presence-testlib';
|
| 16 | +import type { UserPresence, UserStatus } from '../../api/modelTypes'; |
15 | 17 |
|
16 | 18 | const currentTimestamp = Date.now() / 1000;
|
17 | 19 |
|
@@ -85,52 +87,59 @@ describe('getAggregatedPresence', () => {
|
85 | 87 | });
|
86 | 88 | });
|
87 | 89 |
|
88 |
| -describe('userLastActiveAsRelativeTimeString', () => { |
89 |
| - test('given a presence return a relative time', () => { |
90 |
| - expect( |
91 |
| - userLastActiveAsRelativeTimeString( |
92 |
| - { |
93 |
| - aggregated: { client: 'website', status: 'active', timestamp: currentTimestamp - 240 }, |
94 |
| - }, |
95 |
| - { away: false, status_text: null, status_emoji: null }, |
96 |
| - eg.recentZulipFeatureLevel, |
97 |
| - ), |
98 |
| - ).toBe('4 minutes ago'); |
| 90 | +describe('getUserLastActiveAsRelativeTimeString', () => { |
| 91 | + function lastActiveString(args: { |
| 92 | + userPresence: UserPresence, |
| 93 | + userStatus: UserStatus, |
| 94 | + zulipFeatureLevel?: number, |
| 95 | + }): string | null { |
| 96 | + const { userPresence, userStatus, zulipFeatureLevel = eg.recentZulipFeatureLevel } = args; |
| 97 | + return getUserLastActiveAsRelativeTimeString( |
| 98 | + eg.reduxStatePlus({ |
| 99 | + presence: makePresenceState([[eg.otherUser, userPresence]]), |
| 100 | + userStatuses: Immutable.Map([[eg.otherUser.user_id, userStatus]]), |
| 101 | + accounts: [{ ...eg.plusReduxState.accounts[0], zulipFeatureLevel }], |
| 102 | + }), |
| 103 | + eg.otherUser, |
| 104 | + currentTimestamp * 1000, |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + test('a recent time', () => { |
| 109 | + const userPresence = { |
| 110 | + aggregated: { client: 'website', status: 'active', timestamp: currentTimestamp - 240 }, |
| 111 | + }; |
| 112 | + const userStatus = { away: false, status_text: null, status_emoji: null }; |
| 113 | + expect(lastActiveString({ userPresence, userStatus })).toBe('4 minutes ago'); |
99 | 114 | });
|
100 | 115 |
|
101 | 116 | test('if less than a threshold, the user is currently active', () => {
|
102 |
| - expect( |
103 |
| - userLastActiveAsRelativeTimeString( |
104 |
| - { |
105 |
| - aggregated: { client: 'website', status: 'active', timestamp: currentTimestamp - 100 }, |
106 |
| - }, |
107 |
| - { away: false, status_text: null, status_emoji: null }, |
108 |
| - eg.recentZulipFeatureLevel, |
109 |
| - ), |
110 |
| - ).toBe('now'); |
| 117 | + const userPresence = { |
| 118 | + aggregated: { client: 'website', status: 'active', timestamp: currentTimestamp - 100 }, |
| 119 | + }; |
| 120 | + const userStatus = { away: false, status_text: null, status_emoji: null }; |
| 121 | + expect(lastActiveString({ userPresence, userStatus })).toBe('now'); |
111 | 122 | });
|
112 | 123 |
|
113 | 124 | // TODO(server-6.0): Remove
|
114 | 125 | test('Pre-FL 148: if less than a day and user is "away", use imprecise "today"', () => {
|
115 |
| - expect( |
116 |
| - userLastActiveAsRelativeTimeString( |
117 |
| - { aggregated: { client: 'website', status: 'active', timestamp: currentTimestamp - 100 } }, |
118 |
| - { away: true, status_text: null, status_emoji: null }, |
119 |
| - 147, |
120 |
| - ), |
121 |
| - ).toBe('today'); |
| 126 | + const userPresence = { |
| 127 | + aggregated: { client: 'website', status: 'active', timestamp: currentTimestamp - 100 }, |
| 128 | + }; |
| 129 | + const userStatus = { away: true, status_text: null, status_emoji: null }; |
| 130 | + const zulipFeatureLevel = 147; |
| 131 | + expect(lastActiveString({ userPresence, userStatus, zulipFeatureLevel })).toBe('today'); |
122 | 132 | });
|
123 | 133 |
|
124 | 134 | // TODO(server-6.0): Remove, once this test case is redundant with those
|
125 | 135 | // above after the status parameter is gone.
|
126 | 136 | test('FL 148: if less than a day and user is "away", *don\'t* use imprecise "today"', () => {
|
127 |
| - expect( |
128 |
| - userLastActiveAsRelativeTimeString( |
129 |
| - { aggregated: { client: 'website', status: 'active', timestamp: currentTimestamp - 100 } }, |
130 |
| - { away: true, status_text: null, status_emoji: null }, |
131 |
| - 148, |
132 |
| - ), |
133 |
| - ).not.toBe('today'); |
| 137 | + const userPresence = { |
| 138 | + aggregated: { client: 'website', status: 'active', timestamp: currentTimestamp - 100 }, |
| 139 | + }; |
| 140 | + const userStatus = { away: true, status_text: null, status_emoji: null }; |
| 141 | + const zulipFeatureLevel = 148; |
| 142 | + expect(lastActiveString({ userPresence, userStatus, zulipFeatureLevel })).not.toBe('today'); |
134 | 143 | });
|
135 | 144 | });
|
136 | 145 |
|
|
0 commit comments