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

Fixes #4140 - No error message is shown if the mandatory role field is missing during creating/updating overviews.

Florian Liebe 2 лет назад
Родитель
Сommit
13c793c8ea

+ 2 - 1
app/assets/javascripts/app/controllers/_application_controller/form.coffee

@@ -784,7 +784,8 @@ class App.ControllerForm extends App.Controller
     # set autofocus by delay to make validation testable
     App.Delay.set(
       ->
-        lookupForm.find('.has-error').find('input, textarea, select').first().trigger('focus')
+        # make sure to work for all field types (e.g. column_select which is an hidden select)
+        lookupForm.find('.has-error').get(0)?.scrollIntoView(true)
       200
       'validate'
     )

+ 1 - 0
app/assets/javascripts/app/views/generic/column_select.jst.eco

@@ -9,6 +9,7 @@
   <%= @attribute.autofocus %>
   value="<%= @attribute.value %>"
   multiple
+  disabled
 >
   <% for option in @allOptions: %>
   <option value="<%= option.value %>" <%= ' selected' if option.selected %>><%= option.name %></option>

+ 56 - 8
spec/system/manage/overviews_spec.rb

@@ -289,14 +289,6 @@ RSpec.describe 'Manage > Overviews', type: :system do
     end
 
     context 'for organization' do
-      # let(:condition) do
-      #   { 'ticket.organization_id' => {
-      #     operator:      operator,
-      #     pre_condition: 'specific',
-      #     value:         [101, 102, 103]
-      #   } }
-      # end
-
       context 'for new overview' do
         before do
           visit '/#manage/overviews'
@@ -377,4 +369,60 @@ RSpec.describe 'Manage > Overviews', type: :system do
       end
     end
   end
+
+  # https://github.com/zammad/zammad/issues/4140
+  context 'checking form validation' do
+    shared_examples 'showing the error message if roles are empty' do
+      it 'shows an error message if roles are empty' do
+        in_modal disappears: false do
+          wait.until do
+            page.has_css?('.has-error')
+            find('.has-error').has_content?('is required')
+          end
+        end
+      end
+    end
+
+    context 'when new overview is created' do
+      before do
+        visit '/#manage/overviews'
+        click_on 'New Overview'
+
+        in_modal disappears: false do
+          fill_in 'name', with: 'dummy'
+          click_on 'Submit'
+        end
+      end
+
+      include_examples 'showing the error message if roles are empty'
+    end
+
+    context 'when existing overview is edited' do
+      let(:overview) { create(:overview, role_ids: [role_id]) }
+      let(:role_id)  { Role.find_by(name: 'Agent').id }
+
+      before do
+        overview
+
+        visit '/#manage/overviews'
+
+        within '.table-overview .js-tableBody' do
+          find("tr[data-id='#{overview.id}']   td.table-draggable").click
+        end
+
+        in_modal disappears: false do
+          # delete the role and wait for the help message to appear
+          find("div[data-attribute-name='role_ids'] div.js-selected div[data-value='#{role_id}']").click
+
+          wait.until do
+            find("div[data-attribute-name='role_ids'] div.u-placeholder").has_content?('Nothing selected')
+          end
+
+          click_on 'Submit'
+        end
+      end
+
+      include_examples 'showing the error message if roles are empty'
+    end
+  end
 end