Added multiple greetings. Improved tests.

This commit is contained in:
Martin Edenhofer 2015-12-07 11:41:12 +01:00
parent fab440e219
commit af944eea2f
6 changed files with 149 additions and 43 deletions

View file

@ -278,7 +278,9 @@ class ChatWindow extends App.Controller
if preferences.chat && preferences.chat.phrase
phrases = preferences.chat.phrase[@session.chat_id]
if phrases
@input.html(phrases)
phrasesArray = phrases.split(';')
phrase = phrasesArray[_.random(0, phrasesArray.length-1)]
@input.html(phrase)
@sendMessage()
focus: =>

View file

@ -2,7 +2,7 @@
<thead>
<tr>
<th><%- @T('Topic') %>
<th width="100%"><%- @T('Greeting') %>
<th width="100%"><%- @T('Greeting') %> (<%- @T('Separate multiple values by ;') %>)
<th><%- @T('Enabled') %>
</th></tr>
</thead>

View file

@ -85,15 +85,7 @@ do($ = window.jQuery, window) ->
for key, value of params
@options[key] = value
detectHost: ->
protocol = 'ws://'
if window.location.protocol is 'https:'
protocol = 'wss://'
@options.host = "#{ protocol }#{ scriptHost }/ws"
connect: =>
@detectHost() if !@options.host
@log.debug "Connecting to #{@options.host}"
@ws = new window.WebSocket("#{@options.host}")
@ws.onopen = (e) =>
@ -232,6 +224,9 @@ do($ = window.jQuery, window) ->
@options.lang = @options.lang.replace(/-.+?$/, '') # replace "-xx" of xx-xx
@log.debug "lang: #{@options.lang}"
# detect host
@detectHost() if !@options.host
@loadCss()
@io = new Io(@options)
@ -543,7 +538,6 @@ do($ = window.jQuery, window) ->
# delay initial queue position, show connecting first
show = =>
@onQueue data
console.log('onQueueScreen')
@waitingListTimeout.start()
if @initialQueueDelay && !@onInitialQueueDelayId
@ -624,19 +618,19 @@ do($ = window.jQuery, window) ->
scrollToBottom: ->
@el.find('.zammad-chat-body').scrollTop($('.zammad-chat-body').prop('scrollHeight'))
detectHost: ->
protocol = 'ws://'
if window.location.protocol is 'https:'
protocol = 'wss://'
@options.host = "#{ protocol }#{ scriptHost }/ws"
destroy: (params = {}) =>
@log.debug 'destroy widget'
console.log('el', @el)
if params.hide
if @el
@el.remove()
# stop all timer
@waitingListTimeout.stop()
@inactiveTimeout.stop()
@idleTimeout.stop()
@wsReconnectStop()
# stop ws connection
@io.close()
wsReconnectStart: =>
@ -732,6 +726,12 @@ do($ = window.jQuery, window) ->
.attr('data-status', state)
.text @T(capitalizedState)
detectHost: ->
protocol = 'ws://'
if window.location.protocol is 'https:'
protocol = 'wss://'
@options.host = "#{ protocol }#{ scriptHost }/ws"
loadCss: ->
return if !@options.cssAutoload
url = @options.cssUrl

View file

@ -159,19 +159,7 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
return results;
};
Io.prototype.detectHost = function() {
var protocol;
protocol = 'ws://';
if (window.location.protocol === 'https:') {
protocol = 'wss://';
}
return this.options.host = "" + protocol + scriptHost + "/ws";
};
Io.prototype.connect = function() {
if (!this.options.host) {
this.detectHost();
}
this.log.debug("Connecting to " + this.options.host);
this.ws = new window.WebSocket("" + this.options.host);
this.ws.onopen = (function(_this) {
@ -398,6 +386,9 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
this.options.lang = this.options.lang.replace(/-.+?$/, '');
this.log.debug("lang: " + this.options.lang);
}
if (!this.options.host) {
this.detectHost();
}
this.loadCss();
this.io = new Io(this.options);
this.io.set({
@ -749,7 +740,6 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
show = (function(_this) {
return function() {
_this.onQueue(data);
console.log('onQueueScreen');
return _this.waitingListTimeout.start();
};
})(this);
@ -837,26 +827,19 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
return this.el.find('.zammad-chat-body').scrollTop($('.zammad-chat-body').prop('scrollHeight'));
};
ZammadChat.prototype.detectHost = function() {
var protocol;
protocol = 'ws://';
if (window.location.protocol === 'https:') {
protocol = 'wss://';
}
return this.options.host = "" + protocol + scriptHost + "/ws";
};
ZammadChat.prototype.destroy = function(params) {
if (params == null) {
params = {};
}
this.log.debug('destroy widget');
console.log('el', this.el);
if (params.hide) {
if (this.el) {
this.el.remove();
}
}
this.waitingListTimeout.stop();
this.inactiveTimeout.stop();
this.idleTimeout.stop();
this.wsReconnectStop();
return this.io.close();
};
@ -967,6 +950,15 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
return this.el.find('.zammad-chat-agent-status').attr('data-status', state).text(this.T(capitalizedState));
};
ZammadChat.prototype.detectHost = function() {
var protocol;
protocol = 'ws://';
if (window.location.protocol === 'https:') {
protocol = 'wss://';
}
return this.options.host = "" + protocol + scriptHost + "/ws";
};
ZammadChat.prototype.loadCss = function() {
var newSS, styles, url;
if (!this.options.cssAutoload) {

File diff suppressed because one or more lines are too long

View file

@ -389,6 +389,118 @@ class ChatTest < TestCase
)
end
def test_basic_usecase3
agent = browser_instance
login(
browser: agent,
username: 'master@example.com',
password: 'test',
url: browser_url,
)
tasks_close_all(
browser: agent,
)
click(
browser: agent,
css: 'a[href="#customer_chat"]',
)
agent.find_elements( { css: '.active .chat-window .js-close' } ).each(&:click)
# set chat preferences
click(
browser: agent,
css: '.active .js-settings',
)
set(
browser: agent,
css: '.modal [name="chat::phrase::1"]',
value: 'Hi Stranger!;My Greeting',
)
click(
browser: agent,
css: '.modal .js-submit',
)
customer = browser_instance
location(
browser: customer,
url: "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}",
)
watch_for(
browser: customer,
css: '.zammad-chat',
timeout: 5,
)
click(
browser: customer,
css: '.js-chat-open',
)
exists(
browser: customer,
css: '.zammad-chat-is-shown',
)
watch_for(
browser: agent,
css: '.active .js-badgeWaitingCustomers',
value: '1',
)
click(
browser: agent,
css: '.active .js-acceptChat',
)
watch_for(
browser: customer,
css: '.zammad-chat',
value: 'Hi Stranger|My Greeting',
)
watch_for(
browser: customer,
css: '.zammad-chat .zammad-chat-agent-status',
value: 'online',
)
set(
browser: agent,
css: '.active .chat-window .js-customerChatInput',
value: 'my name is me',
)
click(
browser: agent,
css: '.active .chat-window .js-send',
)
watch_for(
browser: customer,
css: '.zammad-chat',
value: 'my name is me',
)
set(
browser: customer,
css: '.zammad-chat .zammad-chat-input',
value: 'my name is customer',
)
click(
browser: customer,
css: '.zammad-chat .zammad-chat-send',
)
watch_for(
browser: agent,
css: '.active .chat-window',
value: 'my name is customer',
)
click(
browser: agent,
css: '.active .chat-window .js-customerChatInput',
)
click(
browser: customer,
css: '.js-chat-close',
)
watch_for(
browser: agent,
css: '.active .chat-window',
value: 'has left the conversation',
)
end
def test_timeouts
customer = browser_instance
location(