Files
odoo_source/addons/mail/static/tests/models/timer_tests.js
T
Alexandre Kühn 5f1d32f3fb [IMP] mail, im_livechat: 'is typing...' indicator on mail channels
With this commit, most threads show an indicator when a member is typing
something. e.g.

	"Mitchell Stephens is typing..."

Supported threads:

	- DM
	- (public & private) channels
	- Livechat (Website & Backend)

Unsupported threads:

	- mailboxes (e.g. 'Inbox')
	- document thread (= 'Chatter')
	- support channel (with `im_support` module)

Some technical details:

	- This is a mix between 'start'/'stop' and 'regular notify' strategies.
	- On typing text in composer: notify 'start typing' to all members of
	  thread.
	- On clearing text in composer: notify 'stop typing' to all members of
	  thread.
	- A member can only notify once every 2.5 seconds to the server when he
	  starts or stops typing something (throttled, buffered notify call).
	- On receiving a message from someone that is typing: determine that he is
	  no longer typing.
	- On non-empty and unchanged composer text for 5.0 seconds: automatically
	  notifies all members of thread that he is no longer typing anything.
	  (This is like a 'soft / cooperative sender' timeout).
	- On non-receiving a typing notification of someone after 60 seconds:
	  determine that he is not longer typing something (This is like a
	  'hard / receiver assumption' timeout).
	- When some types for more than 50 seconds straight: notify that he is
	  still typing something (again and again every 50 seconds).
	- When two or more people are typing something (Multi-User channels), it
	  displays at most 2 typing users (ordering rule: longer typers first):

	  	"Mitchell Stephens, Marc Brown and more are typing..."

	- Timing summary:

		- Usually 2.5 seconds uncertainty.
    	- Up to 5.0 seconds uncertainty on typer inactivity.
    	- Up to 60 seconds uncertainty on typer page reload / browser tab
    	  closed / etc.

Future Improvements:

	- Detect page reload or browser tab close with loose of longpolling
	  connection

Task-ID 28188
2018-08-13 14:17:40 +02:00

89 lines
1.9 KiB
JavaScript

odoo.define('mail.model.TimerTests', function (require) {
"use strict";
var Timer = require('mail.model.Timer');
QUnit.module('mail', {}, function () {
QUnit.module('model', {}, function () {
QUnit.module('Timer');
QUnit.test('start()', function (assert) {
var done = assert.async();
assert.expect(2);
var def = $.Deferred();
var func = function () {
def.resolve();
};
var t = new Timer({
duration: 0,
onTimeout: func,
});
assert.verifySteps([], "should not have called the function");
t.start();
def.then(function () {
assert.ok(true, "should have called the function");
done();
});
});
QUnit.test('clear()', function (assert) {
var done = assert.async();
assert.expect(1);
var func = function () {
assert.step('function_called');
};
var t = new Timer({
duration: 0,
onTimeout: func,
});
t.start();
t.clear();
// Called after timer timeout
setTimeout(function () {
assert.verifySteps([], "should not have called the function");
done();
}, 0);
});
QUnit.test('reset()', function (assert) {
var done = assert.async();
assert.expect(4);
var def = $.Deferred();
var func = function () {
assert.step('function_called');
};
var t = new Timer({
duration: 0,
onTimeout: func,
});
t.start();
// Called after 1st timer timeout
setTimeout(function () {
assert.verifySteps(['function_called'], "should have called the function once");
t.reset();
// Called after 2nd timer timeout
setTimeout(function () {
def.resolve();
}, 0);
}, 0);
def.then(function () {
assert.verifySteps(['function_called', 'function_called'],
"should have called the function twice (2nd time from reset)");
done();
});
});
});
});
});