overview_test.rb 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. require 'test_helper'
  2. class OverviewTest < ActiveSupport::TestCase
  3. test 'overview link' do
  4. UserInfo.current_user_id = 1
  5. roles = Role.where(name: 'Agent')
  6. overview = Overview.create!(
  7. name: 'Not Shown Admin 2',
  8. roles: roles,
  9. condition: {
  10. 'ticket.state_id' => {
  11. operator: 'is',
  12. value: [1, 2, 3],
  13. },
  14. },
  15. order: {
  16. by: 'created_at',
  17. direction: 'DESC',
  18. },
  19. view: {
  20. d: %w[title customer state created_at],
  21. s: %w[number title customer state created_at],
  22. m: %w[number title customer state created_at],
  23. view_mode_default: 's',
  24. },
  25. )
  26. assert_equal(overview.link, 'not_shown_admin_2')
  27. overview.destroy!
  28. overview = Overview.create!(
  29. name: 'My assigned Tickets 2',
  30. roles: roles,
  31. condition: {
  32. 'ticket.state_id' => {
  33. operator: 'is',
  34. value: [1, 2, 3],
  35. },
  36. },
  37. order: {
  38. by: 'created_at',
  39. direction: 'DESC',
  40. },
  41. view: {
  42. d: %w[title customer state created_at],
  43. s: %w[number title customer state created_at],
  44. m: %w[number title customer state created_at],
  45. view_mode_default: 's',
  46. },
  47. )
  48. assert_equal(overview.link, 'my_assigned_tickets_2')
  49. overview.destroy!
  50. overview = Overview.create!(
  51. name: 'Übersicht',
  52. roles: roles,
  53. condition: {
  54. 'ticket.state_id' => {
  55. operator: 'is',
  56. value: [1, 2, 3],
  57. },
  58. },
  59. order: {
  60. by: 'created_at',
  61. direction: 'DESC',
  62. },
  63. view: {
  64. d: %w[title customer state created_at],
  65. s: %w[number title customer state created_at],
  66. m: %w[number title customer state created_at],
  67. view_mode_default: 's',
  68. },
  69. )
  70. assert_equal(overview.link, 'ubersicht')
  71. overview.destroy!
  72. overview = Overview.create!(
  73. name: " Übersicht \n",
  74. roles: roles,
  75. condition: {
  76. 'ticket.state_id' => {
  77. operator: 'is',
  78. value: [1, 2, 3],
  79. },
  80. },
  81. order: {
  82. by: 'created_at',
  83. direction: 'DESC',
  84. },
  85. view: {
  86. d: %w[title customer state created_at],
  87. s: %w[number title customer state created_at],
  88. m: %w[number title customer state created_at],
  89. view_mode_default: 's',
  90. },
  91. )
  92. assert_equal(overview.link, 'ubersicht')
  93. overview.destroy!
  94. overview1 = Overview.create!(
  95. name: 'Meine Übersicht',
  96. roles: roles,
  97. condition: {
  98. 'ticket.state_id' => {
  99. operator: 'is',
  100. value: [1, 2, 3],
  101. },
  102. },
  103. order: {
  104. by: 'created_at',
  105. direction: 'DESC',
  106. },
  107. view: {
  108. d: %w[title customer state created_at],
  109. s: %w[number title customer state created_at],
  110. m: %w[number title customer state created_at],
  111. view_mode_default: 's',
  112. },
  113. )
  114. assert_equal(overview1.link, 'meine_ubersicht')
  115. overview2 = Overview.create!(
  116. name: 'Meine Übersicht',
  117. roles: roles,
  118. condition: {
  119. 'ticket.state_id' => {
  120. operator: 'is',
  121. value: [1, 2, 3],
  122. },
  123. },
  124. order: {
  125. by: 'created_at',
  126. direction: 'DESC',
  127. },
  128. view: {
  129. d: %w[title customer state created_at],
  130. s: %w[number title customer state created_at],
  131. m: %w[number title customer state created_at],
  132. view_mode_default: 's',
  133. },
  134. )
  135. assert(overview2.link.start_with?('meine_ubersicht'))
  136. assert_not_equal(overview1.link, overview2.link)
  137. overview1.destroy!
  138. overview2.destroy!
  139. overview = Overview.create!(
  140. name: 'Д дФ ф',
  141. roles: roles,
  142. condition: {
  143. 'ticket.state_id' => {
  144. operator: 'is',
  145. value: [1, 2, 3],
  146. },
  147. },
  148. order: {
  149. by: 'created_at',
  150. direction: 'DESC',
  151. },
  152. view: {
  153. d: %w[title customer state created_at],
  154. s: %w[number title customer state created_at],
  155. m: %w[number title customer state created_at],
  156. view_mode_default: 's',
  157. },
  158. )
  159. assert_match(/^\d{1,3}$/, overview.link)
  160. overview.destroy!
  161. overview = Overview.create!(
  162. name: ' Д дФ ф abc ',
  163. roles: roles,
  164. condition: {
  165. 'ticket.state_id' => {
  166. operator: 'is',
  167. value: [1, 2, 3],
  168. },
  169. },
  170. order: {
  171. by: 'created_at',
  172. direction: 'DESC',
  173. },
  174. view: {
  175. d: %w[title customer state created_at],
  176. s: %w[number title customer state created_at],
  177. m: %w[number title customer state created_at],
  178. view_mode_default: 's',
  179. },
  180. )
  181. assert_equal(overview.link, 'abc')
  182. overview.destroy!
  183. overview = Overview.create!(
  184. name: 'Übersicht',
  185. link: 'my_overview',
  186. roles: roles,
  187. condition: {
  188. 'ticket.state_id' => {
  189. operator: 'is',
  190. value: [1, 2, 3],
  191. },
  192. },
  193. order: {
  194. by: 'created_at',
  195. direction: 'DESC',
  196. },
  197. view: {
  198. d: %w[title customer state created_at],
  199. s: %w[number title customer state created_at],
  200. m: %w[number title customer state created_at],
  201. view_mode_default: 's',
  202. },
  203. )
  204. assert_equal(overview.link, 'my_overview')
  205. overview.name = 'Übersicht2'
  206. overview.link = 'my_overview2'
  207. overview.save!
  208. assert_equal(overview.link, 'my_overview2')
  209. overview.destroy!
  210. end
  211. test 'same url' do
  212. UserInfo.current_user_id = 1
  213. roles = Role.where(name: 'Agent')
  214. overview1 = Overview.create!(
  215. name: 'My own assigned Tickets',
  216. roles: roles,
  217. condition: {
  218. 'ticket.state_id' => {
  219. operator: 'is',
  220. value: [1, 2, 3],
  221. },
  222. },
  223. order: {
  224. by: 'created_at',
  225. direction: 'DESC',
  226. },
  227. view: {
  228. d: %w[title customer state created_at],
  229. s: %w[number title customer state created_at],
  230. m: %w[number title customer state created_at],
  231. view_mode_default: 's',
  232. },
  233. )
  234. assert_equal(overview1.link, 'my_own_assigned_tickets')
  235. overview2 = Overview.create!(
  236. name: 'My own assigned Tickets',
  237. roles: roles,
  238. condition: {
  239. 'ticket.state_id' => {
  240. operator: 'is',
  241. value: [1, 2, 3],
  242. },
  243. },
  244. order: {
  245. by: 'created_at',
  246. direction: 'DESC',
  247. },
  248. view: {
  249. d: %w[title customer state created_at],
  250. s: %w[number title customer state created_at],
  251. m: %w[number title customer state created_at],
  252. view_mode_default: 's',
  253. },
  254. )
  255. assert_equal(overview2.link, 'my_own_assigned_tickets_1')
  256. overview3 = Overview.create!(
  257. name: 'My own assigned Tickets',
  258. roles: roles,
  259. condition: {
  260. 'ticket.state_id' => {
  261. operator: 'is',
  262. value: [1, 2, 3],
  263. },
  264. },
  265. order: {
  266. by: 'created_at',
  267. direction: 'DESC',
  268. },
  269. view: {
  270. d: %w[title customer state created_at],
  271. s: %w[number title customer state created_at],
  272. m: %w[number title customer state created_at],
  273. view_mode_default: 's',
  274. },
  275. )
  276. assert_equal(overview3.link, 'my_own_assigned_tickets_2')
  277. overview1.destroy!
  278. overview2.destroy!
  279. overview3.destroy!
  280. end
  281. test 'priority rearrangement' do
  282. UserInfo.current_user_id = 1
  283. roles = Role.where(name: 'Agent')
  284. overview1 = Overview.create!(
  285. name: 'Overview1',
  286. link: 'my_overview',
  287. roles: roles,
  288. condition: {
  289. 'ticket.state_id' => {
  290. operator: 'is',
  291. value: [1, 2, 3],
  292. },
  293. },
  294. order: {
  295. by: 'created_at',
  296. direction: 'DESC',
  297. },
  298. view: {
  299. d: %w[title customer state created_at],
  300. s: %w[number title customer state created_at],
  301. m: %w[number title customer state created_at],
  302. view_mode_default: 's',
  303. },
  304. prio: 1,
  305. )
  306. overview2 = Overview.create!(
  307. name: 'Overview2',
  308. link: 'my_overview',
  309. roles: roles,
  310. condition: {
  311. 'ticket.state_id' => {
  312. operator: 'is',
  313. value: [1, 2, 3],
  314. },
  315. },
  316. order: {
  317. by: 'created_at',
  318. direction: 'DESC',
  319. },
  320. view: {
  321. d: %w[title customer state created_at],
  322. s: %w[number title customer state created_at],
  323. m: %w[number title customer state created_at],
  324. view_mode_default: 's',
  325. },
  326. prio: 2,
  327. )
  328. overview3 = Overview.create!(
  329. name: 'Overview3',
  330. link: 'my_overview',
  331. roles: roles,
  332. condition: {
  333. 'ticket.state_id' => {
  334. operator: 'is',
  335. value: [1, 2, 3],
  336. },
  337. },
  338. order: {
  339. by: 'created_at',
  340. direction: 'DESC',
  341. },
  342. view: {
  343. d: %w[title customer state created_at],
  344. s: %w[number title customer state created_at],
  345. m: %w[number title customer state created_at],
  346. view_mode_default: 's',
  347. },
  348. prio: 3,
  349. )
  350. overview2.prio = 3
  351. overview2.save!
  352. overviews = Overview.all.order(prio: :asc).pluck(:id)
  353. assert_equal(overview1.id, overviews[0])
  354. assert_equal(overview3.id, overviews[1])
  355. assert_equal(overview2.id, overviews[2])
  356. overview1.destroy!
  357. overview2.destroy!
  358. overview3.destroy!
  359. end
  360. end