diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb index 58aebb472..f8e77ac0d 100644 --- a/spec/features/notifications_spec.rb +++ b/spec/features/notifications_spec.rb @@ -128,4 +128,50 @@ feature "Notifications" do expect(page).to_not have_css("#notifications") end + context "Admin Notifications" do + let(:admin_notification) do + create(:admin_notification, title: 'Notification title', + body: 'Notification body', + link: 'https://www.external.link.dev/', + segment_recipient: 'all_users') + end + + let!(:notification) do + create(:notification, user: user, notifiable: admin_notification) + end + + before do + login_as user + end + + scenario "With external link" do + visit notifications_path + expect(page).to have_content('Notification title') + expect(page).to have_content('Notification body') + + first("#notification_#{notification.id} a").click + expect(page.current_url).to eq('https://www.external.link.dev/') + end + + scenario "With internal link" do + admin_notification.update_attributes(link: '/stats') + + visit notifications_path + expect(page).to have_content('Notification title') + expect(page).to have_content('Notification body') + + first("#notification_#{notification.id} a").click + expect(page).to have_current_path('/stats') + end + + scenario "Without a link" do + admin_notification.update_attributes(link: '/stats') + + visit notifications_path + expect(page).to have_content('Notification title') + expect(page).to have_content('Notification body') + expect(page).not_to have_link(notification_path(notification), visible: false) + end + end + end