Skip to content

Commit

Permalink
Prevent rendering of delete buttons on global calendars page
Browse files Browse the repository at this point in the history
As per requirements, the global index page for calendars, should not
render the delete buttons for each query on the table (in tandem with
other global index pages).

Also, extracted out some expectations into page objects in the
calendars#index page. This reads nicer to me and helps keep better
track of what is and isn't expected at a high level.
  • Loading branch information
aaron-contreras committed Jul 14, 2023
1 parent f56307c commit a78fb05
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 27 deletions.
8 changes: 7 additions & 1 deletion modules/calendar/app/components/calendar/row_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
48 changes: 22 additions & 26 deletions modules/calendar/spec/features/calendars_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#++

require 'spec_helper'
require_relative '../support/pages/calendar'

RSpec.describe 'Calendars', 'index', :js, :with_cuprite do
shared_let(:project) do
Expand Down Expand Up @@ -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
Expand All @@ -114,23 +116,23 @@

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

context 'with no views' do
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions modules/calendar/spec/support/pages/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a78fb05

Please sign in to comment.