From 1cec1923c82e0678802f2b87eaf97a0a27040adc Mon Sep 17 00:00:00 2001 From: Paulo Henrique Date: Mon, 12 Feb 2024 16:32:35 -0300 Subject: [PATCH 1/5] =?UTF-8?q?Adiciona=20link=20na=20notifica=C3=A7=C3=A3?= =?UTF-8?q?o=20da=20publica=C3=A7=C3=A3o=20comentada?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ana resgalla --- app/views/notifications/_comment.html.erb | 2 +- .../notifications/user_sees_comments_notification_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/notifications/_comment.html.erb b/app/views/notifications/_comment.html.erb index 683889d..aa8b834 100644 --- a/app/views/notifications/_comment.html.erb +++ b/app/views/notifications/_comment.html.erb @@ -1 +1 @@ -

<%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> comentou em sua publicação \ No newline at end of file +

<%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> comentou em sua publicação: <%= link_to notification.notifiable.post.title, post_path(notification.notifiable.post) %> \ No newline at end of file diff --git a/spec/system/notifications/user_sees_comments_notification_spec.rb b/spec/system/notifications/user_sees_comments_notification_spec.rb index 1180386..9eaf027 100644 --- a/spec/system/notifications/user_sees_comments_notification_spec.rb +++ b/spec/system/notifications/user_sees_comments_notification_spec.rb @@ -12,7 +12,8 @@ expect(Notification.count).to eq 1 expect(page).to have_current_path notifications_path - expect(page).to have_content 'comentou em sua publicação' + expect(page).to have_content "comentou em sua publicação: #{post.title}" + expect(page).to have_link post.title, href: post_path(post) expect(page).to have_link comment.user.profile.full_name, href: profile_path(comment.user.profile) end From 5778287be7f39905520a583617aa47bbbfd060c7 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Date: Mon, 12 Feb 2024 16:53:58 -0300 Subject: [PATCH 2/5] =?UTF-8?q?Mostra=20contagem=20de=20notifica=C3=A7?= =?UTF-8?q?=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -Conta somente com status de não lida -Ao clicar em notificações marca todas como lida Co-authored-by: ana resgalla --- app/controllers/notifications_controller.rb | 1 + app/views/shared/_navbar.html.erb | 4 +++- .../notifications/user_sees_notifications_spec.rb | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 1d30a17..49bee49 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -3,5 +3,6 @@ class NotificationsController < ApplicationController def index @notifications = current_user.profile.notifications.order(created_at: :desc) + @notifications.update_all(read: true) end end diff --git a/app/views/shared/_navbar.html.erb b/app/views/shared/_navbar.html.erb index a58182e..56e2682 100644 --- a/app/views/shared/_navbar.html.erb +++ b/app/views/shared/_navbar.html.erb @@ -41,7 +41,9 @@

<% if current_user.admin? %> diff --git a/spec/system/notifications/user_sees_notifications_spec.rb b/spec/system/notifications/user_sees_notifications_spec.rb index 5e739a1..aaac2a7 100644 --- a/spec/system/notifications/user_sees_notifications_spec.rb +++ b/spec/system/notifications/user_sees_notifications_spec.rb @@ -55,4 +55,17 @@ expect(page).to have_content 'Nenhuma notificação' expect(Notification.count).to eq 0 end + + it 'contagem de notificações muda ao ir para página de notificações' do + user = create(:user) + invitation = create(:invitation, profile: user.profile) + + login_as user + visit notifications_path + click_button class: 'dropdown-toggle' + + expect(page).not_to have_content 'Notificações 1' + expect(page).to have_content 'Notificações' + expect(user.profile.notifications.count).to eq 1 + end end From 826608bffa803f282adabd6c6ff06ad84cf9d3a3 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Date: Mon, 12 Feb 2024 17:59:56 -0300 Subject: [PATCH 3/5] Edita model Notification -remove coluna read -adiciona coluna status Co-authored-by: ana resgalla --- app/controllers/notifications_controller.rb | 2 +- app/models/notification.rb | 2 ++ app/views/notifications/_comment.html.erb | 2 +- app/views/notifications/_connection.html.erb | 2 +- app/views/notifications/_invitation.html.erb | 2 +- app/views/notifications/_like.html.erb | 4 ++-- app/views/notifications/_post.html.erb | 2 +- app/views/notifications/index.html.erb | 18 ++++++++++-------- app/views/shared/_navbar.html.erb | 9 ++++++--- ...240212195517_add_status_to_notifications.rb | 5 +++++ ...212195603_remove_read_from_notifications.rb | 5 +++++ db/schema.rb | 4 ++-- .../user_sees_notifications_spec.rb | 2 +- 13 files changed, 38 insertions(+), 21 deletions(-) create mode 100644 db/migrate/20240212195517_add_status_to_notifications.rb create mode 100644 db/migrate/20240212195603_remove_read_from_notifications.rb diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 49bee49..3631e38 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -3,6 +3,6 @@ class NotificationsController < ApplicationController def index @notifications = current_user.profile.notifications.order(created_at: :desc) - @notifications.update_all(read: true) + @notifications.update_all(status: :seen) end end diff --git a/app/models/notification.rb b/app/models/notification.rb index 3475ad6..f7fa0aa 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -1,4 +1,6 @@ class Notification < ApplicationRecord belongs_to :profile belongs_to :notifiable, polymorphic: true + + enum status: { unseen: 0, seen: 5, clicked: 10 } end diff --git a/app/views/notifications/_comment.html.erb b/app/views/notifications/_comment.html.erb index aa8b834..6ad7e46 100644 --- a/app/views/notifications/_comment.html.erb +++ b/app/views/notifications/_comment.html.erb @@ -1 +1 @@ -

<%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> comentou em sua publicação: <%= link_to notification.notifiable.post.title, post_path(notification.notifiable.post) %> \ No newline at end of file +<%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> comentou em sua publicação: <%= link_to notification.notifiable.post.title, post_path(notification.notifiable.post) %> \ No newline at end of file diff --git a/app/views/notifications/_connection.html.erb b/app/views/notifications/_connection.html.erb index 4e2666a..81ad988 100644 --- a/app/views/notifications/_connection.html.erb +++ b/app/views/notifications/_connection.html.erb @@ -1 +1 @@ -

<%= link_to notification.notifiable.follower.user.full_name, profile_path(notification.notifiable.follower) %> começou a te seguir \ No newline at end of file +<%= link_to notification.notifiable.follower.user.full_name, profile_path(notification.notifiable.follower) %> começou a te seguir \ No newline at end of file diff --git a/app/views/notifications/_invitation.html.erb b/app/views/notifications/_invitation.html.erb index b618f6b..7f2ec01 100644 --- a/app/views/notifications/_invitation.html.erb +++ b/app/views/notifications/_invitation.html.erb @@ -1 +1 @@ -

Você recebeu um convite para <%= link_to notification.notifiable.project_title, invitation_path(notification.notifiable) %> \ No newline at end of file +Você recebeu um convite para <%= link_to notification.notifiable.project_title, invitation_path(notification.notifiable) %> \ No newline at end of file diff --git a/app/views/notifications/_like.html.erb b/app/views/notifications/_like.html.erb index 4a428bc..6b0d4a7 100644 --- a/app/views/notifications/_like.html.erb +++ b/app/views/notifications/_like.html.erb @@ -1,5 +1,5 @@ <% if notification.notifiable.likeable.is_a?Post %> -

<%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> curtiu sua publicação + <%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> curtiu sua publicação <% else %> -

<%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> curtiu seu comentário + <%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> curtiu seu comentário <% end %> \ No newline at end of file diff --git a/app/views/notifications/_post.html.erb b/app/views/notifications/_post.html.erb index 9e2e784..22de0f8 100644 --- a/app/views/notifications/_post.html.erb +++ b/app/views/notifications/_post.html.erb @@ -1 +1 @@ -

<%= notification.notifiable.user.full_name %> fez uma <%= link_to 'publicação', post_path(notification.notifiable) %> \ No newline at end of file +<%= notification.notifiable.user.full_name %> fez uma <%= link_to 'publicação', post_path(notification.notifiable) %> \ No newline at end of file diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb index 7d8e41c..e661738 100644 --- a/app/views/notifications/index.html.erb +++ b/app/views/notifications/index.html.erb @@ -1,16 +1,18 @@

Notificações

<% if @notifications&.any? %> +
    <% @notifications.each do |notification| %> -
    - <%= render( - partial: "#{notification.notifiable.class.name.downcase}" , - locals: { notification: notification } - )%> - há <%= distance_of_time_in_words_to_now(notification.notifiable.created_at) %>

    -
    +
  • + <%= render( + partial: "#{notification.notifiable.class.name.downcase}" , + locals: { notification: notification } + )%> + há <%= distance_of_time_in_words_to_now(notification.notifiable.created_at) %> +
  • <% end %> +
<% else %>

Nenhuma notificação encontrada

<% end %> -
\ No newline at end of file + diff --git a/app/views/shared/_navbar.html.erb b/app/views/shared/_navbar.html.erb index 56e2682..14bf761 100644 --- a/app/views/shared/_navbar.html.erb +++ b/app/views/shared/_navbar.html.erb @@ -41,9 +41,12 @@ <% if current_user.admin? %> diff --git a/db/migrate/20240212195517_add_status_to_notifications.rb b/db/migrate/20240212195517_add_status_to_notifications.rb new file mode 100644 index 0000000..dada613 --- /dev/null +++ b/db/migrate/20240212195517_add_status_to_notifications.rb @@ -0,0 +1,5 @@ +class AddStatusToNotifications < ActiveRecord::Migration[7.1] + def change + add_column :notifications, :status, :integer, default: 0 + end +end diff --git a/db/migrate/20240212195603_remove_read_from_notifications.rb b/db/migrate/20240212195603_remove_read_from_notifications.rb new file mode 100644 index 0000000..cacac2b --- /dev/null +++ b/db/migrate/20240212195603_remove_read_from_notifications.rb @@ -0,0 +1,5 @@ +class RemoveReadFromNotifications < ActiveRecord::Migration[7.1] + def change + remove_column :notifications, :read, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index d6382f6..111b6e0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_10_163321) do +ActiveRecord::Schema[7.1].define(version: 2024_02_12_195603) do create_table "action_text_rich_texts", force: :cascade do |t| t.string "name", null: false t.text "body" @@ -133,7 +133,7 @@ t.integer "notifiable_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.boolean "read", default: false + t.integer "status", default: 0 t.index ["notifiable_type", "notifiable_id"], name: "index_notifications_on_notifiable" t.index ["profile_id"], name: "index_notifications_on_profile_id" end diff --git a/spec/system/notifications/user_sees_notifications_spec.rb b/spec/system/notifications/user_sees_notifications_spec.rb index aaac2a7..19996c8 100644 --- a/spec/system/notifications/user_sees_notifications_spec.rb +++ b/spec/system/notifications/user_sees_notifications_spec.rb @@ -58,7 +58,7 @@ it 'contagem de notificações muda ao ir para página de notificações' do user = create(:user) - invitation = create(:invitation, profile: user.profile) + create(:invitation, profile: user.profile) login_as user visit notifications_path From 0b8170e77f1f799a32a122637287be7a75fd7d0e Mon Sep 17 00:00:00 2001 From: Paulo Henrique Date: Tue, 13 Feb 2024 04:47:41 -0300 Subject: [PATCH 4/5] =?UTF-8?q?Notifica=C3=A7=C3=A3o=20muda=20cor=20ao=20s?= =?UTF-8?q?er=20clicada?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -Muda status da notificação para "clicked" ao ser clicada -Muda status da notificação para "seen" ao acessar página de notificações Co-authored-by: ana resgalla --- .../stylesheets/application.bootstrap.scss | 3 ++ app/controllers/notifications_controller.rb | 40 ++++++++++++++++- app/models/profile.rb | 3 +- app/views/notifications/_comment.html.erb | 2 +- app/views/notifications/_connection.html.erb | 2 +- app/views/notifications/_invitation.html.erb | 2 +- app/views/notifications/_like.html.erb | 4 +- app/views/notifications/_post.html.erb | 2 +- app/views/notifications/index.html.erb | 18 ++++---- config/locales/notifications.pt-BR.yml | 2 + config/routes.rb | 2 +- db/schema.rb | 2 +- .../user_sees_comments_notification_spec.rb | 43 ++++++++++++++++--- .../user_sees_invitation_notification_spec.rb | 4 +- ...ser_sees_new_follower_notification_spec.rb | 14 +++++- .../user_sees_post_notification_spec.rb | 34 +++++++++++++-- 16 files changed, 145 insertions(+), 32 deletions(-) diff --git a/app/assets/stylesheets/application.bootstrap.scss b/app/assets/stylesheets/application.bootstrap.scss index d09e0a7..aff48cd 100644 --- a/app/assets/stylesheets/application.bootstrap.scss +++ b/app/assets/stylesheets/application.bootstrap.scss @@ -8,6 +8,9 @@ $theme-colors: ( "light": rgba(255, 251, 251, 0.603), "dark": #1b1b1b ); + +$primary: #a130fd; + @import 'bootstrap/scss/bootstrap'; @import 'bootstrap-icons/font/bootstrap-icons'; @import 'actiontext.css'; diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 3631e38..5b500fc 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -3,6 +3,44 @@ class NotificationsController < ApplicationController def index @notifications = current_user.profile.notifications.order(created_at: :desc) - @notifications.update_all(status: :seen) + @notifications.map { |n| n.seen! if n.unseen? } + end + + def update + @notification = Notification.find(params[:id]) + @notification.clicked! + redirect_to_notification + end + + private + + def redirect_to_notification + return redirect_to_invitation if @notification.notifiable.is_a? Invitation + return redirect_to_comment if @notification.notifiable.is_a? Comment + return redirect_to_connection if @notification.notifiable.is_a? Connection + return redirect_to_post if @notification.notifiable.is_a? Post + + redirect_to_like if @notification.notifiable.is_a? Like + end + + def redirect_to_invitation + redirect_to invitation_path(@notification.notifiable) + end + + def redirect_to_comment + redirect_to post_path(@notification.notifiable.post) + end + + def redirect_to_connection + redirect_to profile_path(@notification.notifiable.follower) + end + + def redirect_to_post + redirect_to post_path(@notification.notifiable) + end + + def redirect_to_like + likeable = @notification.notifiable.likeable + redirect_to post_path(likeable.is_a?(Comment) ? likeable.post : likeable) end end diff --git a/app/models/profile.rb b/app/models/profile.rb index e6da128..130aba5 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -38,8 +38,7 @@ class Profile < ApplicationRecord enum privacy: { private_profile: 0, public_profile: 10 } enum status: { inactive: 0, active: 5 } - delegate :full_name, to: :user - delegate :email, to: :user + delegate :full_name, :email, to: :user def self.advanced_search(search_query) left_outer_joins(:job_categories, :personal_info, :user).where( diff --git a/app/views/notifications/_comment.html.erb b/app/views/notifications/_comment.html.erb index 6ad7e46..4b2dad0 100644 --- a/app/views/notifications/_comment.html.erb +++ b/app/views/notifications/_comment.html.erb @@ -1 +1 @@ -<%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> comentou em sua publicação: <%= link_to notification.notifiable.post.title, post_path(notification.notifiable.post) %> \ No newline at end of file +<%= notification.notifiable.user.full_name %> comentou em sua publicação: <%= notification.notifiable.post.title %> \ No newline at end of file diff --git a/app/views/notifications/_connection.html.erb b/app/views/notifications/_connection.html.erb index 81ad988..dee18fb 100644 --- a/app/views/notifications/_connection.html.erb +++ b/app/views/notifications/_connection.html.erb @@ -1 +1 @@ -<%= link_to notification.notifiable.follower.user.full_name, profile_path(notification.notifiable.follower) %> começou a te seguir \ No newline at end of file +<%= notification.notifiable.follower.full_name %> começou a te seguir \ No newline at end of file diff --git a/app/views/notifications/_invitation.html.erb b/app/views/notifications/_invitation.html.erb index 7f2ec01..133a41b 100644 --- a/app/views/notifications/_invitation.html.erb +++ b/app/views/notifications/_invitation.html.erb @@ -1 +1 @@ -Você recebeu um convite para <%= link_to notification.notifiable.project_title, invitation_path(notification.notifiable) %> \ No newline at end of file +Você recebeu um convite para <%= notification.notifiable.project_title %> \ No newline at end of file diff --git a/app/views/notifications/_like.html.erb b/app/views/notifications/_like.html.erb index 6b0d4a7..d4de84e 100644 --- a/app/views/notifications/_like.html.erb +++ b/app/views/notifications/_like.html.erb @@ -1,5 +1,5 @@ <% if notification.notifiable.likeable.is_a?Post %> - <%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> curtiu sua publicação + <%= notification.notifiable.user.full_name %> curtiu sua publicação <% else %> - <%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> curtiu seu comentário + <%= notification.notifiable.user.full_name %> curtiu seu comentário <% end %> \ No newline at end of file diff --git a/app/views/notifications/_post.html.erb b/app/views/notifications/_post.html.erb index 22de0f8..cb594d8 100644 --- a/app/views/notifications/_post.html.erb +++ b/app/views/notifications/_post.html.erb @@ -1 +1 @@ -<%= notification.notifiable.user.full_name %> fez uma <%= link_to 'publicação', post_path(notification.notifiable) %> \ No newline at end of file +<%= notification.notifiable.user.full_name %> fez uma publicação \ No newline at end of file diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb index e661738..108b5bb 100644 --- a/app/views/notifications/index.html.erb +++ b/app/views/notifications/index.html.erb @@ -1,18 +1,18 @@
-

Notificações

- <% if @notifications&.any? %> +

<%= Notification.model_name.human(count: 2) %>

+ <% if @notifications.any? %>
    <% @notifications.each do |notification| %> -
  • - <%= render( - partial: "#{notification.notifiable.class.name.downcase}" , - locals: { notification: notification } - )%> - há <%= distance_of_time_in_words_to_now(notification.notifiable.created_at) %> +
  • + <%= button_to notification_path(notification), method: :patch, class: 'btn btn-link' do %> + <%= render( partial: "#{notification.notifiable.class.name.downcase}", + locals: { notification: notification } ) %> + há <%= distance_of_time_in_words_to_now(notification.notifiable.created_at) %> + <% end %>
  • <% end %>
<% else %> -

Nenhuma notificação encontrada

+

<%= t('notifications.no_notifications') %>

<% end %>
diff --git a/config/locales/notifications.pt-BR.yml b/config/locales/notifications.pt-BR.yml index 77f9b52..7b98f92 100644 --- a/config/locales/notifications.pt-BR.yml +++ b/config/locales/notifications.pt-BR.yml @@ -6,5 +6,7 @@ pt-BR: other: 'Notificações' notifications: + no_notifications: 'Nenhuma notificação' + new_follower_mail: '%{follower_name} te seguiu' new_notificaiton: 'Você recebeu uma nova notificação!' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 15daf51..b82d5e2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,7 @@ post '/projects', to: 'projects#create_invitation_request', as: 'invitation_request' resources :job_categories, only: %i[index create destroy] - resources :notifications, only: %i[index] + resources :notifications, only: %i[index update] resources :posts, only: %i[new create] do resources :comments, only: %i[create] diff --git a/db/schema.rb b/db/schema.rb index 111b6e0..81d5037 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -160,7 +160,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "pin", default: 0 - t.datetime "edited_at", default: "2024-02-12 12:29:41" + t.datetime "edited_at", default: "2024-02-13 03:11:57" t.integer "status", default: 0 t.datetime "published_at" t.string "old_status" diff --git a/spec/system/notifications/user_sees_comments_notification_spec.rb b/spec/system/notifications/user_sees_comments_notification_spec.rb index 9eaf027..bc2e27b 100644 --- a/spec/system/notifications/user_sees_comments_notification_spec.rb +++ b/spec/system/notifications/user_sees_comments_notification_spec.rb @@ -5,16 +5,14 @@ user = create(:user) post = create(:post, user:) other_user = create(:user) - comment = create(:comment, post:, user: other_user) + create(:comment, post:, user: other_user) login_as user visit notifications_path expect(Notification.count).to eq 1 expect(page).to have_current_path notifications_path - expect(page).to have_content "comentou em sua publicação: #{post.title}" - expect(page).to have_link post.title, href: post_path(post) - expect(page).to have_link comment.user.profile.full_name, href: profile_path(comment.user.profile) + expect(page).to have_content "#{other_user.full_name} comentou em sua publicação: #{post.title}" end it 'e não vê notificação de seu comentário' do @@ -44,8 +42,8 @@ end expect(page).to have_current_path notifications_path - expect(page).to have_content 'curtiu seu comentário' - expect(page).to have_link like.user.profile.full_name, href: profile_path(like.user.profile) + expect(page).to have_content "#{like.user.full_name} curtiu seu comentário" + expect(Notification.last).to be_seen end it 'e não recebe ao curtir seu próprio comentário' do @@ -64,4 +62,37 @@ expect(page).not_to have_content 'curtiu seu comentário' expect(page).not_to have_link like.user.profile.full_name, href: profile_path(like.user.profile) end + + context 'ao clicar na notificação' do + it 'de comentário é redirecionado para a página do post' do + user = create(:user) + post = create(:post, user:) + comment = create(:comment, post:) + + login_as user + visit notifications_path + click_on comment.user.full_name + + expect(page).to have_current_path post_path(post) + expect(page).to have_content post.title + expect(page).to have_content comment.message + expect(Notification.last).to be_clicked + end + + it 'de curtida é redirecionado para a página do post' do + user = create(:user) + post = create(:post) + comment = create(:comment, post:, user:) + like = create(:like, likeable: comment) + + login_as user + visit notifications_path + click_on like.user.full_name + + expect(page).to have_current_path post_path(post) + expect(page).to have_content post.title + expect(page).to have_content comment.message + expect(Notification.last).to be_clicked + end + end end diff --git a/spec/system/notifications/user_sees_invitation_notification_spec.rb b/spec/system/notifications/user_sees_invitation_notification_spec.rb index 6bca12c..760f2bb 100644 --- a/spec/system/notifications/user_sees_invitation_notification_spec.rb +++ b/spec/system/notifications/user_sees_invitation_notification_spec.rb @@ -10,7 +10,6 @@ expect(page).to have_current_path notifications_path expect(page).to have_content "Você recebeu um convite para #{invitation.project_title} há 1 dia" - expect(page).to have_link invitation.project_title, href: invitation_path(invitation) end it 'e não vê convites de outros usuários' do @@ -28,7 +27,7 @@ expect(page).to_not have_content "Você recebeu um convite para #{other_user_invitation.project_title}" end - it 'ao clicar na notificação é redirecionado para a página de convites' do + it 'ao clicar na notificação é redirecionado para a página do convite' do user = create(:user) invitation = create(:invitation, profile: user.profile) @@ -38,5 +37,6 @@ expect(page).to have_current_path invitation_path(invitation) expect(page).to have_content invitation.project_title + expect(Notification.last).to be_clicked end end diff --git a/spec/system/notifications/user_sees_new_follower_notification_spec.rb b/spec/system/notifications/user_sees_new_follower_notification_spec.rb index 9970da4..5b291c0 100644 --- a/spec/system/notifications/user_sees_new_follower_notification_spec.rb +++ b/spec/system/notifications/user_sees_new_follower_notification_spec.rb @@ -11,6 +11,18 @@ expect(page).to have_current_path notifications_path expect(page).to have_content 'Paulo começou a te seguir' - expect(page).to have_link follower.full_name, href: profile_path(follower) + end + + it 'ao clicar na notificação redireciona para o perfil do seguidor' do + follower = create(:user, full_name: 'Paulo') + followed = create(:user, full_name: 'Ana') + Connection.create!(followed_profile: followed.profile, follower: follower.profile) + + login_as followed + visit notifications_path + click_on 'Paulo começou a te seguir' + + expect(page).to have_current_path profile_path(follower) + expect(Notification.last).to be_clicked end end diff --git a/spec/system/notifications/user_sees_post_notification_spec.rb b/spec/system/notifications/user_sees_post_notification_spec.rb index 28de556..f242c81 100644 --- a/spec/system/notifications/user_sees_post_notification_spec.rb +++ b/spec/system/notifications/user_sees_post_notification_spec.rb @@ -13,7 +13,7 @@ visit notifications_path expect(page).to have_content 'Ana fez uma publicação' - expect(page).to have_link 'publicação', href: post_path(post) + expect(Notification.last).to be_seen end context 'nova publicação notifica seguidores' do @@ -39,8 +39,7 @@ visit notifications_path expect(page).to have_current_path notifications_path - expect(page).to have_content 'curtiu sua publicação' - expect(page).to have_link like.user.full_name, href: profile_path(like.user.profile) + expect(page).to have_content "#{like.user.full_name} curtiu sua publicação" end it 'e não recebe quando curte sua própria publicação' do @@ -54,5 +53,34 @@ expect(page).not_to have_content 'curtiu sua publicação' expect(page).not_to have_link like.user.profile.full_name, href: profile_path(like.user.profile) end + + it 'ao clicar na notificação é redirecionado para a publicação' do + user = create(:user) + post = create(:post, user:) + like = create(:like, likeable: post) + + login_as user + visit notifications_path + click_on "#{like.user.full_name} curtiu sua publicação" + + expect(page).to have_current_path post_path(post) + expect(Notification.last).to be_clicked + end + end + + it 'ao clicar na notificação é redirecionado para a publicação' do + follower = create(:user, full_name: 'Paulo') + followed = create(:user, full_name: 'Ana') + Connection.create!(followed_profile: followed.profile, follower: follower.profile) + post = create(:post, user: followed) + + NewPostNotificationJob.perform_now(post) + + login_as follower + visit notifications_path + click_on 'Ana fez uma publicação' + + expect(page).to have_current_path post_path(post) + expect(Notification.last).to be_clicked end end From 9d2aa9bf6602c3e17961768645cffbb1b4973931 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Date: Tue, 13 Feb 2024 05:40:27 -0300 Subject: [PATCH 5/5] =?UTF-8?q?Adiciona=20tradu=C3=A7=C3=B5es=20nas=20p?= =?UTF-8?q?=C3=A1ginas=20de=20notifica=C3=A7=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -corrige mensagem de tradução do mail no arquivo notification.pt-BR.ylm Co-authored-by: ana resgalla --- app/views/connections_mailer/notify_follow.html.erb | 2 +- app/views/notifications/_comment.html.erb | 2 +- app/views/notifications/_connection.html.erb | 2 +- app/views/notifications/_invitation.html.erb | 2 +- app/views/notifications/_like.html.erb | 4 ++-- app/views/notifications/_post.html.erb | 2 +- app/views/notifications/index.html.erb | 2 +- config/locales/notifications.pt-BR.yml | 11 +++++++---- spec/mailer/connections_mailer_spec.rb | 2 +- .../user_sees_new_follower_notification_spec.rb | 4 ++-- .../notifications/user_sees_notifications_spec.rb | 4 ++-- 11 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/views/connections_mailer/notify_follow.html.erb b/app/views/connections_mailer/notify_follow.html.erb index dc3b139..6620377 100644 --- a/app/views/connections_mailer/notify_follow.html.erb +++ b/app/views/connections_mailer/notify_follow.html.erb @@ -1 +1 @@ -

<%= I18n.t('notifications.new_follower_mail', follower_name: @notification.notifiable.follower.full_name) %>

+

<%= @notification.notifiable.follower.full_name %> <%= t('notifications.started_following_you') %>

diff --git a/app/views/notifications/_comment.html.erb b/app/views/notifications/_comment.html.erb index 4b2dad0..923e7a1 100644 --- a/app/views/notifications/_comment.html.erb +++ b/app/views/notifications/_comment.html.erb @@ -1 +1 @@ -<%= notification.notifiable.user.full_name %> comentou em sua publicação: <%= notification.notifiable.post.title %> \ No newline at end of file +<%= notification.notifiable.user.full_name %> <%= t('notifications.commented_on_your_post') %> <%= notification.notifiable.post.title %> \ No newline at end of file diff --git a/app/views/notifications/_connection.html.erb b/app/views/notifications/_connection.html.erb index dee18fb..91618f7 100644 --- a/app/views/notifications/_connection.html.erb +++ b/app/views/notifications/_connection.html.erb @@ -1 +1 @@ -<%= notification.notifiable.follower.full_name %> começou a te seguir \ No newline at end of file +<%= notification.notifiable.follower.full_name %> <%= t('notifications.started_following_you') %> \ No newline at end of file diff --git a/app/views/notifications/_invitation.html.erb b/app/views/notifications/_invitation.html.erb index 133a41b..1d3cc0d 100644 --- a/app/views/notifications/_invitation.html.erb +++ b/app/views/notifications/_invitation.html.erb @@ -1 +1 @@ -Você recebeu um convite para <%= notification.notifiable.project_title %> \ No newline at end of file +<%= t('notifications.new_invitation_to') %> <%= notification.notifiable.project_title %> \ No newline at end of file diff --git a/app/views/notifications/_like.html.erb b/app/views/notifications/_like.html.erb index d4de84e..57fae01 100644 --- a/app/views/notifications/_like.html.erb +++ b/app/views/notifications/_like.html.erb @@ -1,5 +1,5 @@ <% if notification.notifiable.likeable.is_a?Post %> - <%= notification.notifiable.user.full_name %> curtiu sua publicação + <%= notification.notifiable.user.full_name %> <%= t('notifications.liked_your_post') %> <% else %> - <%= notification.notifiable.user.full_name %> curtiu seu comentário + <%= notification.notifiable.user.full_name %> <%= t('notifications.liked_your_comment') %> <% end %> \ No newline at end of file diff --git a/app/views/notifications/_post.html.erb b/app/views/notifications/_post.html.erb index cb594d8..5dbc716 100644 --- a/app/views/notifications/_post.html.erb +++ b/app/views/notifications/_post.html.erb @@ -1 +1 @@ -<%= notification.notifiable.user.full_name %> fez uma publicação \ No newline at end of file +<%= notification.notifiable.user.full_name %> <%= t('notifications.published_a_new_post') %> \ No newline at end of file diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb index 108b5bb..30dc121 100644 --- a/app/views/notifications/index.html.erb +++ b/app/views/notifications/index.html.erb @@ -13,6 +13,6 @@ <% end %> <% else %> -

<%= t('notifications.no_notifications') %>

+

<%= t('notifications.no_notification') %>

<% end %> diff --git a/config/locales/notifications.pt-BR.yml b/config/locales/notifications.pt-BR.yml index 7b98f92..3628aed 100644 --- a/config/locales/notifications.pt-BR.yml +++ b/config/locales/notifications.pt-BR.yml @@ -6,7 +6,10 @@ pt-BR: other: 'Notificações' notifications: - no_notifications: 'Nenhuma notificação' - - new_follower_mail: '%{follower_name} te seguiu' - new_notificaiton: 'Você recebeu uma nova notificação!' \ No newline at end of file + no_notification: 'Nenhuma notificação' + published_a_new_post: 'fez uma publicação' + liked_your_post: 'curtiu sua publicação' + liked_your_comment: 'curtiu seu comentário' + commented_on_your_post: 'comentou em sua publicação:' + started_following_you: 'começou a seguir você' + new_invitation_to: 'Você recebeu um convite para' diff --git a/spec/mailer/connections_mailer_spec.rb b/spec/mailer/connections_mailer_spec.rb index 8c59276..9656f87 100644 --- a/spec/mailer/connections_mailer_spec.rb +++ b/spec/mailer/connections_mailer_spec.rb @@ -14,7 +14,7 @@ expect(mail.subject).to include 'Alguém seguiu seu perfil' expect(mail.to).to eq [followed_profile.email] expect(mail.from).to eq ['notifications@portfoliorrr.com'] - expect(mail.body).to include 'Danilo Martins te seguiu' + expect(mail.body).to include 'Danilo Martins começou a seguir você' end end end diff --git a/spec/system/notifications/user_sees_new_follower_notification_spec.rb b/spec/system/notifications/user_sees_new_follower_notification_spec.rb index 5b291c0..2e78d64 100644 --- a/spec/system/notifications/user_sees_new_follower_notification_spec.rb +++ b/spec/system/notifications/user_sees_new_follower_notification_spec.rb @@ -10,7 +10,7 @@ visit notifications_path expect(page).to have_current_path notifications_path - expect(page).to have_content 'Paulo começou a te seguir' + expect(page).to have_content 'Paulo começou a seguir você' end it 'ao clicar na notificação redireciona para o perfil do seguidor' do @@ -20,7 +20,7 @@ login_as followed visit notifications_path - click_on 'Paulo começou a te seguir' + click_on 'Paulo começou a seguir você' expect(page).to have_current_path profile_path(follower) expect(Notification.last).to be_clicked diff --git a/spec/system/notifications/user_sees_notifications_spec.rb b/spec/system/notifications/user_sees_notifications_spec.rb index 19996c8..e713708 100644 --- a/spec/system/notifications/user_sees_notifications_spec.rb +++ b/spec/system/notifications/user_sees_notifications_spec.rb @@ -28,12 +28,12 @@ expect(page).to have_current_path notifications_path expect(new_post_notification_job_spy).to have_received(:perform_later) expect(user.profile.notifications.count).to eq 5 - expect(page).to have_content 'começou a te seguir' + expect(page).to have_content 'começou a seguir você' expect(page).to have_content 'curtiu sua publicação' expect(page).to have_content 'comentou em sua publicação' expect(page).to have_content 'curtiu seu comentário' expect(page).to have_content 'Você recebeu um convite' - expect(page.body.index('começou a te seguir')).to be > page.body.index('curtiu sua publicação') + expect(page.body.index('começou a seguir você')).to be > page.body.index('curtiu sua publicação') expect(page.body.index('curtiu sua publicação')).to be > page.body.index('comentou em sua publicação') expect(page.body.index('comentou em sua publicação')).to be > page.body.index('curtiu seu comentário') expect(page.body.index('curtiu seu comentário')).to be > page.body.index('Você recebeu um convite')