|
@@ -62,7 +62,8 @@ describe("Converse", function() {
|
|
|
|
|
|
describe("Automatic status change", function () {
|
|
|
|
|
|
- it("happens when the client is idle for long enough", mock.initConverse((done, _converse) => {
|
|
|
+ it("happens when the client is idle for long enough",
|
|
|
+ mock.initConverse(['initialized'], {}, async (done, _converse) => {
|
|
|
let i = 0;
|
|
|
// Usually initialized by registerIntervalHandler
|
|
|
_converse.idle_seconds = 0;
|
|
@@ -70,26 +71,26 @@ describe("Converse", function() {
|
|
|
_converse.api.settings.set('auto_away', 3);
|
|
|
_converse.api.settings.set('auto_xa', 6);
|
|
|
|
|
|
- expect(_converse.api.user.status.get()).toBe('online');
|
|
|
+ expect(await _converse.api.user.status.get()).toBe('online');
|
|
|
while (i <= _converse.api.settings.get("auto_away")) {
|
|
|
_converse.onEverySecond(); i++;
|
|
|
}
|
|
|
expect(_converse.auto_changed_status).toBe(true);
|
|
|
|
|
|
while (i <= _converse.auto_xa) {
|
|
|
- expect(_converse.api.user.status.get()).toBe('away');
|
|
|
+ expect(await _converse.api.user.status.get()).toBe('away');
|
|
|
_converse.onEverySecond();
|
|
|
i++;
|
|
|
}
|
|
|
- expect(_converse.api.user.status.get()).toBe('xa');
|
|
|
+ expect(await _converse.api.user.status.get()).toBe('xa');
|
|
|
expect(_converse.auto_changed_status).toBe(true);
|
|
|
|
|
|
_converse.onUserActivity();
|
|
|
- expect(_converse.api.user.status.get()).toBe('online');
|
|
|
+ expect(await _converse.api.user.status.get()).toBe('online');
|
|
|
expect(_converse.auto_changed_status).toBe(false);
|
|
|
|
|
|
// Check that it also works for the chat feature
|
|
|
- _converse.api.user.status.set('chat')
|
|
|
+ await _converse.api.user.status.set('chat')
|
|
|
i = 0;
|
|
|
while (i <= _converse.api.settings.get("auto_away")) {
|
|
|
_converse.onEverySecond();
|
|
@@ -97,36 +98,36 @@ describe("Converse", function() {
|
|
|
}
|
|
|
expect(_converse.auto_changed_status).toBe(true);
|
|
|
while (i <= _converse.auto_xa) {
|
|
|
- expect(_converse.api.user.status.get()).toBe('away');
|
|
|
+ expect(await _converse.api.user.status.get()).toBe('away');
|
|
|
_converse.onEverySecond();
|
|
|
i++;
|
|
|
}
|
|
|
- expect(_converse.api.user.status.get()).toBe('xa');
|
|
|
+ expect(await _converse.api.user.status.get()).toBe('xa');
|
|
|
expect(_converse.auto_changed_status).toBe(true);
|
|
|
|
|
|
_converse.onUserActivity();
|
|
|
- expect(_converse.api.user.status.get()).toBe('online');
|
|
|
+ expect(await _converse.api.user.status.get()).toBe('online');
|
|
|
expect(_converse.auto_changed_status).toBe(false);
|
|
|
|
|
|
// Check that it doesn't work for 'dnd'
|
|
|
- _converse.api.user.status.set('dnd');
|
|
|
+ await _converse.api.user.status.set('dnd');
|
|
|
i = 0;
|
|
|
while (i <= _converse.api.settings.get("auto_away")) {
|
|
|
_converse.onEverySecond();
|
|
|
i++;
|
|
|
}
|
|
|
- expect(_converse.api.user.status.get()).toBe('dnd');
|
|
|
+ expect(await _converse.api.user.status.get()).toBe('dnd');
|
|
|
expect(_converse.auto_changed_status).toBe(false);
|
|
|
while (i <= _converse.auto_xa) {
|
|
|
- expect(_converse.api.user.status.get()).toBe('dnd');
|
|
|
+ expect(await _converse.api.user.status.get()).toBe('dnd');
|
|
|
_converse.onEverySecond();
|
|
|
i++;
|
|
|
}
|
|
|
- expect(_converse.api.user.status.get()).toBe('dnd');
|
|
|
+ expect(await _converse.api.user.status.get()).toBe('dnd');
|
|
|
expect(_converse.auto_changed_status).toBe(false);
|
|
|
|
|
|
_converse.onUserActivity();
|
|
|
- expect(_converse.api.user.status.get()).toBe('dnd');
|
|
|
+ expect(await _converse.api.user.status.get()).toBe('dnd');
|
|
|
expect(_converse.auto_changed_status).toBe(false);
|
|
|
done();
|
|
|
}));
|
|
@@ -136,47 +137,51 @@ describe("Converse", function() {
|
|
|
|
|
|
describe("The \"status\" API", function () {
|
|
|
|
|
|
- it("has a method for getting the user's availability", mock.initConverse((done, _converse) => {
|
|
|
+ it("has a method for getting the user's availability",
|
|
|
+ mock.initConverse(['statusInitialized'], {}, async(done, _converse) => {
|
|
|
_converse.xmppstatus.set('status', 'online');
|
|
|
- expect(_converse.api.user.status.get()).toBe('online');
|
|
|
+ expect(await _converse.api.user.status.get()).toBe('online');
|
|
|
_converse.xmppstatus.set('status', 'dnd');
|
|
|
- expect(_converse.api.user.status.get()).toBe('dnd');
|
|
|
+ expect(await _converse.api.user.status.get()).toBe('dnd');
|
|
|
done();
|
|
|
}));
|
|
|
|
|
|
- it("has a method for setting the user's availability", mock.initConverse((done, _converse) => {
|
|
|
- _converse.api.user.status.set('away');
|
|
|
- expect(_converse.xmppstatus.get('status')).toBe('away');
|
|
|
- _converse.api.user.status.set('dnd');
|
|
|
- expect(_converse.xmppstatus.get('status')).toBe('dnd');
|
|
|
- _converse.api.user.status.set('xa');
|
|
|
- expect(_converse.xmppstatus.get('status')).toBe('xa');
|
|
|
- _converse.api.user.status.set('chat');
|
|
|
- expect(_converse.xmppstatus.get('status')).toBe('chat');
|
|
|
- expect(() => _converse.api.user.status.set('invalid')).toThrow(
|
|
|
- new Error('Invalid availability value. See https://xmpp.org/rfcs/rfc3921.html#rfc.section.2.2.2.1')
|
|
|
- );
|
|
|
- done();
|
|
|
+ it("has a method for setting the user's availability", mock.initConverse(async (done, _converse) => {
|
|
|
+ await _converse.api.user.status.set('away');
|
|
|
+ expect(await _converse.xmppstatus.get('status')).toBe('away');
|
|
|
+ await _converse.api.user.status.set('dnd');
|
|
|
+ expect(await _converse.xmppstatus.get('status')).toBe('dnd');
|
|
|
+ await _converse.api.user.status.set('xa');
|
|
|
+ expect(await _converse.xmppstatus.get('status')).toBe('xa');
|
|
|
+ await _converse.api.user.status.set('chat');
|
|
|
+ expect(await _converse.xmppstatus.get('status')).toBe('chat');
|
|
|
+ const promise = _converse.api.user.status.set('invalid')
|
|
|
+ promise.catch(e => {
|
|
|
+ expect(e.message).toBe('Invalid availability value. See https://xmpp.org/rfcs/rfc3921.html#rfc.section.2.2.2.1');
|
|
|
+ done();
|
|
|
+ });
|
|
|
}));
|
|
|
|
|
|
- it("allows setting the status message as well", mock.initConverse((done, _converse) => {
|
|
|
- _converse.api.user.status.set('away', "I'm in a meeting");
|
|
|
+ it("allows setting the status message as well", mock.initConverse(async (done, _converse) => {
|
|
|
+ await _converse.api.user.status.set('away', "I'm in a meeting");
|
|
|
expect(_converse.xmppstatus.get('status')).toBe('away');
|
|
|
expect(_converse.xmppstatus.get('status_message')).toBe("I'm in a meeting");
|
|
|
done();
|
|
|
}));
|
|
|
|
|
|
- it("has a method for getting the user's status message", mock.initConverse((done, _converse) => {
|
|
|
- _converse.xmppstatus.set('status_message', undefined);
|
|
|
- expect(_converse.api.user.status.message.get()).toBe(undefined);
|
|
|
- _converse.xmppstatus.set('status_message', "I'm in a meeting");
|
|
|
- expect(_converse.api.user.status.message.get()).toBe("I'm in a meeting");
|
|
|
+ it("has a method for getting the user's status message",
|
|
|
+ mock.initConverse(['statusInitialized'], {}, async (done, _converse) => {
|
|
|
+ await _converse.xmppstatus.set('status_message', undefined);
|
|
|
+ expect(await _converse.api.user.status.message.get()).toBe(undefined);
|
|
|
+ await _converse.xmppstatus.set('status_message', "I'm in a meeting");
|
|
|
+ expect(await _converse.api.user.status.message.get()).toBe("I'm in a meeting");
|
|
|
done();
|
|
|
}));
|
|
|
|
|
|
- it("has a method for setting the user's status message", mock.initConverse((done, _converse) => {
|
|
|
+ it("has a method for setting the user's status message",
|
|
|
+ mock.initConverse(['statusInitialized'], {}, async (done, _converse) => {
|
|
|
_converse.xmppstatus.set('status_message', undefined);
|
|
|
- _converse.api.user.status.message.set("I'm in a meeting");
|
|
|
+ await _converse.api.user.status.message.set("I'm in a meeting");
|
|
|
expect(_converse.xmppstatus.get('status_message')).toBe("I'm in a meeting");
|
|
|
done();
|
|
|
}));
|