123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- require 'rails_helper'
- RSpec.describe Service::Translation::Search do
- describe '#execute' do
- let(:locale) { 'en-us' }
- let(:filter_locale) { locale }
- let(:query) { nil }
- let(:translation_search_service) { described_class.new(locale: filter_locale, query:) }
- context 'when query is nil', :aggregate_failures do
- it 'return default list' do
- expect(translation_search_service.execute[:items].count).to eq(150)
- expect(translation_search_service.execute[:total_count]).to be > 150
- end
- it 'includes already translated suggestions with translation item' do
- result = translation_search_service.execute
- priority_name = Ticket::Priority.first.name
- first_priority_translation = result[:items].select { |item| item[:source].eql?(priority_name) }
- expect(first_priority_translation.length).to be(1)
- expect(first_priority_translation[0][:id]).to eq(Translation.find_source(locale, priority_name).id)
- end
- end
- context 'with specific query' do
- let(:query) { SecureRandom.uuid }
- before do
- create(:translation, locale: locale, source: "Other #{query}", target: "Andere #{query}")
- create(:translation, locale: locale, source: "Example #{query}", target: "Ein #{query}", is_synchronized_from_codebase: true)
- end
- context 'with not matching locale' do
- let(:filter_locale) { 'de-de' }
- it 'returns no result' do
- expect(translation_search_service.execute[:items].count).to eq(0)
- end
- end
- context 'when case sensitive should match' do
- let(:query) { Translation.last.source.downcase }
- it 'returns also with case insensitive a result' do
- expect(translation_search_service.execute[:items].count).to eq(2)
- end
- end
- context 'with matching query' do
- shared_examples 'returns filtered result' do |factory_name, attribute, count|
- before do
- create(factory_name, attribute => "#{factory_name} #{query}")
- end
- it 'returns filtered result' do
- expect(translation_search_service.execute[:items].count).to eq(count)
- end
- end
- context 'with custom priority' do
- it_behaves_like 'returns filtered result', :ticket_priority, 'name', 2
- end
- context 'with custom state' do
- it_behaves_like 'returns filtered result', :ticket_state, 'name', 2
- end
- context 'with custom overview' do
- it_behaves_like 'returns filtered result', :overview, 'name', 2
- end
- context 'with custom macro' do
- it_behaves_like 'returns filtered result', :macro, 'name', 2
- end
- context 'with custom object attribute' do
- before do
- create(:object_manager_attribute_select, display: "Select #{query}", data_option_options: [{ name: query, value: query }])
- end
- it 'returns filtered result' do
- expect(translation_search_service.execute[:items].count).to eq(3)
- end
- context 'with not translatabale option' do
- before do
- create(:object_manager_attribute_select, display: "Select2 #{query}", data_option: {
- default: '',
- options: [{ name: "item #{query}", value: "item #{query}" }],
- translate: false
- })
- end
- it 'returns filtered result' do
- expect(translation_search_service.execute[:items].count).to eq(4)
- end
- end
- end
- context 'with multiple suggestion with the same name' do
- before do
- create(:ticket_priority, name: "high #{query}")
- create(:object_manager_attribute_select, display: "high #{query}")
- end
- it 'returns filtered result without duplicate entries' do
- expect(translation_search_service.execute[:items].count).to eq(2)
- end
- end
- end
- end
- end
- end
|