-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(announces): show Nouveautés link in main navigation
- Loading branch information
Showing
13 changed files
with
224 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/components/main_navigation/announces_link_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
class MainNavigation::AnnouncesLinkComponent < ApplicationComponent | ||
def render? | ||
@most_recent_released_on = load_most_recent_released_on | ||
return false if @most_recent_released_on.nil? | ||
|
||
# also see app/controllers/release_notes_controller.rb#ensure_access_allowed! | ||
return true if helpers.instructeur_signed_in? | ||
return true if helpers.administrateur_signed_in? | ||
return true if helpers.expert_signed_in? | ||
|
||
false | ||
end | ||
|
||
def something_new? | ||
return true if current_user.announces_seen_at.nil? | ||
|
||
@most_recent_released_on.after? current_user.announces_seen_at | ||
end | ||
|
||
def load_most_recent_released_on | ||
categories = helpers.infer_default_announce_categories | ||
|
||
ReleaseNote.most_recent_announce_date_for_categories(categories) | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
app/components/main_navigation/announces_link_component/announces_link_component.en.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
en: | ||
news: News | ||
something_new: New informations about the website may be of interest to you. |
4 changes: 4 additions & 0 deletions
4
app/components/main_navigation/announces_link_component/announces_link_component.fr.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
fr: | ||
news: Nouveautés | ||
something_new: De nouvelles informations à propos du site pourraient vous intéresser. |
4 changes: 4 additions & 0 deletions
4
app/components/main_navigation/announces_link_component/announces_link_component.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
%li.fr-nav__item.fr-nav__notifiable | ||
= link_to t('.news'), release_notes_path, class: "fr-nav__link",'aria-current': current_page?(release_notes_path) ? 'page' : nil | ||
- if something_new? | ||
%span.notifications{ 'aria-label': t('.something_new') } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
spec/components/main_navigation/announces_link_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe MainNavigation::AnnouncesLinkComponent, type: :component do | ||
let(:user) { build(:user) } | ||
let!(:admin_release_note) { create(:release_note, released_on: Date.yesterday, categories: ["administrateur"]) } | ||
let!(:instructeur_release_note) { create(:release_note, released_on: Date.yesterday, categories: ["instructeur"]) } | ||
let(:not_published_release_note) { create(:release_note, published: false, released_on: Date.tomorrow) } | ||
|
||
let(:as_administrateur) { false } | ||
let(:as_instructeur) { false } | ||
|
||
before do | ||
if as_administrateur | ||
user.build_administrateur | ||
end | ||
|
||
if as_instructeur | ||
user.build_instructeur | ||
end | ||
|
||
allow(controller).to receive(:current_user).and_return(user) | ||
end | ||
|
||
subject { render_inline(described_class.new) } | ||
|
||
context 'when signed as simple user' do | ||
it 'does not render the announcements link if not signed in' do | ||
expect(subject.to_html).to be_empty | ||
end | ||
end | ||
|
||
context 'when no signed in' do | ||
let(:current_user) { nil } | ||
|
||
it 'does not render the announcements link if not signed in' do | ||
expect(subject.to_html).to be_empty | ||
end | ||
end | ||
|
||
context 'when instructeur signed in' do | ||
let(:as_instructeur) { true } | ||
|
||
it 'renders the announcements link' do | ||
expect(subject).to have_link("Nouveautés") | ||
end | ||
|
||
context 'when there are new announcements' do | ||
before do | ||
user.announces_seen_at = 5.days.ago | ||
end | ||
|
||
it 'does not render the notification badge' do | ||
expect(subject).to have_link("Nouveautés") | ||
expect(subject).to have_css(".notifications") | ||
end | ||
end | ||
|
||
context 'when there are no new announcements' do | ||
before do | ||
user.announces_seen_at = 1.minute.ago | ||
end | ||
|
||
it 'does not render the notification badge' do | ||
expect(subject).to have_link("Nouveautés") | ||
expect(subject).not_to have_css(".notifications") | ||
end | ||
end | ||
|
||
context 'when there are no announcement at all' do | ||
let(:instructeur_release_note) { nil } | ||
|
||
it 'does not render anything' do | ||
expect(subject.to_html).to be_empty | ||
end | ||
end | ||
end | ||
|
||
context 'when administrateur signed in' do | ||
let(:as_administrateur) { true } | ||
|
||
it 'renders the announcements link' do | ||
expect(subject).to have_link("Nouveautés") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters