diff --git a/modules/calendar/app/components/calendar/row_component.rb b/modules/calendar/app/components/calendar/row_component.rb index 269fb0a64521..17f7e5433c74 100644 --- a/modules/calendar/app/components/calendar/row_component.rb +++ b/modules/calendar/app/components/calendar/row_component.rb @@ -51,7 +51,7 @@ def button_links end def delete_link - if table.current_user.allowed_to?(:manage_calendars, project) + if render_delete_link? link_to( '', project_calendar_path(project, query.id), @@ -65,5 +65,11 @@ def delete_link ) end end + + private + + def render_delete_link? + table.current_project && table.current_user.allowed_to?(:manage_calendars, project) + end end end diff --git a/modules/calendar/spec/features/calendars_index_spec.rb b/modules/calendar/spec/features/calendars_index_spec.rb index c88bf26a91cb..d11e9fbfe4d8 100644 --- a/modules/calendar/spec/features/calendars_index_spec.rb +++ b/modules/calendar/spec/features/calendars_index_spec.rb @@ -27,6 +27,7 @@ #++ require 'spec_helper' +require_relative '../support/pages/calendar' RSpec.describe 'Calendars', 'index', :js, :with_cuprite do shared_let(:project) do @@ -104,6 +105,7 @@ end context 'when visiting from a global context', with_flag: { more_global_index_pages: true } do + let(:calendars_page) { Pages::Calendar.new(nil) } let(:queries) { [query, other_query] } before do @@ -114,7 +116,7 @@ context 'with permissions to globally manage calendars' do it 'shows no create button' do - expect(page).not_to have_selector '.button', text: 'Calendar' + calendars_page.expect_no_create_button end end @@ -122,15 +124,15 @@ let(:queries) { [] } it 'shows an empty index page' do - expect(page).to have_text 'There is currently nothing to display.' + calendars_page.expect_no_views_visible end end context 'with existing views' do it 'shows those views', :aggregate_failures do queries.each do |q| - expect(page).to have_selector 'td', text: q.name - expect(page).to have_selector "[data-qa-selector='calendar-remove-#{q.id}']" + calendars_page.expect_view_visible(q) + calendars_page.expect_no_delete_button(q) end end end @@ -147,17 +149,18 @@ let(:query) { create(:query, user:, project:, public: false) } it 'does not show a non-public view' do - expect(page).to have_text 'There is currently nothing to display.' - expect(page).not_to have_selector 'td', text: query.name + calendars_page.expect_no_views_visible + calendars_page.expect_view_not_visible query - # Does not show the delete - expect(page).not_to have_selector "[data-qa-selector='team-planner-remove-#{query.id}']" + calendars_page.expect_no_delete_button query end end end end context 'when visiting from a project-specific context' do + let(:calendars_page) { Pages::Calendar.new(project) } + before do login_as current_user query @@ -168,15 +171,15 @@ let(:query) { nil } it 'shows an empty index page' do - expect(page).to have_text 'There is currently nothing to display.' - expect(page).to have_selector '.button', text: 'Calendar' + calendars_page.expect_no_views_visible + calendars_page.expect_create_button end end context 'with an existing view' do it 'shows that view' do - expect(page).to have_selector 'td', text: query.name - expect(page).to have_selector "[data-qa-selector='calendar-remove-#{query.id}']" + calendars_page.expect_view_visible query + calendars_page.expect_delete_button query end context 'with another user with limited access' do @@ -187,28 +190,21 @@ member_with_permissions: %w[view_work_packages view_calendar]) end - it 'does not show the create button' do - expect(page).to have_selector 'td', text: query.name + it 'does not show the management buttons' do + calendars_page.expect_view_visible query - # Does not show the delete - expect(page).not_to have_selector "[data-qa-selector='calendar-remove-#{query.id}']" - - # Does not show the create button - expect(page).not_to have_selector '.button', text: 'Calendar' + calendars_page.expect_no_delete_button query + calendars_page.expect_no_create_button end context 'when the view is non-public' do let(:query) { create(:query, user:, project:, public: false) } it 'does not show a non-public view' do - expect(page).to have_text 'There is currently nothing to display.' - expect(page).not_to have_selector 'td', text: query.name - - # Does not show the delete - expect(page).not_to have_selector "[data-qa-selector='team-planner-remove-#{query.id}']" + calendars_page.expect_no_views_visible + calendars_page.expect_view_not_visible query - # Does not show the create button - expect(page).not_to have_selector '.button', text: 'Calendar' + calendars_page.expect_no_create_button end end end diff --git a/modules/calendar/spec/support/pages/calendar.rb b/modules/calendar/spec/support/pages/calendar.rb index 658ed3c5006d..18658dd1e6ea 100644 --- a/modules/calendar/spec/support/pages/calendar.rb +++ b/modules/calendar/spec/support/pages/calendar.rb @@ -111,5 +111,33 @@ def expect_wp_not_resizable(work_package) def expect_wp_not_draggable(work_package) expect(page).to have_selector('.fc-event:not(.fc-event-draggable)', text: work_package.subject) end + + def expect_create_button + expect(page).to have_selector '.button', text: 'Calendar' + end + + def expect_no_create_button + expect(page).not_to have_selector '.button', text: 'Calendar' + end + + def expect_delete_button(query) + expect(page).to have_selector "[data-qa-selector='calendar-remove-#{query.id}']" + end + + def expect_no_delete_button(query) + expect(page).not_to have_selector "[data-qa-selector='calendar-remove-#{query.id}']" + end + + def expect_no_views_visible + expect(page).to have_text 'There is currently nothing to display.' + end + + def expect_view_visible(query) + expect(page).to have_selector 'td', text: query.name + end + + def expect_view_not_visible(query) + expect(page).not_to have_selector 'td', text: query.name + end end end