forked from consuldemocracy/consuldemocracy
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathnotifiable_in_app.rb
140 lines (106 loc) · 4.12 KB
/
notifiable_in_app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
shared_examples "notifiable in-app" do |described_class|
let(:author) { create(:user, :verified) }
let!(:notifiable) { create(model_name(described_class), author: author) }
scenario "Notification icon is shown" do
notification = create(:notification, notifiable: notifiable, user: author)
login_as author
visit root_path
expect(page).to have_css ".icon-notification"
end
scenario "A user commented on my notifiable", :js do
notification = create(:notification, notifiable: notifiable, user: author)
login_as author
visit root_path
find(".icon-notification").click
expect(page).to have_css ".notification", count: 1
expect(page).to have_content "Someone commented on"
expect(page).to have_xpath "//a[@href='#{notification_path(notification)}']"
end
scenario "Multiple users commented on my notifiable", :js do
3.times do
login_as(create(:user, :verified))
visit path_for(notifiable)
fill_in comment_body(notifiable), with: "I agree"
click_button "publish_comment"
within "#comments" do
expect(page).to have_content "I agree"
end
logout
end
login_as author
visit notifications_path
expect(page).to have_css ".notification", count: 1
expect(page).to have_content "There are 3 new comments on"
expect(page).to have_xpath "//a[@href='#{notification_path(Notification.last)}']"
end
scenario "A user replied to my comment", :js do
comment = create :comment, commentable: notifiable, user: author
login_as(create(:user, :verified))
visit path_for(notifiable)
click_link "Reply"
within "#js-comment-form-comment_#{comment.id}" do
fill_in "comment-body-comment_#{comment.id}", with: "I replied to your comment"
click_button "Publish reply"
end
within "#comment_#{comment.id}" do
expect(page).to have_content "I replied to your comment"
end
logout
login_as author
visit notifications_path
expect(page).to have_css ".notification", count: 1
expect(page).to have_content "Someone replied to your comment on"
expect(page).to have_xpath "//a[@href='#{notification_path(Notification.last)}']"
end
scenario "Multiple replies to my comment", :js do
comment = create :comment, commentable: notifiable, user: author
3.times do |n|
login_as(create(:user, :verified))
visit path_for(notifiable)
within("#comment_#{comment.id}_reply") { click_link "Reply" }
within "#js-comment-form-comment_#{comment.id}" do
fill_in "comment-body-comment_#{comment.id}", with: "Reply number #{n}"
click_button "Publish reply"
end
within "#comment_#{comment.id}" do
expect(page).to have_content "Reply number #{n}"
end
logout
end
login_as author
visit notifications_path
expect(page).to have_css ".notification", count: 1
expect(page).to have_content "There are 3 new replies to your comment on"
expect(page).to have_xpath "//a[@href='#{notification_path(Notification.last)}']"
end
scenario "Author commented on his own notifiable", :js do
login_as(author)
visit path_for(notifiable)
fill_in comment_body(notifiable), with: "I commented on my own notifiable"
click_button "publish_comment"
within "#comments" do
expect(page).to have_content "I commented on my own notifiable"
end
within("#notifications") do
find(".icon-no-notification").click
expect(page).to have_css ".notification", count: 0
end
end
scenario "Author replied to his own comment", :js do
comment = create :comment, commentable: notifiable, user: author
login_as author
visit path_for(notifiable)
click_link "Reply"
within "#js-comment-form-comment_#{comment.id}" do
fill_in "comment-body-comment_#{comment.id}", with: "I replied to my own comment"
click_button "Publish reply"
end
within "#comment_#{comment.id}" do
expect(page).to have_content "I replied to my own comment"
end
within("#notifications") do
find(".icon-no-notification").click
expect(page).to have_css ".notification", count: 0
end
end
end