Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Merge ical_spec into calendar_sharing_spec

Mir Bhatia7ffa4358b58c
diff --git a/modules/calendar/spec/features/calendar_sharing_spec.rb b/modules/calendar/spec/features/calendar_sharing_spec.rb
index cab73e0dcec..70e4816511c 100644
--- a/modules/calendar/spec/features/calendar_sharing_spec.rb
+++ b/modules/calendar/spec/features/calendar_sharing_spec.rb
@@ -73,98 +73,19 @@ RSpec.describe 'Calendar sharing via ical', js: true do
public: false)
end
- # context 'without sufficient permissions and the ical_enabled setting enabled', with_settings: { ical_enabled: true } do
- # let(:saved_query) do
- # create(:query_with_view_work_packages_calendar,
- # user: user_without_sharing_permission,
- # project:,
- # public: false)
- # end
-
- # before do
- # login_as user_without_sharing_permission
- # calendar.visit!
- # end
-
- # context 'on persisted calendar query' do
- # before do
- # saved_query
-
- # visit project_calendars_path(project)
-
- # within '#content' do
- # click_link saved_query.name
- # end
-
- # loading_indicator_saveguard
- # end
-
- # it 'shows disabled sharing menu item' do
- # # wait for settings button to become visible
- # expect(page).to have_selector("#work-packages-settings-button")
-
- # # click on settings button
- # page.find_by_id('work-packages-settings-button').click
-
- # # expect disabled sharing menu item
- # within "#settingsDropdown" do
- # # expect(page).to have_button("Subscribe to iCalendar", disabled: true) # disabled selector not working
- # expect(page).to have_selector(".menu-item.inactive", text: "Subscribe to iCalendar")
- # page.click_button("Subscribe to iCalendar")
-
- # # modal should not be shown
- # expect(page).not_to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
- # end
- # end
- # end
- # end
-
- context 'with sufficient permissions and the ical_enabled setting enabled', with_settings: { ical_enabled: true } do
+ context 'without sufficient permissions and the ical_enabled setting enabled', with_settings: { ical_enabled: true } do
+ let(:saved_query) do
+ create(:query_with_view_work_packages_calendar,
+ user: user_without_sharing_permission,
+ project:,
+ public: false)
+ end
+
before do
- login_as user_with_sharing_permission
+ login_as user_without_sharing_permission
calendar.visit!
end
- # context 'on not persisted calendar query' do
- # # add "manage_calendars" permission to user for this context
- # # in order to enable creating a new calendar on the UI.
- # # this permission is not mandatory for the actual feature
- # let(:user_with_sharing_permission) do
- # create(:user,
- # firstname: 'Bernd',
- # member_in_project: project,
- # member_with_permissions: %w[
- # view_work_packages
- # save_queries
- # view_calendar
- # manage_calendars
- # share_calendars
- # ])
- # end
-
- # it 'shows disabled sharing menu item' do
- # visit project_calendars_path(project)
-
- # click_link "Create new calendar"
-
- # # wait for settings button to become visible
- # expect(page).to have_selector("#work-packages-settings-button")
-
- # # click on settings button
- # page.find_by_id('work-packages-settings-button').click
-
- # # expect disabled sharing menu item
- # within "#settingsDropdown" do
- # # expect(page).to have_button("Subscribe to iCalendar", disabled: true) # disabled selector not working
- # expect(page).to have_selector(".menu-item.inactive", text: "Subscribe to iCalendar")
- # page.click_button("Subscribe to iCalendar")
-
- # # modal should not be shown
- # expect(page).not_to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
- # end
- # end
- # end
-
context 'on persisted calendar query' do
before do
saved_query
@@ -178,152 +99,223 @@ RSpec.describe 'Calendar sharing via ical', js: true do
loading_indicator_saveguard
end
- # it 'shows an active menu item' do
- # # wait for settings button to become visible
- # expect(page).to have_selector("#work-packages-settings-button")
+ it 'shows disabled sharing menu item' do
+ # wait for settings button to become visible
+ expect(page).to have_selector("#work-packages-settings-button")
- # # click on settings button
- # page.find_by_id('work-packages-settings-button').click
+ # click on settings button
+ page.find_by_id('work-packages-settings-button').click
- # # expect active sharing menu item
- # within "#settingsDropdown" do
- # expect(page).to have_selector(".menu-item", text: "Subscribe to iCalendar")
- # end
- # end
+ # expect disabled sharing menu item
+ within "#settingsDropdown" do
+ # expect(page).to have_button("Subscribe to iCalendar", disabled: true) # disabled selector not working
+ expect(page).to have_selector(".menu-item.inactive", text: "Subscribe to iCalendar")
+ page.click_button("Subscribe to iCalendar")
- context 'when ical sharing is disabled globally' do
+ # modal should not be shown
+ expect(page).not_to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
+ end
+ end
+ end
+ end
- it 'navigates to iCal settings and disables the setting as an admin' do
- login_as admin
- visit admin_index_path
+ context 'with sufficient permissions', with_settings: { ical_enabled: true } do
+ before do
+ login_as user_with_sharing_permission
+ calendar.visit!
+ end
- within '.menu-blocks--container' do
- click_link 'Calendars and dates'
- end
+ context 'on not persisted calendar query' do
+ # add "manage_calendars" permission to user for this context
+ # in order to enable creating a new calendar on the UI.
+ # this permission is not mandatory for the actual feature
+ let(:user_with_sharing_permission) do
+ create(:user,
+ firstname: 'Bernd',
+ member_in_project: project,
+ member_with_permissions: %w[
+ view_work_packages
+ save_queries
+ view_calendar
+ manage_calendars
+ share_calendars
+ ])
+ end
- expect(page).to have_selector(".title-container", text: "Working days")
- click_link 'iCalendar'
+ it 'shows disabled sharing menu item' do
+ visit project_calendars_path(project)
+
+ click_link "Create new calendar"
+
+ # wait for settings button to become visible
+ expect(page).to have_selector("#work-packages-settings-button")
- expect(page)
- .to have_field('Enable iCalendar subscriptions', checked: true)
+ # click on settings button
+ page.find_by_id('work-packages-settings-button').click
+
+ # expect disabled sharing menu item
+ within "#settingsDropdown" do
+ # expect(page).to have_button("Subscribe to iCalendar", disabled: true) # disabled selector not working
+ expect(page).to have_selector(".menu-item.inactive", text: "Subscribe to iCalendar")
+ page.click_button("Subscribe to iCalendar")
+
+ # modal should not be shown
+ expect(page).not_to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
+ end
+ end
+ end
- binding.pry # Why can this be accessed? current_user is not admin?
+ context 'on persisted calendar query' do
+ before do
+ saved_query
- uncheck 'settings[ical_enabled]'
+ visit project_calendars_path(project)
- click_button 'Save'
+ within '#content' do
+ click_link saved_query.name
+ end
- expect(page)
- .to have_content "Successful update."
+ loading_indicator_saveguard
+ end
- expect(page)
- .to have_field('Enable iCalendar subscriptions', checked: false)
+ it 'shows an active menu item' do
+ # wait for settings button to become visible
+ expect(page).to have_selector("#work-packages-settings-button")
+ # click on settings button
+ page.find_by_id('work-packages-settings-button').click
- binding.pry # Setting reverts
+ # expect active sharing menu item
+ within "#settingsDropdown" do
+ expect(page).to have_selector(".menu-item", text: "Subscribe to iCalendar")
end
+ end
- it 'shows a disabled menu item' do
- login_as user_with_sharing_permission
- saved_query
+ it 'shows a sharing modal' do
+ open_sharing_modal
- visit project_calendars_path(project)
+ expect(page).to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
+ end
- within '#content' do
- click_link saved_query.name
- end
+ it 'closes the sharing modal when closed by user by clicking the close button' do
+ open_sharing_modal
- loading_indicator_saveguard
+ expect(page).to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
- # wait for settings button to become visible
- expect(page).to have_selector("#work-packages-settings-button")
+ click_button "Cancel"
- # click on settings button
- page.find_by_id('work-packages-settings-button').click
+ expect(page).not_to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
+ end
- # expect disabled sharing menu item
- within "#settingsDropdown" do
- # expect(page).to have_button("Subscribe to iCalendar", disabled: true) # disabled selector not working
- expect(page).to have_selector(".menu-item.inactive", text: "Subscribe to iCalendar")
- page.click_button("Subscribe to iCalendar")
+ it 'successfully requests a new tokenized iCalendar URL when a unique name is provided' do
+ open_sharing_modal
- # modal should not be shown
- expect(page).not_to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
- end
- end
+ fill_in "Token name", with: "A token name"
+
+ click_button "Copy URL"
+
+ # implicitly testing for success -> modal is closed and fallback message is shown
+ expect(page).not_to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
+ expect(page).to have_content("/projects/#{saved_query.project.id}/calendars/#{saved_query.id}/ical?ical_token=")
+
+ # explictly testing for success message is not working in test env, probably
+ # due to missing clipboard permissions of the headless browser
+ #
+ # expect(page).to have_content("URL copied to clipboard")
+
+ # TODO: Not able to test if the URL was actuall copied to the clipboard
+ # Tried following without success
+ # https://copyprogramming.com/howto/emulating-a-clipboard-copy-paste-with-selinum-capybara
end
- # it 'shows a sharing modal' do
- # open_sharing_modal
+ it 'validates the presence of a name' do
+ open_sharing_modal
- # expect(page).to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
- # end
+ # fill_in "Token name", with: "A token name"
- # it 'closes the sharing modal when closed by user by clicking the close button' do
- # open_sharing_modal
+ click_button "Copy URL"
- # expect(page).to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
+ # modal is still shown and error message is shown
+ expect(page).to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
+ expect(page).to have_content("Name is mandatory")
+ end
+
+ it 'validates the uniqueness of a name' do
+ open_sharing_modal
+
+ fill_in "Token name", with: "A token name"
- # click_button "Cancel"
+ click_button "Copy URL"
- # expect(page).not_to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
- # end
+ expect(page).not_to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
+ expect(page).to have_content("/projects/#{saved_query.project.id}/calendars/#{saved_query.id}/ical?ical_token=")
- # it 'successfully requests a new tokenized iCalendar URL when a unique name is provided' do
- # open_sharing_modal
+ # do the same thing again, now expect validation error
- # fill_in "Token name", with: "A token name"
+ open_sharing_modal
- # click_button "Copy URL"
+ fill_in "Token name", with: "A token name" # same name for same user and same query -> not allowed
+
+ click_button "Copy URL"
+
+ # modal is still shown and error message is shown
+ expect(page).to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
+ expect(page).to have_content("Name is already in use")
+ end
+ end
+ end
- # # implicitly testing for success -> modal is closed and fallback message is shown
- # expect(page).not_to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
- # expect(page).to have_content("/projects/#{saved_query.project.id}/calendars/#{saved_query.id}/ical?ical_token=")
+ context 'with sufficient permissions on persisted calendary query' do
+ it 'navigates to iCal settings and disables the setting as an admin, disallowing sharing for a user' do
+ login_as admin
+ visit admin_index_path
- # # explictly testing for success message is not working in test env, probably
- # # due to missing clipboard permissions of the headless browser
- # #
- # # expect(page).to have_content("URL copied to clipboard")
+ within '.menu-blocks--container' do
+ click_link 'Calendars and dates'
+ end
- # # TODO: Not able to test if the URL was actuall copied to the clipboard
- # # Tried following without success
- # # https://copyprogramming.com/howto/emulating-a-clipboard-copy-paste-with-selinum-capybara
- # end
+ expect(page).to have_selector(".title-container", text: "Working days")
+ click_link 'iCalendar'
- # it 'validates the presence of a name' do
- # open_sharing_modal
+ expect(page)
+ .to have_field('Enable iCalendar subscriptions', checked: true)
- # # fill_in "Token name", with: "A token name"
+ uncheck 'settings[ical_enabled]'
- # click_button "Copy URL"
+ click_button 'Save'
- # # modal is still shown and error message is shown
- # expect(page).to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
- # expect(page).to have_content("Name is mandatory")
- # end
+ expect(page)
+ .to have_content "Successful update."
- # it 'validates the uniqueness of a name' do
- # open_sharing_modal
+ expect(page)
+ .to have_field('Enable iCalendar subscriptions', checked: false)
- # fill_in "Token name", with: "A token name"
+ login_as user_with_sharing_permission
+ saved_query
- # click_button "Copy URL"
+ visit project_calendars_path(project)
- # expect(page).not_to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
- # expect(page).to have_content("/projects/#{saved_query.project.id}/calendars/#{saved_query.id}/ical?ical_token=")
+ within '#content' do
+ click_link saved_query.name
+ end
- # # do the same thing again, now expect validation error
+ loading_indicator_saveguard
- # open_sharing_modal
+ # wait for settings button to become visible
+ expect(page).to have_selector("#work-packages-settings-button")
- # fill_in "Token name", with: "A token name" # same name for same user and same query -> not allowed
+ # click on settings button
+ page.find_by_id('work-packages-settings-button').click
- # click_button "Copy URL"
+ # expect disabled sharing menu item
+ within "#settingsDropdown" do
+ # expect(page).to have_button("Subscribe to iCalendar", disabled: true) # disabled selector not working
+ expect(page).to have_selector(".menu-item.inactive", text: "Subscribe to iCalendar")
+ page.click_button("Subscribe to iCalendar")
- # # modal is still shown and error message is shown
- # expect(page).to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
- # expect(page).to have_content("Name is already in use")
- # end
+ # modal should not be shown
+ expect(page).not_to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
+ end
end
end