trabajo-afectivo/public/assets/tests/qunit/form_sla_times.js

108 lines
22 KiB
JavaScript
Raw Normal View History

QUnit.test("form SLA times highlights first row and sets 2:00 by default for new item", function(assert) {
$('#forms').append('<hr><h1>SLA with defaults</h1><form id="form1"></form>')
App.ObjectManagerAttribute.refresh([{"name":"number","object":"Ticket","display":"#","active":true,"editable":false,"data_type":"input","data_option":{"type":"text","readonly":1,"null":true,"maxlength":60,"width":"68px"},"screens":{"create_top":{},"edit":{}},"position":5,"id":1},{"name":"title","object":"Ticket","display":"Title","active":true,"editable":false,"data_type":"input","data_option":{"type":"text","maxlength":200,"null":false,"translate":false},"screens":{"create_top":{"-all-":{"null":false}},"edit":{}},"position":8,"id":2},{"name":"customer_id","object":"Ticket","display":"Customer","active":true,"editable":false,"data_type":"user_autocompletion","data_option":{"relation":"User","autocapitalize":false,"multiple":false,"guess":true,"null":false,"limit":200,"placeholder":"Enter Person or Organization/Company","minLengt":2,"translate":false,"permission":["ticket.agent"]},"screens":{"create_top":{"-all-":{"null":false}},"edit":{}},"position":10,"id":3},{"name":"organization_id","object":"Ticket","display":"Organization","active":true,"editable":false,"data_type":"autocompletion_ajax","data_option":{"relation":"Organization","autocapitalize":false,"multiple":false,"null":true,"translate":false,"permission":["ticket.agent"],"readonly":1},"screens":{"create_top":{"-all-":{"null":false}},"edit":{}},"position":12,"id":4},{"name":"type","object":"Ticket","display":"Type","active":false,"editable":true,"data_type":"select","data_option":{"default":"","options":{"Incident":"Incident","Problem":"Problem","Request for Change":"Request for Change"},"nulloption":true,"multiple":false,"null":true,"translate":true,"maxlength":255},"screens":{"create_middle":{"-all-":{"null":false,"item_class":"column"}},"edit":{"ticket.agent":{"null":false}}},"position":20,"id":5},{"name":"group_id","object":"Ticket","display":"Group","active":true,"editable":false,"data_type":"select","data_option":{"default":"","relation":"Group","relation_condition":{"access":"full"},"nulloption":true,"multiple":false,"null":false,"translate":false,"only_shown_if_selectable":true,"permission":["ticket.agent","ticket.customer"],"maxlength":255},"screens":{"create_middle":{"-all-":{"null":false,"item_class":"column"}},"edit":{"ticket.agent":{"null":false}}},"position":25,"id":6},{"name":"owner_id","object":"Ticket","display":"Owner","active":true,"editable":false,"data_type":"select","data_option":{"default":"","relation":"User","relation_condition":{"roles":"Agent"},"nulloption":true,"multiple":false,"null":true,"translate":false,"permission":["ticket.agent"],"maxlength":255},"screens":{"create_middle":{"-all-":{"null":true,"item_class":"column"}},"edit":{"-all-":{"null":true}}},"position":30,"id":7},{"name":"state_id","object":"Ticket","display":"State","active":true,"editable":false,"data_type":"select","data_option":{"relation":"TicketState","nulloption":true,"multiple":false,"null":false,"default":2,"translate":true,"filter":[2,1,3,4,6,7],"maxlength":255},"screens":{"create_middle":{"ticket.agent":{"null":false,"item_class":"column","filter":[2,1,3,4,7]},"ticket.customer":{"item_class":"column","nulloption":false,"null":true,"filter":[1,4],"default":1}},"edit":{"ticket.agent":{"nulloption":false,"null":false,"filter":[2,3,4,7]},"ticket.customer":{"nulloption":false,"null":true,"filter":[2,4],"default":2}}},"position":40,"id":8},{"name":"pending_time","object":"Ticket","display":"Pending till","active":true,"editable":false,"data_type":"datetime","data_option":{"future":true,"past":false,"diff":24,"null":true,"translate":true,"permission":["ticket.agent"]},"screens":{"create_middle":{"-all-":{"null":false,"item_class":"column"}},"edit":{"-all-":{"null":false}}},"position":41,"id":9},{"name":"priority_id","object":"Ticket","display":"Priority","active":true,"editable":false,"data_type":"select","data_option":{"relation":"TicketPriority","nulloption":false,"multiple":false,"null":false,"default":2,"translate":true,"maxlength":255},"screens":{"create_middle":{"ticket.agent":{"null":false,"item_class":"column"}},"edit":{"ticket.agent":{"null":false}}},"pos
var el = $('#form1')
var item = new App.Sla()
new App.ControllerForm({
el: el,
model: item.constructor,
params: item
});
var row = el.find('.sla_times tbody > tr:first')
assert.ok(row.hasClass('is-active'))
assert.equal(row.find('input[data-name=first_response_time]').val(), '02:00')
$('#forms').append('<hr><h1>SLA with empty times</h1><form id="form2"></form>')
var el = $('#form2')
var item = new App.Sla()
item.id = '123'
new App.ControllerForm({
el: el,
model: item.constructor,
params: item
});
var row = el.find('.sla_times tbody > tr:first')
assert.notOk(row.hasClass('is-active'))
assert.equal(row.find('input[data-name=first_response_time]').val(), '')
});
QUnit.test("form SLA times highlights and shows settings accordingly", function(assert) {
$('#forms').append('<hr><h1>SLA with non-first time set</h1><form id="form3"></form>')
var el = $('#form3')
var item = new App.Sla()
item.id = '123'
item.update_time = 240
new App.ControllerForm({
el: el,
model: item.constructor,
params: item
});
var firstRow = el.find('.sla_times tbody > tr:first')
var secondRow = el.find('.sla_times tbody > tr:nth-child(2)')
assert.notOk(firstRow.hasClass('is-active'))
assert.equal(firstRow.find('input[data-name=first_response_time]').val(), '')
assert.ok(secondRow.hasClass('is-active'))
assert.equal(secondRow.find('input[data-name=update_time]').val(), '04:00')
assert.equal(secondRow.find('input[name=update_type]:checked').val(), 'update')
$('#forms').append('<hr><h1>SLA with response time set</h1><form id="form3a"></form>')
var el = $('#form3a')
var item = new App.Sla()
item.id = '123'
item.response_time = 180
new App.ControllerForm({
el: el,
model: item.constructor,
params: item
});
var firstRow = el.find('.sla_times tbody > tr:first')
var secondRow = el.find('.sla_times tbody > tr:nth-child(2)')
assert.notOk(firstRow.hasClass('is-active'))
assert.equal(firstRow.find('input[data-name=first_response_time]').val(), '')
assert.ok(secondRow.hasClass('is-active'))
assert.equal(secondRow.find('input[data-name=response_time]').val(), '03:00')
assert.equal(secondRow.find('input[name=update_type]:checked').val(), 'response')
})
QUnit.test("form SLA times clears field instead of 00:00", function(assert) {
$('#forms').append('<hr><h1>SLA placeholder instead of 00:00</h1><form id="form5"></form>')
var el = $('#form5')
var item = new App.Sla()
new App.ControllerForm({
el: el,
model: item.constructor,
params: item
});
var row = el.find('.sla_times tbody > tr:nth-child(2)')
var input = row.find('input[data-name=update_time]')
input.val('asd').trigger('blur')
assert.equal(input.val(), '', 'shows placeholder')
});