From 8d16bcbfdd886279dd080dbf4bd5ea338dd90e3f Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Mon, 21 Oct 2019 13:03:54 +0200 Subject: [PATCH] Fixes #2229 - Wrong dates on synced calendars. --- .../views/calendar/holiday_selector.jst.eco | 2 +- spec/support/capybara/browser_test_helper.rb | 21 ++++++++++ spec/support/capybara/common_actions.rb | 27 ++++++++++++ spec/support/time_zone.rb | 10 +++++ spec/system/admin/calendars/date_spec.rb | 41 +++++++++++++++++++ 5 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 spec/support/time_zone.rb create mode 100644 spec/system/admin/calendars/date_spec.rb diff --git a/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco b/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco index 4ed5a2382..8996e5bbc 100644 --- a/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco +++ b/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco @@ -15,7 +15,7 @@ <%- @Icon('checkbox', 'icon-unchecked') %> <%- @Icon('checkbox-checked', 'icon-checked') %> - <%- @Tdate(day) %> + <%= day %> <% if !meta.feed: %> diff --git a/spec/support/capybara/browser_test_helper.rb b/spec/support/capybara/browser_test_helper.rb index 2b9e894aa..5f31438c5 100644 --- a/spec/support/capybara/browser_test_helper.rb +++ b/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 diff --git a/spec/support/capybara/common_actions.rb b/spec/support/capybara/common_actions.rb index 70fa9bc8b..2028fffed 100644 --- a/spec/support/capybara/common_actions.rb +++ b/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| diff --git a/spec/support/time_zone.rb b/spec/support/time_zone.rb new file mode 100644 index 000000000..256e06644 --- /dev/null +++ b/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 diff --git a/spec/system/admin/calendars/date_spec.rb b/spec/system/admin/calendars/date_spec.rb new file mode 100644 index 000000000..9fe97a305 --- /dev/null +++ b/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