Added business hours tests.

This commit is contained in:
Martin Edenhofer 2015-09-21 00:19:45 +02:00
parent dcc542ab1b
commit 50546fa2d4
7 changed files with 377 additions and 103 deletions

View file

@ -500,7 +500,7 @@ class App.ControllerForm extends App.Controller
time = new Date( Date.parse( param[key] ) )
if time is 'Invalid Datetime'
throw "Invalid Datetime #{param[key]}"
param[newKey] = time.toISOString().replace(/:\d\d\.\d\d\dZ$/, ':00Z')
param[newKey] = time.toISOString().replace(/:\d\d\.\d\d\dZ$/, ':00.000Z')
catch err
param[newKey] = "invalid #{param[key]}"
console.log('ERR', err)
@ -527,6 +527,32 @@ class App.ControllerForm extends App.Controller
for key of inputSelectObject
param[ key ] = inputSelectObject[ key ]
# data type conversion
for key of param
# get {business_hours}
if key.substr(0,16) is '{business_hours}'
newKey = key.substr(16, key.length)
if lookupForm.find("[data-name=\"#{newKey}\"]").hasClass('is-hidden')
param[newKey] = null
else if param[key]
newParams = {}
for day, value of param[key]
newParams[day] = {}
newParams[day].active = false
if value.active is 'true'
newParams[day].active = true
newParams[day].timeframes = []
if _.isArray(value.start)
for pos of value.start
newParams[day].timeframes.push [ value.start[pos], value.end[pos] ]
else
newParams[day].timeframes.push [ value.start, value.end ]
param[newKey] = newParams
else
param[newKey] = undefined
delete param[key]
#App.Log.notice 'ControllerForm', 'formParam', form, param
param

View file

@ -1,49 +1,55 @@
class App.UiElement.business_hours
@render: (attribute, params) ->
@render: (attributeOrig) ->
attribute = _.clone(attributeOrig)
attribute.nameRaw = attribute.name
attribute.name = "{business_hours}#{attribute.name}"
# Martin: our frontend doesn't create 24:00.
# you have to check second values ('till') for 00:00
# and convert them to 24:00
hours =
mon:
active: true
timeframes: [
['09:00','17:00']
]
tue:
active: true
timeframes: [
['00:00','24:00']
]
wed:
active: true
timeframes: [
['09:00','17:00']
]
thu:
active: true
timeframes: [
['09:00','12:00']
['13:00','17:00']
]
fri:
active: true
timeframes: [
['09:00','17:00']
]
sat:
active: false
timeframes: [
['10:00','14:00']
]
sun:
active: false
timeframes: [
['10:00','14:00']
]
if !attribute.value
attribute.value =
mon:
active: true
timeframes: [
['09:00','17:00']
]
tue:
active: true
timeframes: [
['00:00','22:00']
]
wed:
active: true
timeframes: [
['09:00','17:00']
]
thu:
active: true
timeframes: [
['09:00','12:00'],
['13:00','17:00']
]
fri:
active: true
timeframes: [
['09:00','17:00']
]
sat:
active: false
timeframes: [
['10:00','14:00']
]
sun:
active: false
timeframes: [
['10:00','14:00']
]
businessHours = new App.BusinessHours
hours: hours
attribute: attribute
hours: attribute.value
businessHours.render()
businessHours.el

View file

@ -79,8 +79,8 @@ class App.UiElement.ticket_selector
elementRow = $(e.target).closest('.js-filterElement')
@rebuildAttributeSelectors(item, elementRow, groupAndAttribute)
@rebuildOperater(item, elementRow, groupAndAttribute, elements)
@buildValue(item, elementRow, groupAndAttribute, elements)
@rebuildOperater(item, elementRow, groupAndAttribute, elements, undefined, attribute)
@buildValue(item, elementRow, groupAndAttribute, elements, undefined, undefined, attribute)
)
# change operator
@ -88,7 +88,7 @@ class App.UiElement.ticket_selector
groupAndAttribute = $(e.target).find('.js-attributeSelector option:selected').attr('value')
operator = $(e.target).find('option:selected').attr('value')
elementRow = $(e.target).closest('.js-filterElement')
@buildValue(item, elementRow, groupAndAttribute, elements, undefined, operator)
@buildValue(item, elementRow, groupAndAttribute, elements, undefined, operator, attribute)
)
# build inital params
@ -108,8 +108,8 @@ class App.UiElement.ticket_selector
# clone, rebuild and append
elementClone = elementFirst.clone(true)
@rebuildAttributeSelectors(item, elementClone, groupAndAttribute)
@rebuildOperater(item, elementClone, groupAndAttribute, elements, operator)
@buildValue(item, elementClone, groupAndAttribute, elements, value, operator)
@rebuildOperater(item, elementClone, groupAndAttribute, elements, operator, attribute)
@buildValue(item, elementClone, groupAndAttribute, elements, value, operator, attribute)
elementLast.after(elementClone)
# remove first dummy row
@ -169,10 +169,10 @@ class App.UiElement.ticket_selector
ticket_ids: ticket_ids
)
@buildValue: (elementFull, elementRow, groupAndAttribute, elements, value, operator) ->
@buildValue: (elementFull, elementRow, groupAndAttribute, elements, value, operator, attribute) ->
# do nothing if item already exists
name = "condition::#{groupAndAttribute}::value"
name = "#{attribute.name}::#{groupAndAttribute}::value"
return if elementRow.find("[name=\"#{name}\"]").get(0)
return if elementRow.find("[data-name=\"#{name}\"]").get(0)
@ -237,8 +237,8 @@ class App.UiElement.ticket_selector
if groupAndAttribute
elementRow.find('.js-attributeSelector select').val(groupAndAttribute)
@buildOperator: (elementFull, elementRow, groupAndAttribute, elements, current_operator) ->
selection = $("<select class=\"form-control\" name=\"condition::#{groupAndAttribute}::operator\"></select>")
@buildOperator: (elementFull, elementRow, groupAndAttribute, elements, current_operator, attribute) ->
selection = $("<select class=\"form-control\" name=\"#{attribute.name}::#{groupAndAttribute}::operator\"></select>")
attributeConfig = elements[groupAndAttribute]
if attributeConfig.operator
@ -250,15 +250,15 @@ class App.UiElement.ticket_selector
selection.append("<option value=\"#{operator}\" #{selected}>#{operatorName}</option>")
selection
@rebuildOperater: (elementFull, elementRow, groupAndAttribute, elements, current_operator) ->
@rebuildOperater: (elementFull, elementRow, groupAndAttribute, elements, current_operator, attribute) ->
return if !groupAndAttribute
# do nothing if item already exists
name = "condition::#{groupAndAttribute}::operator"
name = "#{attribute.name}::#{groupAndAttribute}::operator"
return if elementRow.find("[name=\"#{name}\"]").get(0)
# render new operator
operator = @buildOperator(elementFull, elementRow, groupAndAttribute, elements, current_operator)
operator = @buildOperator(elementFull, elementRow, groupAndAttribute, elements, current_operator, attribute)
elementRow.find('.js-operator select').replaceWith(operator)
@humanText: (condition) ->

View file

@ -24,6 +24,7 @@ class App.BusinessHours extends Spine.Controller
@updateMaxTimeframes()
html = App.view('generic/business_hours')
attribute: @attribute
days: @days
hours: @options.hours
maxTimeframes: @maxTimeframes
@ -71,7 +72,8 @@ class App.BusinessHours extends Spine.Controller
validate: =>
for day, hours of @options.hours
break if not hours.active
break if !hours.active
break if !hours.timeframes
# edge case: full day
if hours.timeframes[0][0] is '00:00' and hours.timeframes[hours.timeframes.length - 1][1] is '00:00'

View file

@ -4,7 +4,7 @@
<th style="text-align: center">
<label class="day-name">
<span class="checkbox-replacement checkbox-replacement--inline">
<input class="js-toggle-day" data-target="<%- id %>" type="checkbox"<%- ' checked' if @hours[id].active %>>
<input class="js-toggle-day" name="<%= @attribute.name %>::<%- id %>::active" value="true" data-target="<%- id %>" type="checkbox"<%- ' checked' if @hours[id].active %>>
<%- @Icon('checkbox', 'icon-unchecked') %>
<%- @Icon('checkbox-checked', 'icon-checked') %>
</span>
@ -19,9 +19,9 @@
<% if @hours[id].timeframes[slot]: %>
<td data-day="<%- id %>" data-slot="<%- slot %>" class="form-group day-time<%- ' is-active' if @hours[id].active %>">
<label for="<%- id %>_start_time">from</label>
<input type="text" id="<%- id %>_start_time" value="<%- @hours[id].timeframes[slot][0] %>" data-day="<%- id %>" data-slot="<%- slot %>" data-i="0" class="form-control form-control--small time js-time">
<input type="text" id="<%- id %>_start_time" name="<%= @attribute.name %>::<%- id %>::start" value="<%- @hours[id].timeframes[slot][0] %>" data-day="<%- id %>" data-slot="<%- slot %>" data-i="0" class="form-control form-control--small time js-time">
<label for="monday_end_time">till</label>
<input type="text" id="monday_end_time" value="<%- @hours[id].timeframes[slot][1] %>" data-day="<%- id %>" data-slot="<%- slot %>" data-i="1" class="form-control form-control--small time js-time">
<input type="text" id="monday_end_time" name="<%= @attribute.name %>::<%- id %>::end" value="<%- @hours[id].timeframes[slot][1] %>" data-day="<%- id %>" data-slot="<%- slot %>" data-i="1" class="form-control form-control--small time js-time">
<% else: %>
<td class="empty-cell">
<% end %>

View file

@ -1,6 +1,6 @@
// form
test( "form simple checks", function() {
test( 'form checks', function() {
App.TicketPriority.refresh( [
{
@ -33,55 +33,254 @@ test( "form simple checks", function() {
},
] )
// timeplan
$('#forms').append('<hr><h1>form time check</h1><form id="form1"></form>')
var el = $('#form1')
var defaults = {
times: {
days: ['mon', 'wed'],
hours: [2],
working_hours: {
mon: {
active: true,
timeframes: [
['09:00','17:00']
]
},
tue: {
active: true,
timeframes: [
['00:00','22:00']
]
},
wed: {
active: true,
timeframes: [
['09:00','17:00']
]
},
thu: {
active: true,
timeframes: [
['09:00','12:00'],
['13:00','17:00']
]
},
fri: {
active: true,
timeframes: [
['09:00','17:00']
]
},
sat: {
active: false,
timeframes: [
['10:00','14:00']
]
},
sun: {
active: false,
timeframes: [
['10:00','14:00']
]
},
},
first_response_time: 150,
solution_time: '',
update_time: 45,
conditions: {
'tickets.title': 'some title',
'tickets.priority_id': [1,2,3],
'ticket.title': {
operator: 'contains',
value: 'some title',
},
'ticket.priority_id': {
operator: 'is',
value: [1,2,3],
},
'ticket.created_at': {
operator: 'before (absolute)',
value: '2015-09-20T03:41:00.000Z',
},
},
executions: {
'tickets.title': 'some title new',
'tickets.priority_id': 3,
'ticket.title': {
value: 'some title new',
},
'ticket.priority_id': {
value: 3,
},
},
}
new App.ControllerForm({
el: el,
model: {
configure_attributes: [
{ name: 'times', display: 'Times', tag: 'timeplan', null: true, default: defaults['times'] },
{ name: 'conditions', display: 'Conditions', tag: 'ticket_attribute_selection', null: true, default: defaults['conditions'] },
{ name: 'executions', display: 'Executions', tag: 'ticket_attribute_set', null: true, default: defaults['executions'] },
{ name: 'escalation_times', display: 'Times', tag: 'sla_times', null: true },
{ name: 'working_hours', display: 'Hours', tag: 'business_hours', null: true },
{ name: 'conditions', display: 'Conditions', tag: 'ticket_selector', null: true },
{ name: 'executions', display: 'Executions', tag: 'ticket_perform_action', null: true },
]
},
params: defaults,
autofocus: true
});
deepEqual( el.find('[name="times::days"]').val(), ['mon', 'wed'], 'check times::days value')
equal( el.find('[name="times::hours"]').val(), 2, 'check times::hours value')
equal( el.find('[name="times::minutes"]').val(), null, 'check times::minutes value')
var params = App.ControllerForm.params( el )
var test_params = {
times: {
days: ['mon', 'wed'],
hours: '2',
},
first_response_time: '150',
first_response_time_in_text: '02:30',
solution_time: '',
solution_time_in_text: '',
update_time: '45',
update_time_in_text: '00:45',
conditions: {
'tickets.title': 'some title',
'tickets.priority_id': ['1','3'],
'ticket.title': {
operator: 'contains',
value: 'some title',
},
'ticket.priority_id': {
operator: 'is',
value: ['1', '3'],
},
'ticket.created_at': {
operator: 'before (absolute)',
value: '2015-09-20T03:41:00.000Z',
},
},
executions: {
'tickets.title': 'some title new',
'tickets.priority_id': '3',
'ticket.title': {
value: 'some title new',
},
'ticket.priority_id': {
value: '3',
},
},
working_hours: {
mon: {
active: true,
timeframes: [
['09:00','17:00']
]
},
tue: {
active: true,
timeframes: [
['00:00','22:00']
]
},
wed: {
active: true,
timeframes: [
['09:00','17:00']
]
},
thu: {
active: true,
timeframes: [
['09:00','12:00'],
['13:00','17:00']
]
},
fri: {
active: true,
timeframes: [
['09:00','17:00']
]
},
sat: {
active: false,
timeframes: [
['10:00','14:00']
]
},
sun: {
active: false,
timeframes: [
['10:00','14:00']
]
},
},
}
deepEqual( params, test_params, 'form param check' );
// change sla times
el.find('[name="first_response_time_in_text"]').val('0:30').trigger('blur')
el.find('#update_time').click()
// change selector
el.find('[name="conditions::ticket.priority_id::value"]').closest('.js-filterElement').find('.js-remove').click()
el.find('[name="executions::ticket.title::value"]').closest('.js-filterElement').find('.js-remove').click()
var params = App.ControllerForm.params( el )
var test_params = {
working_hours: {
mon: {
active: true,
timeframes: [
['09:00','17:00']
]
},
tue: {
active: true,
timeframes: [
['00:00','22:00']
]
},
wed: {
active: true,
timeframes: [
['09:00','17:00']
]
},
thu: {
active: true,
timeframes: [
['09:00','12:00'],
['13:00','17:00']
]
},
fri: {
active: true,
timeframes: [
['09:00','17:00']
]
},
sat: {
active: false,
timeframes: [
['10:00','14:00']
]
},
sun: {
active: false,
timeframes: [
['10:00','14:00']
]
},
},
first_response_time: '30',
first_response_time_in_text: '00:30',
solution_time: '',
solution_time_in_text: '',
update_time: '',
update_time_in_text: '',
conditions: {
'ticket.title': {
operator: 'contains',
value: 'some title',
},
'ticket.created_at': {
operator: 'before (absolute)',
value: '2015-09-20T03:41:00.000Z',
},
},
executions: {
'ticket.priority_id': {
value: '3',
},
},
}
deepEqual( params, test_params, 'form param check' );
//deepEqual( el.find('[name="times::days"]').val(), ['mon', 'wed'], 'check times::days value')
//equal( el.find('[name="times::hours"]').val(), 2, 'check times::hours value')
//equal( el.find('[name="times::minutes"]').val(), null, 'check times::minutes value')
});

View file

@ -685,14 +685,29 @@ test( "form postmaster filter", function() {
var defaults = {
input2: 'some name',
match: {
from: 'some@address',
subject: 'some subject',
from: {
operator: 'contains',
value: 'some@address',
},
subject: {
operator: 'contains',
value: 'some subject',
},
},
set: {
'x-zammad-ticket-owner': 'owner',
'x-zammad-ticket-customer': 'customer',
'x-zammad-ticket-priority_id': 2,
'x-zammad-ticket-group_id': 1,
'x-zammad-ticket-customer': {
value: 'customer'
},
'x-zammad-ticket-group_id': {
value: '1'
},
'x-zammad-ticket-owner': {
value: 'owner',
value_completion: ''
},
'x-zammad-ticket-priority_id': {
value: '1'
}
},
}
new App.ControllerForm({
@ -709,35 +724,61 @@ test( "form postmaster filter", function() {
});
params = App.ControllerForm.params( el )
test_params = {
input1: "some not used default",
input2: "some name",
input1: 'some not used default',
input2: 'some name',
match: {
from: 'some@address',
subject: 'some subject',
from: {
operator: 'contains',
value: 'some@address'
},
subject: {
operator: 'contains',
value: 'some subject'
}
},
set: {
'x-zammad-ticket-owner': 'owner',
'x-zammad-ticket-customer': 'customer',
'x-zammad-ticket-priority_id': '2',
'x-zammad-ticket-group_id': '1',
'x-zammad-ticket-customer': {
value: 'customer'
},
'x-zammad-ticket-group_id': {
value: '1'
},
'x-zammad-ticket-owner': {
value: 'owner',
value_completion: ''
},
'x-zammad-ticket-priority_id': {
value: '1'
}
},
};
deepEqual( params, test_params, 'form param check' );
el.find('[name="set::x-zammad-ticket-priority_id"]').closest('.form-group').find('.remove').click()
el.find('[name="set::x-zammad-ticket-customer"]').closest('.form-group').find('.remove').click()
el.find('[name="set::x-zammad-ticket-priority_id::value"]').closest('.js-filterElement').find('.js-remove').click()
el.find('[name="set::x-zammad-ticket-customer::value"]').closest('.js-filterElement').find('.js-remove').click()
App.Delay.set( function() {
test( "form param check after remove click", function() {
params = App.ControllerForm.params( el )
test_params = {
input1: "some not used default",
input2: "some name",
input1: 'some not used default',
input2: 'some name',
match: {
from: 'some@address',
subject: 'some subject',
from: {
operator: 'contains',
value: 'some@address'
},
subject: {
operator: 'contains',
value: 'some subject'
}
},
set: {
'x-zammad-ticket-owner': 'owner',
'x-zammad-ticket-group_id': '1',
'x-zammad-ticket-owner': {
value: 'owner',
value_completion: ''
},
'x-zammad-ticket-group_id': {
value: '1'
},
},
};
deepEqual( params, test_params, 'form param check' );
@ -765,8 +806,8 @@ test( "form selector", function() {
params: defaults,
});
test_params = {
input1: "some not used default33",
input2: "some name66",
input1: 'some not used default33',
input2: 'some name66',
};
params = App.ControllerForm.params( el )
deepEqual( params, test_params, 'form param check via $("#form")' );