Skip to content

Commit

Permalink
Maintenance: Stabilize user history test.
Browse files Browse the repository at this point in the history
(cherry picked from commit ccc6d36)
  • Loading branch information
dvuckovic authored and mgruner committed Jun 19, 2023
1 parent 5f49be3 commit 569749e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 42 deletions.
48 changes: 27 additions & 21 deletions spec/system/ticket/history_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,55 @@
require 'rails_helper'

RSpec.describe 'Ticket history', time_zone: 'Europe/London', type: :system do
let(:group) { create(:group) }
let(:ticket) { create(:ticket, group: group) }
let(:group) { create(:group) }
let(:ticket) { create(:ticket, group: group) }

context 'with German locale', authenticated_as: :admin_de do
context 'with German locale', authenticated_as: :authenticate do
let(:admin_de) { create(:admin, :groupable, preferences: { locale: 'de-de' }, group: group) }

before do
def authenticate
Time.use_zone('UTC') do
freeze_time

travel_to DateTime.parse('2021-01-22 13:40:00 UTC')
travel_to DateTime.parse('2021-01-22 13:40: UTC')
current_time = Time.current
ticket.update(title: 'New Ticket Title')
ticket_article = create(:ticket_article, ticket: ticket, internal: true)
ticket.update! state: Ticket::State.lookup(name: 'open')
ticket.update! last_owner_update_at: current_time
ticket.update! priority: Ticket::Priority.lookup(name: '1 low')
ticket.update! last_contact_at: current_time
ticket.update! last_contact_customer_at: current_time
ticket.update! last_contact_agent_at: current_time
ticket.update!(
title: 'New Ticket Title',
state: Ticket::State.lookup(name: 'open'),
last_owner_update_at: current_time,
priority: Ticket::Priority.lookup(name: '1 low'),
last_contact_at: current_time,
last_contact_customer_at: current_time,
last_contact_agent_at: current_time,
)
ticket_article.update! internal: false

travel_to DateTime.parse('2021-04-06 23:30:00 UTC')
current_time = Time.current
ticket.update! state: Ticket::State.lookup(name: 'pending close')
ticket.update! priority: Ticket::Priority.lookup(name: '3 high')
ticket.update!(
state: Ticket::State.lookup(name: 'pending close'),
priority: Ticket::Priority.lookup(name: '3 high'),
last_contact_at: current_time,
last_contact_customer_at: current_time,
last_contact_agent_at: current_time,
pending_time: current_time,
first_response_escalation_at: current_time,
)
ticket_article.update! internal: true
ticket.update! last_contact_at: current_time
ticket.update! last_contact_customer_at: current_time
ticket.update! last_contact_agent_at: current_time
ticket.update! pending_time: current_time
ticket.update! first_response_escalation_at: current_time

travel_back
end

admin_de
end

before do
visit '/'

# Suppress the modal dialog that invites to contributions for translations that are < 90% as this breaks the tests for de-de.
page.evaluate_script "App.LocalStorage.set('translation_support_no', true, App.Session.get('id'))"

refresh

visit "#ticket/zoom/#{ticket.id}"
find('[data-tab="ticket"] .js-actions').click
click('[data-type="ticket-history"]')
Expand Down
45 changes: 24 additions & 21 deletions spec/system/user/history_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,51 @@

require 'rails_helper'

RSpec.describe 'Ticket history', time_zone: 'Europe/London', type: :system do
RSpec.describe 'User history', authenticated_as: :authenticate, time_zone: 'Europe/London', type: :system do
let(:group) { Group.find_by(name: 'Users') }
let(:customer) { create(:customer, organization: organization) }
let!(:session_user) { User.find_by(login: 'admin@example.com') }
let(:locale) { 'de-de' }
let(:session_user) { create(:admin, preferences: { locale: locale }) }
let(:organization) { create(:organization) }
let(:org_name_1) { 'organization test 1' }
let(:org_name_2) { 'organization test 2' }
let(:org_1) { create(:organization, name: org_name_1) }
let(:org_2) { create(:organization, name: org_name_2) }
let(:locale) { 'de-de' }

before do
def authenticate
freeze_time

travel_to Time.zone.parse('2021-01-22 13:40:00')
current_time = Time.current
customer.update! firstname: 'Customer'
customer.update! email: 'test@example.com'
customer.update! country: 'Germany'
customer.update! out_of_office_start_at: current_time
customer.update! last_login: current_time
customer.organizations << [org_1, org_2]
customer.update!(
firstname: 'Customer',
email: 'test@example.com',
country: 'Germany',
out_of_office_start_at: current_time,
last_login: current_time,
organizations: [organization, org_1, org_2]
)

travel_to Time.zone.parse('2021-04-06 23:30:00')
current_time = Time.current
customer.update! lastname: 'Example'
customer.update! mobile: '5757473827'
customer.update! out_of_office_end_at: current_time
customer.update! last_login: current_time
customer.organizations.delete(org_2)
customer.update!(
lastname: 'Example',
mobile: '5757473827',
out_of_office_end_at: current_time,
last_login: current_time,
organizations: [organization, org_1]
)

travel_back

session_user.preferences[:locale] = locale
session_user.save!
session_user
end

visit '/'
before do
visit '/' if locale != 'en'

# Suppress the modal dialog that invites to contributions for translations that are < 90% as this breaks the tests for de-de.
page.evaluate_script "App.LocalStorage.set('translation_support_no', true, App.Session.get('id'))"

refresh
page.evaluate_script "App.LocalStorage.set('translation_support_no', true, App.Session.get('id'))" if locale != 'en'

visit "#user/profile/#{customer.id}"

Expand Down

0 comments on commit 569749e

Please sign in to comment.