search_overview_spec.rb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Mobile > Search', app: :mobile, authenticated_as: :user, type: :system do
  4. context 'when searching as customer', authenticated_as: :customer do
  5. let(:organization) { create(:organization) }
  6. let(:customer) { create(:customer, organization: organization) }
  7. it 'opens tickets search page by default, since customer doesn\'t have access to others' do
  8. visit '/search'
  9. expect_current_route('/search/ticket')
  10. end
  11. it 'can search tickets' do
  12. create(:ticket, title: 'test ticket', customer_id: customer.id).tap do |ticket|
  13. create(:ticket_article, ticket: ticket)
  14. end
  15. create(:ticket, title: 'other ticket', customer_id: customer.id).tap do |ticket|
  16. create(:ticket_article, ticket: ticket)
  17. end
  18. visit '/search/ticket'
  19. fill_in placeholder: 'Search…', with: 'test'
  20. wait_for_gql('apps/mobile/pages/search/graphql/queries/searchOverview.graphql')
  21. expect(page).to have_text('test ticket')
  22. expect(page).to have_no_text('other ticket')
  23. end
  24. it 'can\'t search users' do
  25. visit '/search/user'
  26. expect(page).to have_no_text('User')
  27. end
  28. it 'can\'t search organizations' do
  29. visit '/search/organization'
  30. expect(page).to have_no_text('Organization')
  31. end
  32. end
  33. context 'when searching as agent', authenticated_as: :agent do
  34. let(:organization) { create(:organization) }
  35. let(:ticket1) do
  36. create(:ticket, title: 'test ticket', organization_id: organization.id).tap do |ticket|
  37. create(:ticket_article, ticket: ticket)
  38. end
  39. end
  40. let(:ticket2) do
  41. create(:ticket, title: 'other ticket', organization_id: organization.id).tap do |ticket|
  42. create(:ticket_article, ticket: ticket)
  43. end
  44. end
  45. let(:agent) { create(:agent, organization: organization, groups: [ticket1.group, ticket2.group]) }
  46. it 'can search tickets' do
  47. visit '/search/ticket'
  48. fill_in placeholder: 'Search…', with: 'test'
  49. wait_for_gql('apps/mobile/pages/search/graphql/queries/searchOverview.graphql')
  50. expect(page).to have_text('test ticket')
  51. expect(page).to have_no_text('other ticket')
  52. end
  53. it 'can search users' do
  54. create(:customer, firstname: 'test', lastname: 'customer')
  55. create(:customer, firstname: 'other', lastname: 'customer')
  56. visit '/search/user'
  57. fill_in placeholder: 'Search…', with: 'test'
  58. wait_for_gql('apps/mobile/pages/search/graphql/queries/searchOverview.graphql')
  59. expect(page).to have_text('test customer')
  60. expect(page).to have_no_text('other customer')
  61. end
  62. it 'can search organizations' do
  63. create(:organization, name: 'test organization')
  64. create(:organization, name: 'other organization')
  65. visit '/search/organization'
  66. fill_in placeholder: 'Search…', with: 'test'
  67. wait_for_gql('apps/mobile/pages/search/graphql/queries/searchOverview.graphql')
  68. expect(page).to have_text('test organization')
  69. expect(page).to have_no_text('other organization')
  70. end
  71. end
  72. end