123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- require 'test_helper'
- class OverviewTest < ActiveSupport::TestCase
- test 'overview link' do
- UserInfo.current_user_id = 1
- roles = Role.where(name: 'Agent')
- overview = Overview.create!(
- name: 'Not Shown Admin 2',
- roles: roles,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- assert_equal(overview.link, 'not_shown_admin_2')
- overview.destroy!
- overview = Overview.create!(
- name: 'My assigned Tickets 2',
- roles: roles,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- assert_equal(overview.link, 'my_assigned_tickets_2')
- overview.destroy!
- overview = Overview.create!(
- name: 'Übersicht',
- roles: roles,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- assert_equal(overview.link, 'ubersicht')
- overview.destroy!
- overview = Overview.create!(
- name: " Übersicht \n",
- roles: roles,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- assert_equal(overview.link, 'ubersicht')
- overview.destroy!
- overview1 = Overview.create!(
- name: 'Meine Übersicht',
- roles: roles,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- assert_equal(overview1.link, 'meine_ubersicht')
- overview2 = Overview.create!(
- name: 'Meine Übersicht',
- roles: roles,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- assert(overview2.link.start_with?('meine_ubersicht'))
- assert_not_equal(overview1.link, overview2.link)
- overview1.destroy!
- overview2.destroy!
- overview = Overview.create!(
- name: 'Д дФ ф',
- roles: roles,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- assert_match(/^\d{1,3}$/, overview.link)
- overview.destroy!
- overview = Overview.create!(
- name: ' Д дФ ф abc ',
- roles: roles,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- assert_equal(overview.link, 'abc')
- overview.destroy!
- overview = Overview.create!(
- name: 'Übersicht',
- link: 'my_overview',
- roles: roles,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- assert_equal(overview.link, 'my_overview')
- overview.name = 'Übersicht2'
- overview.link = 'my_overview2'
- overview.save!
- assert_equal(overview.link, 'my_overview2')
- overview.destroy!
- end
- test 'same url' do
- UserInfo.current_user_id = 1
- roles = Role.where(name: 'Agent')
- overview1 = Overview.create!(
- name: 'My own assigned Tickets',
- roles: roles,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- assert_equal(overview1.link, 'my_own_assigned_tickets')
- overview2 = Overview.create!(
- name: 'My own assigned Tickets',
- roles: roles,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- assert_equal(overview2.link, 'my_own_assigned_tickets_1')
- overview3 = Overview.create!(
- name: 'My own assigned Tickets',
- roles: roles,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- assert_equal(overview3.link, 'my_own_assigned_tickets_2')
- overview1.destroy!
- overview2.destroy!
- overview3.destroy!
- end
- test 'priority rearrangement' do
- UserInfo.current_user_id = 1
- roles = Role.where(name: 'Agent')
- overview1 = Overview.create!(
- name: 'Overview1',
- link: 'my_overview',
- roles: roles,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- prio: 1,
- )
- overview2 = Overview.create!(
- name: 'Overview2',
- link: 'my_overview',
- roles: roles,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- prio: 2,
- )
- overview3 = Overview.create!(
- name: 'Overview3',
- link: 'my_overview',
- roles: roles,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- prio: 3,
- )
- overview2.prio = 3
- overview2.save!
- overviews = Overview.all.order(prio: :asc).pluck(:id)
- assert_equal(overview1.id, overviews[0])
- assert_equal(overview3.id, overviews[1])
- assert_equal(overview2.id, overviews[2])
- overview1.destroy!
- overview2.destroy!
- overview3.destroy!
- end
- end
|