123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865 |
- // ticket_perform_action
- QUnit.test( "ticket_perform_action check", assert => {
- App.TicketPriority.refresh([
- {
- id: 2,
- name: '2 normal',
- active: false,
- },
- {
- id: 1,
- name: '1 low',
- active: true,
- },
- ])
- App.TicketState.refresh([
- {
- id: 1,
- name: 'new',
- active: true,
- },
- {
- id: 2,
- name: 'open',
- active: true,
- },
- {
- id: 3,
- name: 'closed',
- active: false,
- },
- ])
- $('#forms').append('<hr><h1>ticket_perform_action check</h1><form id="form1"></form>')
- var el = $('#form1')
- var defaults = {
- ticket_perform_action1: {
- 'ticket.state_id': {
- value: '2'
- }
- },
- ticket_perform_action2: {
- 'ticket.state_id': {
- value: '1'
- },
- 'ticket.priority_id': {
- value: '2'
- },
- 'notification.email': {
- body: 'some body',
- internal: 'false',
- recipient: ['ticket_owner', 'ticket_customer'],
- subject: 'some subject',
- include_attachments: 'false',
- },
- },
- ticket_perform_action3: {
- 'ticket.state_id': {
- value: '3'
- },
- }
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- {
- name: 'ticket_perform_action1',
- display: 'TicketPerformAction1',
- tag: 'ticket_perform_action',
- null: true,
- },
- {
- name: 'ticket_perform_action2',
- display: 'TicketPerformAction2',
- tag: 'ticket_perform_action',
- null: false,
- notification: true,
- },
- {
- name: 'ticket_perform_action3',
- display: 'TicketPerformAction3',
- tag: 'ticket_perform_action',
- null: true,
- notification: true,
- },
- ]
- },
- params: defaults,
- autofocus: true
- })
- var params = App.ControllerForm.params(el)
- var test_params = {
- ticket_perform_action1: {
- 'ticket.state_id': {
- value: '2'
- }
- },
- ticket_perform_action2: {
- 'notification.email': {
- body: 'some body',
- internal: 'false',
- recipient: ['ticket_owner', 'ticket_customer'],
- subject: 'some subject',
- include_attachments: 'false',
- },
- 'ticket.priority_id': {
- value: '2'
- },
- 'ticket.state_id': {
- value: '1'
- },
- },
- ticket_perform_action3: {
- 'ticket.state_id': {
- value: '3'
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check')
- // add email notification
- $('[data-attribute-name="ticket_perform_action3"] .js-add').trigger('click')
- $('[data-attribute-name="ticket_perform_action3"] .js-attributeSelector .form-control').last().val('notification.email').trigger('change')
- $('[data-attribute-name="ticket_perform_action3"] .js-setNotification [name="ticket_perform_action3::notification.email::subject"]').val('some subject').trigger('change')
- $('[data-attribute-name="ticket_perform_action3"] .js-setNotification [data-name="ticket_perform_action3::notification.email::body"]').html('some body').trigger('change')
- $('[data-attribute-name="ticket_perform_action3"] .js-setNotification .js-recipient .js-option[data-value="ticket_owner"]').trigger('click')
- params = App.ControllerForm.params(el)
- test_params = {
- ticket_perform_action1: {
- 'ticket.state_id': {
- value: '2'
- }
- },
- ticket_perform_action2: {
- 'notification.email': {
- body: 'some body',
- internal: 'false',
- recipient: ['ticket_owner', 'ticket_customer'],
- subject: 'some subject',
- include_attachments: 'false',
- },
- 'ticket.priority_id': {
- value: '2'
- },
- 'ticket.state_id': {
- value: '1'
- },
- },
- ticket_perform_action3: {
- 'notification.email': {
- body: 'some body',
- internal: 'false',
- recipient: ['ticket_owner'],
- subject: 'some subject',
- include_attachments: 'false',
- },
- 'ticket.state_id': {
- value: '3'
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check')
- // remove recipient
- $('[data-attribute-name="ticket_perform_action2"] .js-setNotification .js-recipient .js-remove.js-option[data-value="ticket_owner"]').trigger('click')
- params = App.ControllerForm.params(el)
- test_params = {
- ticket_perform_action1: {
- 'ticket.state_id': {
- value: '2'
- }
- },
- ticket_perform_action2: {
- 'notification.email': {
- body: 'some body',
- internal: 'false',
- recipient: ['ticket_customer'],
- subject: 'some subject',
- include_attachments: 'false',
- },
- 'ticket.priority_id': {
- value: '2'
- },
- 'ticket.state_id': {
- value: '1'
- },
- },
- ticket_perform_action3: {
- 'notification.email': {
- body: 'some body',
- internal: 'false',
- recipient: ['ticket_owner'],
- subject: 'some subject',
- include_attachments: 'false',
- },
- 'ticket.state_id': {
- value: '3'
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check')
- // set notification to internal
- $('[data-attribute-name="ticket_perform_action2"] .js-internal select').val('true').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- ticket_perform_action1: {
- 'ticket.state_id': {
- value: '2'
- }
- },
- ticket_perform_action2: {
- 'notification.email': {
- body: 'some body',
- internal: 'true',
- recipient: ['ticket_customer'],
- subject: 'some subject',
- include_attachments: 'false',
- },
- 'ticket.priority_id': {
- value: '2'
- },
- 'ticket.state_id': {
- value: '1'
- },
- },
- ticket_perform_action3: {
- 'notification.email': {
- body: 'some body',
- internal: 'false',
- recipient: ['ticket_owner'],
- subject: 'some subject',
- include_attachments: 'false',
- },
- 'ticket.state_id': {
- value: '3'
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check')
- // add pending time
- $('[data-attribute-name="ticket_perform_action3"] .js-add').last().trigger('click')
- var row = $('[data-attribute-name="ticket_perform_action3"] .js-filterElement').last()
- var date_string = '2010-07-15T12:00:00.000Z'
- var date_parsed = new Date(date_string) // make sure it works regardless of browser locale
- row.find('.js-attributeSelector .form-control').last().val('ticket.pending_time').trigger('change')
- row.find('.js-datepicker').val(date_parsed.toLocaleDateString()).trigger('blur')
- row.find('.js-datepicker').datepicker('setDate')
- row.find('.js-timepicker').val(date_parsed.getHours() + ':' + date_parsed.getMinutes()).trigger('blur')
- test_params = {
- ticket_perform_action1: {
- 'ticket.state_id': {
- value: '2'
- }
- },
- ticket_perform_action2: {
- 'notification.email': {
- body: 'some body',
- internal: 'true',
- recipient: ['ticket_customer'],
- subject: 'some subject',
- include_attachments: 'false',
- },
- 'ticket.priority_id': {
- value: '2'
- },
- 'ticket.state_id': {
- value: '1'
- },
- },
- ticket_perform_action3: {
- 'notification.email': {
- body: 'some body',
- internal: 'false',
- recipient: ['ticket_owner'],
- subject: 'some subject',
- include_attachments: 'false',
- },
- 'ticket.pending_time': {
- operator: 'static',
- value: date_string
- },
- 'ticket.state_id': {
- value: '3'
- }
- }
- }
- var done = assert.async()
- setTimeout(function(){
- params = App.ControllerForm.params(el)
- assert.deepEqual(params, test_params, 'form param check')
- done()
- }, 0);
- // switch pending time to relative
- row.find('.js-operator select').val('relative').trigger('change')
- row.find('.js-range').val('day').trigger('change')
- row.find('.js-value').val('10').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- ticket_perform_action1: {
- 'ticket.state_id': {
- value: '2'
- }
- },
- ticket_perform_action2: {
- 'notification.email': {
- body: 'some body',
- internal: 'true',
- recipient: ['ticket_customer'],
- subject: 'some subject',
- include_attachments: 'false',
- },
- 'ticket.priority_id': {
- value: '2'
- },
- 'ticket.state_id': {
- value: '1'
- },
- },
- ticket_perform_action3: {
- 'notification.email': {
- body: 'some body',
- internal: 'false',
- recipient: ['ticket_owner'],
- subject: 'some subject',
- include_attachments: 'false',
- },
- 'ticket.pending_time': {
- operator: 'relative',
- range: 'day',
- value: '10'
- },
- 'ticket.state_id': {
- value: '3'
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check')
- });
- // Test for backwards compatibility after issue is fixed https://github.com/zammad/zammad/issues/2782
- QUnit.test( "ticket_perform_action backwards check after issue #2782", assert => {
- $('#forms').append('<hr><h1>ticket_perform_action check</h1><form id="form2"></form>')
- var el = $('#form2')
- var defaults = {
- ticket_perform_action5: {
- 'notification.email': {
- body: 'some body',
- recipient: ['ticket_owner', 'ticket_customer'],
- subject: 'some subject',
- include_attachments: 'true',
- },
- },
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- {
- name: 'ticket_perform_action5',
- display: 'TicketPerformAction5',
- tag: 'ticket_perform_action',
- null: true,
- },
- ]
- },
- params: defaults,
- autofocus: true
- })
- var params = App.ControllerForm.params(el)
- var test_params = {
- ticket_perform_action5: {
- 'notification.email': {
- body: 'some body',
- internal: 'false',
- recipient: ['ticket_owner', 'ticket_customer'],
- subject: 'some subject',
- include_attachments: 'true',
- },
- }
- }
- assert.deepEqual(params, test_params, 'form param check')
- });
- QUnit.test( "ticket_perform_action rows manipulation", assert => {
- App.TicketPriority.refresh([
- {
- id: 2,
- name: '2 normal',
- active: false,
- },
- {
- id: 1,
- name: '1 low',
- active: true,
- },
- ])
- App.TicketState.refresh([
- {
- id: 1,
- name: 'new',
- active: true,
- },
- {
- id: 2,
- name: 'open',
- active: true,
- },
- {
- id: 3,
- name: 'closed',
- active: false,
- },
- ])
- $('#forms').append('<hr><h1>ticket_perform_action rows manipulation</h1><form id="form99"></form>')
- var el = $('#form99')
- var defaults = {
- ticket_perform_action1: {
- 'ticket.state_id': {
- value: '2'
- }
- }
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- {
- name: 'ticket_perform_action99',
- display: 'TicketPerformAction99',
- tag: 'ticket_perform_action',
- null: true,
- },
- ]
- },
- params: defaults,
- autofocus: true
- })
- assert.equal(true, true)
- var selector = '[data-attribute-name="ticket_perform_action99"] '
- $(selector + '.js-remove').trigger('click')
- assert.equal($(selector + '.js-filterElement').length, 1, 'prevents removing single initial row')
- $(selector + '.js-add').trigger('click')
- assert.equal($(selector + '.js-filterElement').length, 2, 'adds 2nd row')
- $(selector + ' .js-remove:last').trigger('click')
- assert.equal($(selector + '.js-filterElement').length, 1, 'removes 2nd row')
- $(selector + '.js-remove:last').trigger('click')
- assert.equal($(selector + ' .js-filterElement').length, 1, 'prevents removing last row')
- });
- // Test for backwards compatibility after PR https://github.com/zammad/zammad/pull/2862
- QUnit.test( "ticket_perform_action backwards check after PR#2862", assert => {
- $('#forms').append('<hr><h1>ticket_perform_action check</h1><form id="form3"></form>')
- var el = $('#form3')
- var defaults = {
- ticket_perform_action4: {
- 'ticket.pending_time': {
- value: '2010-07-15T05:00:00.000Z'
- }
- }
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- {
- name: 'ticket_perform_action4',
- display: 'TicketPerformAction4',
- tag: 'ticket_perform_action',
- null: true,
- },
- ]
- },
- params: defaults,
- autofocus: true
- })
- var params = App.ControllerForm.params(el)
- var test_params = {
- ticket_perform_action4: {
- 'ticket.pending_time': {
- operator: 'static',
- value: '2010-07-15T05:00:00.000Z'
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check')
- });
- QUnit.test( "ticket_perform_action orphan time fields", assert => {
- $('#forms').append('<hr><h1>ticket_perform_action orphan time fields</h1><form id="form4"></form>')
- var el = $('#form4')
- var defaults = {
- ticket_perform_action4: {
- 'ticket.pending_time': {
- operator: 'relative',
- value: '1'
- }
- }
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- {
- name: 'ticket_perform_action4',
- display: 'TicketPerformAction4',
- tag: 'ticket_perform_action',
- null: true,
- },
- ]
- },
- params: defaults,
- autofocus: true
- })
- // change to another attribute
- el.find('select:first').val('ticket.tags').trigger('change')
- assert.equal(el.find('.js-valueRangeSelector').length, 0)
- });
- QUnit.test( "ticket_perform_action check possible owner selection", assert => {
- $('#forms').append('<hr><h1>ticket_perform_action check possible owner selection</h1><form id="form5"></form>')
- var el = $('#form5')
- var defaults = {
- ticket_perform_action5: {
- 'ticket.owner_id': {
- pre_condition: 'not_set',
- }
- }
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- {
- name: 'ticket_perform_action5',
- display: 'TicketPerformAction5',
- tag: 'ticket_perform_action',
- null: true,
- },
- ]
- },
- params: defaults,
- autofocus: true
- })
- var params = App.ControllerForm.params(el)
- var test_params = {
- ticket_perform_action5: {
- 'ticket.owner_id': {
- pre_condition: 'not_set',
- value: '',
- value_completion: ''
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check')
- el.find('[name="ticket_perform_action5::ticket.owner_id::pre_condition"]').val('specific').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- ticket_perform_action5: {
- 'ticket.owner_id': {
- pre_condition: 'specific',
- value: '',
- value_completion: ''
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check')
- });
- QUnit.test( "ticket_perform_action check when there's no available webhook", assert => {
- $('#forms').append('<hr><h1>ticket_perform_action check when there\'s no available webhook</h1><form id="form6"></form>')
- var el = $('#form6')
- var defaults = {
- ticket_perform_action6: {
- 'notification.webhook': {
- value: undefined
- }
- }
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- {
- name: 'ticket_perform_action6',
- display: 'TicketPerformAction6',
- tag: 'ticket_perform_action',
- null: true,
- notification: true,
- },
- ]
- },
- params: defaults,
- autofocus: true
- })
- var params = App.ControllerForm.params(el)
- assert.deepEqual(params, {}, 'form param check')
- var testNoticeMessage = 'No webhook available, please create a new one or activate an existing one at "Manage > Webhook"'
- var noticeMessage = el.find('.controls.js-webhooks div').text()
- assert.equal(noticeMessage, testNoticeMessage, 'form shows message when webhook is not available')
- });
- QUnit.test( "ticket_perform_action check when there's an available webhook", assert => {
- $('#forms').append('<hr><h1>ticket_perform_action check when there\'s an available webhook</h1><form id="form7"></form>')
- var el = $('#form7')
- var defaults = {
- ticket_perform_action7: {
- 'notification.webhook': {
- webhook_id: 'c-1'
- }
- }
- }
- App.Webhook.refresh([
- {
- name: 'Webhook test',
- endpoint: 'https://target.example.com/webhook',
- active: true,
- id: 'c-1'
- }
- ], { clear: true })
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- {
- name: 'ticket_perform_action7',
- display: 'TicketPerformAction7',
- tag: 'ticket_perform_action',
- null: true,
- notification: true,
- },
- ]
- },
- params: defaults,
- autofocus: true
- })
- var params = App.ControllerForm.params(el)
- var test_params = {
- 'ticket_perform_action7': {
- 'notification.webhook': {
- 'webhook_id': 'c-1'
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check')
- var testNoticeMessage = 'No webhook available, please create a new one or activate an existing one at "Manage > Webhook"'
- var noticeMessage = el.find('.controls.js-webhooks').text()
- assert.notEqual(noticeMessage, testNoticeMessage, 'form does not show notice message when webhook is available')
- var noticeMessage = el.find('.controls.js-webhooks select option').eq(1).text()
- assert.equal(noticeMessage, 'Webhook test (https://target.example.com/webhook)', 'form shows available webhook when webhook is available')
- });
- QUnit.test( "ticket_perform_action check template attributes", assert => {
- $('#forms').append('<hr><h1>ticket_perform_action check template attributes</h1><form id="form8"></form>')
- var el = $('#form8')
- var defaults = {
- ticket_perform_action8: {
- 'article.body': {
- value: 'foobar',
- },
- 'ticket.foo': {
- value: 'bar',
- },
- },
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- {
- name: 'ticket_perform_action8',
- display: 'TicketPerformAction8',
- tag: 'ticket_perform_action',
- user_action: false,
- article_body_cc_only: true,
- sender_type: true,
- no_richtext_uploads: true,
- skip_unknown_attributes: true,
- null: true,
- },
- ],
- },
- params: defaults,
- autofocus: true,
- })
- var params = App.ControllerForm.params(el)
- var test_params = {
- 'ticket_perform_action8': {
- 'article.body': {
- value: 'foobar',
- },
- },
- }
- assert.deepEqual(params, test_params, 'form param check')
- var row = $('[data-attribute-name="ticket_perform_action8"] .js-filterElement').last()
- var select = row.find('.js-attributeSelector .form-control').first()
- var options = select.find('option').map((index, option) => option.value).toArray().sort()
- var test_options = [
- 'article.body',
- 'article.cc',
- 'ticket.customer_id',
- 'ticket.formSenderType',
- 'ticket.group_id',
- 'ticket.organization_id',
- 'ticket.owner_id',
- 'ticket.pending_time',
- 'ticket.priority_id',
- 'ticket.state_id',
- 'ticket.tags',
- 'ticket.title',
- ]
- assert.deepEqual(options, test_options, 'select options check')
- var articleBody = row.find('[data-name="ticket_perform_action8::article.body::value"]')
- assert.equal(articleBody.html(), 'foobar', 'article body text check')
- });
- QUnit.test( "ticket_perform_action allows to load data from external data source", assert => {
- var testOptions = [
- {
- value: 1,
- label: 'A',
- },
- {
- value: 2,
- label: 'B',
- },
- {
- value: 3,
- label: 'C',
- },
- ]
- App.ExternalDataSourceAjaxSelect.TEST_SEARCH_RESULT_CACHE = {
- 'Ticket+external_data_source1+*': {
- result: testOptions,
- },
- 'Ticket+external_data_source1+': {
- result: testOptions,
- },
- }
- $('#forms').append('<hr><h1>ticket_perform_action allows to load data from external data source</h1><form id="form9"></form>')
- var el = $('#form9')
- App.Ticket.configure_attributes.push({
- name: 'external_data_source1',
- display: 'ExternalDataSource1',
- tag: 'autocompletion_ajax_external_data_source',
- null: true,
- })
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- {
- name: 'ticket_perform_action6',
- display: 'TicketPerformAction6',
- tag: 'ticket_perform_action',
- null: true,
- },
- ]
- },
- params: {},
- autofocus: true
- })
- $('[data-attribute-name="ticket_perform_action6"] .js-attributeSelector .form-control')
- .last()
- .val('ticket.external_data_source1')
- .trigger('change')
- $('[data-attribute-name="ticket_perform_action6"] .js-input')
- .trigger('focus')
- .val('*')
- .trigger('input')
- var entries = $('[data-attribute-name="ticket_perform_action6"]').find('.js-optionsList li').length
- assert.equal(entries, 3, 'dropdown count')
- $('[data-attribute-name="ticket_perform_action6"]').find('.js-optionsList li:first').trigger('click')
- var params = App.ControllerForm.params(el)
- var test_params = {
- ticket_perform_action6: {
- 'ticket.external_data_source1': {
- 'value': {
- label: 'A',
- value: 1
- }
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check')
- });
|