Browse Source

Maintenance: Mock test time zone in system tests as well.

Dusan Vuckovic 2 years ago
parent
commit
a4cace60f6

+ 1 - 1
spec/support/custom_matchers/system/have_time_tag.rb

@@ -5,7 +5,7 @@ module HaveTimeTag
 
   matcher :have_time_tag do
     match do |actual|
-      actual.has_css?('time', **args) { |elem| elem[:datetime] == expected.iso8601 || elem[:datetime] == expected.iso8601(3) } # handle JS version with miliseconds too
+      actual.has_css?('time', **args) { |elem| elem[:datetime] == expected.utc.iso8601 || elem[:datetime] == expected.utc.iso8601(3) } # handle JS version with miliseconds too
     end
 
     def args

+ 5 - 7
spec/support/time_zone.rb

@@ -2,17 +2,15 @@
 
 RSpec.configure do |config|
   config.around(:each, :time_zone) do |example|
+    # RSpec System/Capybara tests use TZ environment variable to set timezone in the browser.
     if example.metadata[:type] == :system
-      # RSpec System/Capybara tests use TZ variable to set timezone in browser
       old_tz = ENV['TZ']
       ENV['TZ'] = example.metadata[:time_zone]
-
-      example.run
-    else
-      # Other RSpec tests run inside of the same process and don't take TZ into account.
-      # Mocking time zone via Time object is enough
-      Time.use_zone(example.metadata[:time_zone]) { example.run }
     end
+
+    # Other RSpec tests run inside the same process and don't take TZ variable into account.
+    #   However, they should still have mocking of the test time zone for the Time object applied.
+    Time.use_zone(example.metadata[:time_zone]) { example.run }
   ensure
     ENV['TZ'] = old_tz if example.metadata[:type] == :system
   end

+ 0 - 8
spec/system/ticket/create_spec.rb

@@ -498,10 +498,6 @@ RSpec.describe 'Ticket Create', type: :system do
       ObjectManager::Attribute.where(name: %i[date_test datetime_test]).destroy_all
     end
 
-    around do |example|
-      Time.use_zone('Europe/London') { example.run }
-    end
-
     before do
       visit '/'
 
@@ -1311,10 +1307,6 @@ RSpec.describe 'Ticket Create', type: :system do
 
   describe 'Ticket templates are missing pending till option #4318', time_zone: 'Europe/London' do
 
-    around do |example|
-      Time.use_zone('Europe/London') { example.run }
-    end
-
     shared_examples 'check datetime field' do
 
       shared_examples 'calculated datetime value' do

+ 28 - 26
spec/system/ticket/history_spec.rb

@@ -8,32 +8,34 @@ RSpec.describe 'Ticket history', authenticated_as: :admin_de, time_zone: 'Europe
   let(:admin_de) { create(:admin, :groupable, preferences: { locale: 'de-de' }, group: group) }
 
   before do
-    freeze_time
-
-    travel_to DateTime.parse('2021-01-22 13:40:00 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_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_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
+    Time.use_zone('UTC') do
+      freeze_time
+
+      travel_to DateTime.parse('2021-01-22 13:40:00 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_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_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
 
     visit '/'
 

+ 2 - 2
spec/system/user/history_spec.rb

@@ -16,7 +16,7 @@ RSpec.describe 'Ticket history', time_zone: 'Europe/London', type: :system do
   before do
     freeze_time
 
-    travel_to DateTime.parse('2021-01-22 13:40:00 UTC')
+    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'
@@ -25,7 +25,7 @@ RSpec.describe 'Ticket history', time_zone: 'Europe/London', type: :system do
     customer.update! last_login: current_time
     customer.organizations << [org_1, org_2]
 
-    travel_to DateTime.parse('2021-04-06 23:30:00 UTC')
+    travel_to Time.zone.parse('2021-04-06 23:30:00')
     current_time = Time.current
     customer.update! lastname: 'Example'
     customer.update! mobile: '5757473827'