form_column_select.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // column_select
  2. QUnit.test( "column_select check", assert => {
  3. $('#forms').append('<hr><h1>column_select check</h1><form id="form1"></form>')
  4. var el = $('#form1')
  5. var defaults = {
  6. column_select2: ['aaa', 'bbb'],
  7. column_select3: [1, '2'],
  8. }
  9. var options = {
  10. 'aaa': 'aaa display',
  11. 'bbb': 'bbb display',
  12. 'ccc': 'ccc display',
  13. 1: '1 display',
  14. '2': '2 display',
  15. }
  16. new App.ControllerForm({
  17. el: el,
  18. model: {
  19. configure_attributes: [
  20. { name: 'column_select1', display: 'ColumnSelect1', tag: 'column_select', options: options, null: true, default: defaults['column_select1'] },
  21. { name: 'column_select2', display: 'ColumnSelect2', tag: 'column_select', options: options, null: false, default: defaults['column_select2'] },
  22. { name: 'column_select3', display: 'ColumnSelect3', tag: 'column_select', options: options, null: false, default: defaults['column_select3'] },
  23. ]
  24. },
  25. autofocus: true
  26. })
  27. var params = App.ControllerForm.params(el)
  28. var test_params = {
  29. column_select1: [],
  30. column_select2: ['aaa', 'bbb'],
  31. column_select3: ['1', '2'],
  32. }
  33. assert.deepEqual(params, test_params, 'form param check')
  34. // add and remove selections
  35. $('[data-name="column_select1"] .js-pool .js-option[data-value="bbb"]').trigger('click')
  36. params = App.ControllerForm.params(el)
  37. test_params = {
  38. column_select1: ['bbb'],
  39. column_select2: ['aaa', 'bbb'],
  40. column_select3: ['1', '2'],
  41. }
  42. assert.deepEqual(params, test_params, 'form param check')
  43. var done = assert.async();
  44. setTimeout(function() {
  45. $('[data-name="column_select1"] .js-pool .js-option[data-value="aaa"]').trigger('click')
  46. $('[data-name="column_select2"] .js-pool .js-option[data-value="1"]').trigger('click')
  47. $('[data-name="column_select2"].js-selected .js-option[data-value="aaa"]').trigger('click')
  48. $('[data-name="column_select3"] .js-pool .js-option[data-value="aaa"]').trigger('click')
  49. params = App.ControllerForm.params(el)
  50. test_params = {
  51. column_select1: ['aaa', 'bbb'],
  52. column_select2: ['1', 'bbb'],
  53. column_select3: ['1', '2', 'aaa'],
  54. }
  55. assert.deepEqual(params, test_params, 'form param check')
  56. done();
  57. }, 400);
  58. });