1 | "use strict";
|
2 | import 'source-map-support/register';
|
3 | const sdk = require("../..");
|
4 | const User = sdk.User;
|
5 | const utils = require("../test-utils");
|
6 |
|
7 | import expect from 'expect';
|
8 |
|
9 | describe("User", function() {
|
10 | const userId = "@alice:bar";
|
11 | let user;
|
12 |
|
13 | beforeEach(function() {
|
14 | utils.beforeEach(this);
|
15 | user = new User(userId);
|
16 | });
|
17 |
|
18 | describe("setPresenceEvent", function() {
|
19 | const event = utils.mkEvent({
|
20 | type: "m.presence", content: {
|
21 | presence: "online",
|
22 | user_id: userId,
|
23 | displayname: "Alice",
|
24 | last_active_ago: 1085,
|
25 | avatar_url: "mxc://foo/bar",
|
26 | }, event: true,
|
27 | });
|
28 |
|
29 | it("should emit 'User.displayName' if the display name changes", function() {
|
30 | let emitCount = 0;
|
31 | user.on("User.displayName", function(ev, usr) {
|
32 | emitCount += 1;
|
33 | });
|
34 | user.setPresenceEvent(event);
|
35 | expect(emitCount).toEqual(1);
|
36 | user.setPresenceEvent(event);
|
37 | expect(emitCount).toEqual(1);
|
38 | });
|
39 |
|
40 | it("should emit 'User.avatarUrl' if the avatar URL changes", function() {
|
41 | let emitCount = 0;
|
42 | user.on("User.avatarUrl", function(ev, usr) {
|
43 | emitCount += 1;
|
44 | });
|
45 | user.setPresenceEvent(event);
|
46 | expect(emitCount).toEqual(1);
|
47 | user.setPresenceEvent(event);
|
48 | expect(emitCount).toEqual(1);
|
49 | });
|
50 |
|
51 | it("should emit 'User.presence' if the presence changes", function() {
|
52 | let emitCount = 0;
|
53 | user.on("User.presence", function(ev, usr) {
|
54 | emitCount += 1;
|
55 | });
|
56 | user.setPresenceEvent(event);
|
57 | expect(emitCount).toEqual(1);
|
58 | user.setPresenceEvent(event);
|
59 | expect(emitCount).toEqual(1);
|
60 | });
|
61 |
|
62 | it("should set User.displayName", function() {
|
63 | user.setPresenceEvent(event);
|
64 | expect(user.displayName).toEqual("Alice");
|
65 | });
|
66 |
|
67 | it("should set User.avatarUrl", function() {
|
68 | user.setPresenceEvent(event);
|
69 | expect(user.avatarUrl).toEqual("mxc://foo/bar");
|
70 | });
|
71 |
|
72 | it("should set User.presence", function() {
|
73 | user.setPresenceEvent(event);
|
74 | expect(user.presence).toEqual("online");
|
75 | });
|
76 |
|
77 | it("should set User.lastActiveAgo", function() {
|
78 | user.setPresenceEvent(event);
|
79 | expect(user.lastActiveAgo).toEqual(1085);
|
80 | });
|
81 |
|
82 | it("should set User.events.presence", function() {
|
83 | user.setPresenceEvent(event);
|
84 | expect(user.events.presence).toEqual(event);
|
85 | });
|
86 | });
|
87 | });
|