Просмотр исходного кода

Fixes #2229 - Wrong dates on synced calendars.

Mantas Masalskis 5 лет назад
Родитель
Сommit
8d16bcbfdd

+ 1 - 1
app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco

@@ -15,7 +15,7 @@
           <%- @Icon('checkbox', 'icon-unchecked') %>
           <%- @Icon('checkbox-checked', 'icon-checked') %>
         </label>
-      <td><%- @Tdate(day) %>
+      <td><%= day %>
       <td class="settings-list-control-cell"><input class="form-control form-control--small js-summary <% if !meta.active: %>is-disabled<% end %>" type="text" name="public_holidays::<%= day %>::summary" value="<%= meta.summary %>" required/>
       <td class="settings-list-row-control">
         <% if !meta.feed: %>

+ 21 - 0
spec/support/capybara/browser_test_helper.rb

@@ -80,6 +80,27 @@ module BrowserTestHelper
       raise e
     end
 
+    # This method is a derivation of Selenium::WebDriver::Wait#until
+    # which ignores Capybara::ElementNotFound exceptions raised
+    # in the given block.
+    #
+    # @example
+    #  wait(5).until_disappear { find('[data-title="example"]') }
+    #
+    def until_disappears
+      self.until do
+
+        yield
+        false
+      rescue Capybara::ElementNotFound
+        true
+      end
+    rescue Selenium::WebDriver::Error::TimeOutError => e
+      # cleanup backtrace
+      e.set_backtrace(e.backtrace.drop(3))
+      raise e
+    end
+
     # This method loops a given block until the result of it is constant.
     #
     # @example

+ 27 - 0
spec/support/capybara/common_actions.rb

@@ -183,6 +183,33 @@ module CommonActions
     click '.js-openDropdownMacro'
   end
 
+  # Checks if modal is ready
+  #
+  # @param timeout [Integer] seconds to wait
+  def modal_ready(timeout: 4)
+    wait(timeout).until_exists { find('.modal.in') }
+  end
+
+  # Checks if modal has disappeared
+  #
+  # @param timeout [Integer] seconds to wait
+  def modal_disappear(timeout: 4)
+    wait(timeout).until_disappears { find('.modal.in') }
+  end
+
+  # Scrolls to given element
+  #
+  # @option options [String] :css selector
+  # @option options [String] :vertical may be "start", "center", "end", or "nearest". Defaults to "start".
+  def scroll_to(params)
+    vertical = params.fetch :vertical, 'start'
+
+    script = "$('#{params[:css]}').get(0).scrollIntoView({block: '#{vertical}'})"
+
+    execute_script script
+
+    wait(1).until_constant { evaluate_script "$('#{params[:css]}').get(0).scrollTop"  }
+  end
 end
 
 RSpec.configure do |config|

+ 10 - 0
spec/support/time_zone.rb

@@ -0,0 +1,10 @@
+RSpec.configure do |config|
+  config.around(:each, :time_zone) do |example|
+    old_tz = ENV['TZ']
+    ENV['TZ'] = example.metadata[:time_zone]
+
+    example.run
+  ensure
+    ENV['TZ'] = old_tz
+  end
+end

+ 41 - 0
spec/system/admin/calendars/date_spec.rb

@@ -0,0 +1,41 @@
+require 'rails_helper'
+
+RSpec.describe 'Admin Panel > Calendars date', type: :system, authenticated: true, time_zone: 'America/Sao_Paulo' do
+  # https://github.com/zammad/zammad/issues/2229
+  it 'Show festivities dates correctly far away from UTC' do
+    visit '/#manage/calendars'
+
+    click '.js-new'
+
+    modal_ready
+
+    within '.modal-dialog' do
+      fill_in 'name', with: 'test calendar'
+
+      click '.dropdown-toggle'
+      click '.dropdown-menu [data-value="America/Sao_Paulo"]'
+
+      find('.ical_feed select').select 'Brazil'
+
+      click '.js-submit'
+    end
+
+    modal_disappear
+
+    container = find('.action') { |elem| elem.find('.action-row h2').text == 'test calendar' }
+
+    container.find('.js-edit').click
+
+    modal_ready
+
+    within '.modal-dialog' do
+      scroll_to(css: '.modal-dialog', vertical: 'end')
+
+      rows = find_all('.holiday_selector tr') { |elem| elem.has_css?('input.js-summary') && elem.find('input.js-summary').value.starts_with?('Christmas Eve') }
+      row = rows[0]
+
+      expect(row).to have_text('24')
+      expect(row).to have_text('12')
+    end
+  end
+end