refactors notifications into concerns and shared examples
This commit is contained in:
@@ -195,6 +195,170 @@ feature 'Proposal Notifications' do
|
||||
|
||||
end
|
||||
|
||||
context "In-app notifications from the proposal's author" do
|
||||
|
||||
scenario "Voters should receive a notification", :js do
|
||||
author = create(:user)
|
||||
|
||||
user1 = create(:user)
|
||||
user2 = create(:user)
|
||||
user3 = create(:user)
|
||||
|
||||
proposal = create(:proposal, author: author)
|
||||
|
||||
create(:vote, voter: user1, votable: proposal, vote_flag: true)
|
||||
create(:vote, voter: user2, votable: proposal, vote_flag: true)
|
||||
|
||||
login_as(author)
|
||||
visit root_path
|
||||
|
||||
visit new_proposal_notification_path(proposal_id: proposal.id)
|
||||
|
||||
fill_in 'proposal_notification_title', with: "Thank you for supporting my proposal"
|
||||
fill_in 'proposal_notification_body', with: "Please share it with others so we can make it happen!"
|
||||
click_button "Send message"
|
||||
|
||||
expect(page).to have_content "Your message has been sent correctly."
|
||||
|
||||
logout
|
||||
login_as user1
|
||||
visit root_path
|
||||
visit root_path
|
||||
|
||||
find(".icon-notification").click
|
||||
|
||||
notification_for_user1 = Notification.where(user: user1).first
|
||||
expect(page).to have_css ".notification", count: 1
|
||||
expect(page).to have_content "There is one new notification on #{proposal.title}"
|
||||
expect(page).to have_xpath "//a[@href='#{notification_path(notification_for_user1)}']"
|
||||
|
||||
logout
|
||||
login_as user2
|
||||
visit root_path
|
||||
visit root_path
|
||||
|
||||
find(".icon-notification").click
|
||||
|
||||
notification_for_user2 = Notification.where(user: user2).first
|
||||
expect(page).to have_css ".notification", count: 1
|
||||
expect(page).to have_content "There is one new notification on #{proposal.title}"
|
||||
expect(page).to have_xpath "//a[@href='#{notification_path(notification_for_user2)}']"
|
||||
|
||||
logout
|
||||
login_as user3
|
||||
visit root_path
|
||||
visit root_path
|
||||
|
||||
find(".icon-no-notification").click
|
||||
|
||||
expect(page).to have_css ".notification", count: 0
|
||||
end
|
||||
|
||||
scenario "Followers should receive a notification", :js do
|
||||
author = create(:user)
|
||||
|
||||
user1 = create(:user)
|
||||
user2 = create(:user)
|
||||
user3 = create(:user)
|
||||
|
||||
proposal = create(:proposal, author: author)
|
||||
|
||||
create(:follow, :followed_proposal, user: user1, followable: proposal)
|
||||
create(:follow, :followed_proposal, user: user2, followable: proposal)
|
||||
|
||||
login_as author.reload
|
||||
visit root_path
|
||||
|
||||
visit new_proposal_notification_path(proposal_id: proposal.id)
|
||||
|
||||
fill_in 'proposal_notification_title', with: "Thank you for supporting my proposal"
|
||||
fill_in 'proposal_notification_body', with: "Please share it with others so we can make it happen!"
|
||||
click_button "Send message"
|
||||
|
||||
expect(page).to have_content "Your message has been sent correctly."
|
||||
|
||||
logout
|
||||
login_as user1.reload
|
||||
visit root_path
|
||||
|
||||
find(".icon-notification").click
|
||||
|
||||
notification_for_user1 = Notification.where(user: user1).first
|
||||
expect(page).to have_css ".notification", count: 1
|
||||
expect(page).to have_content "There is one new notification on #{proposal.title}"
|
||||
expect(page).to have_xpath "//a[@href='#{notification_path(notification_for_user1)}']"
|
||||
|
||||
logout
|
||||
login_as user2.reload
|
||||
visit root_path
|
||||
|
||||
find(".icon-notification").click
|
||||
|
||||
notification_for_user2 = Notification.where(user: user2).first
|
||||
expect(page).to have_css ".notification", count: 1
|
||||
expect(page).to have_content "There is one new notification on #{proposal.title}"
|
||||
expect(page).to have_xpath "//a[@href='#{notification_path(notification_for_user2)}']"
|
||||
|
||||
logout
|
||||
login_as user3.reload
|
||||
visit root_path
|
||||
|
||||
find(".icon-no-notification").click
|
||||
|
||||
expect(page).to have_css ".notification", count: 0
|
||||
end
|
||||
|
||||
scenario "Proposal hidden", :js do
|
||||
author = create(:user)
|
||||
user = create(:user)
|
||||
|
||||
proposal = create(:proposal, author: author)
|
||||
|
||||
create(:vote, voter: user, votable: proposal, vote_flag: true)
|
||||
|
||||
login_as(author)
|
||||
visit root_path
|
||||
|
||||
visit new_proposal_notification_path(proposal_id: proposal.id)
|
||||
|
||||
fill_in 'proposal_notification_title', with: "Thank you for supporting my proposal"
|
||||
fill_in 'proposal_notification_body', with: "Please share it with others so we can make it happen!"
|
||||
click_button "Send message"
|
||||
|
||||
expect(page).to have_content "Your message has been sent correctly."
|
||||
|
||||
proposal.hide
|
||||
|
||||
logout
|
||||
login_as user
|
||||
visit root_path
|
||||
visit root_path
|
||||
|
||||
find(".icon-notification").click
|
||||
|
||||
notification_for_user = Notification.where(user: user).first
|
||||
expect(page).to have_css ".notification", count: 1
|
||||
expect(page).to have_content "This resource is not available anymore"
|
||||
expect(page).to_not have_xpath "//a[@href='#{notification_path(notification_for_user)}']"
|
||||
end
|
||||
|
||||
scenario "Proposal retired by author", :js do
|
||||
author = create(:user)
|
||||
user = create(:user)
|
||||
|
||||
proposal = create(:proposal, author: author)
|
||||
|
||||
create(:vote, voter: user, votable: proposal, vote_flag: true)
|
||||
|
||||
login_as(author)
|
||||
visit root_path
|
||||
|
||||
visit new_proposal_notification_path(proposal_id: proposal.id)
|
||||
end
|
||||
|
||||
pending "group notifications for the same proposal"
|
||||
end
|
||||
|
||||
scenario "Error messages" do
|
||||
author = create(:user)
|
||||
proposal = create(:proposal, author: author)
|
||||
|
||||
Reference in New Issue
Block a user