OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/spec/features/work_packages/tabs/activity_notifications_spec.rb

109 lines
4.1 KiB

require 'spec_helper'
require 'features/work_packages/work_packages_page'
require 'support/edit_fields/edit_field'
describe 'Activity tab notifications', js: true, selenium: true do
shared_let(:project) { FactoryBot.create :project_with_types, public: true }
shared_let(:work_package) do
work_package = FactoryBot.create(:work_package,
project: project,
created_at: 5.days.ago.to_date.to_s(:db))
3 years ago
work_package.update({ journal_notes: 'First comment on this wp.',
updated_at: 5.days.ago.to_date.to_s })
work_package.update({ journal_notes: 'Second comment on this wp.',
updated_at: 4.days.ago.to_date.to_s })
work_package.update({ journal_notes: 'Third comment on this wp.',
updated_at: 3.days.ago.to_date.to_s })
work_package
end
shared_let(:admin) { FactoryBot.create(:admin) }
shared_examples_for 'when there are notifications for the work package' do
shared_let(:notification) do
FactoryBot.create :notification,
recipient: admin,
project: project,
resource: work_package,
journal: work_package.journals.last
end
it 'shows a notification bubble with the right number' do
expect(page).to have_selector('[data-qa-selector="tab-counter-Activity"]', text: '1')
end
it 'shows a notification icon next to activities that have an unread notification' do
expect(page).to have_selector('[data-qa-selector="user-activity-bubble"]', count: 1)
expect(page).to have_selector('[data-qa-activity-number="3"] [data-qa-selector="user-activity-bubble"]')
end
it 'shows a button to mark the notifications as read' do
expect(page).to have_selector('[data-qa-selector="mark-notification-read-button"]')
# A click marks the notification as read ...
page.find('[data-qa-selector="mark-notification-read-button"]').click
# ... and updates the view accordingly
expect(page).not_to have_selector('[data-qa-selector="mark-notification-read-button"]')
expect(page).not_to have_selector('[data-qa-selector="tab-counter-Activity"]')
expect(page).not_to have_selector('[data-qa-selector="user-activity-bubble"]')
end
end
shared_examples_for 'when there are no notifications for the work package' do
it 'shows no notification bubble' do
expect(page).not_to have_selector('[data-qa-selector="tab-counter-Activity"]')
end
it 'does not show any notification icons next to activities' do
expect(page).not_to have_selector('[data-qa-selector="user-activity-bubble"]')
end
it 'shows no button to mark the notifications as read' do
expect(page).not_to have_selector('[data-qa-selector="mark-notification-read-button"]')
end
end
context 'when on full view' do
shared_let(:full_view) { Pages::FullWorkPackage.new(work_package, project) }
before do
login_as(admin)
full_view.visit_tab! 'activity'
end
it_behaves_like 'when there are notifications for the work package'
it_behaves_like 'when there are no notifications for the work package'
end
context 'when on split view' do
shared_let(:split_view) { Pages::SplitWorkPackage.new(work_package, project) }
before do
login_as(admin)
split_view.visit_tab! 'activity'
end
it_behaves_like 'when there are notifications for the work package'
it_behaves_like 'when there are no notifications for the work package'
end
context 'when visiting as an anonymous user', with_settings: { login_required?: false } do
let(:full_view) { Pages::FullWorkPackage.new(work_package, project) }
let!(:anonymous_role) do
FactoryBot.create :anonymous_role, permissions: [:view_work_packages]
end
it 'does not show an error' do
full_view.visit_tab! 'activity'
full_view.ensure_page_loaded
full_view.expect_no_notification type: :error, message: 'Http failure response for'
full_view.expect_no_notification
end
end
end