Skip to content

Commit

Permalink
Improve specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio-e committed Oct 2, 2024
1 parent ece14ba commit c2c2096
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 39 deletions.
2 changes: 1 addition & 1 deletion app/helpers/session_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def current_day_anchor(session_date)
def current_starts_at_filter
return unless current_conference

(current_conference.sessions.starts_at(Date.current).first || current_conference.sessions.order(:starts_at).first)&.starts_at&.to_date
current_conference.sessions.starts_at(Date.current).first&.starts_at&.to_date
end

def current_agenda_session
Expand Down
4 changes: 2 additions & 2 deletions app/models/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class Session < ApplicationRecord
scope :starts_at, ->(date) { where("date(starts_at) = ?", date) }
scope :past, -> { where(ends_at: ...Time.current) }
scope :live, -> { where("? BETWEEN starts_at AND ends_at", Time.current) }
scope :starting_soon, -> { where("starts_at BETWEEN ? and ?", Time.current, 1.hour.from_now) }
scope :upcoming_today, -> { where("date(starts_at) = ? and starts_at > ?", Date.current, Time.current) }
scope :starting_soon, -> { where("starts_at BETWEEN ? AND ?", Time.current, 1.hour.from_now) }
scope :upcoming_today, -> { where("date(starts_at) = ? AND starts_at > ?", Date.current, Time.current) }
scope :live_or_upcoming_today, -> { live.or(upcoming_today) }
scope :publics, -> { where(public: true) }
scope :privates, -> { where(public: false) }
Expand Down
6 changes: 4 additions & 2 deletions app/views/layouts/_bottom_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
class: [
nav_text_class_for([sessions_path, root_path, "/speakers"]),
"flex flex-col items-center justify-center"
]
],
data: { test_id: "sessions_nav" }
) do %>
<%= inline_svg_tag "icons/calendar.svg", class: nav_icon_class_for([sessions_path, root_path, "/speakers"]) %>
Agenda
Expand All @@ -22,7 +23,8 @@
class: [
nav_text_class_for([schedule_path]),
"flex flex-col items-center justify-center"
]
],
data: { test_id: "schedule_nav" }
) do %>
<%= inline_svg_tag "icons/clock.svg", class: nav_icon_class_for([schedule_path]) %>
My Schedule
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_secondary_top_nav.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="flex justify-center w-full px-4 pb-2 bg-white pt-safe-area-2">
<div class="relative flex items-center justify-center w-full max-w-screen-sm">
<%= link_to "javascript:history.back()", class: "absolute left-0 flex items-center py-2" do %>
<%= link_to "javascript:history.back()", class: "absolute left-0 flex items-center py-2", data: { test_id: "back_btn" } do %>
<%= inline_svg_tag("icons/chevron_left.svg", size: "24", class: "fill-red") %>
<span class="ml-1 text-lg italic font-black text-red">Back</span>
<% end %>
Expand Down
12 changes: 6 additions & 6 deletions app/views/sessions/_bookmark.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<% if show_bookmark_button?(session) %>
<% if user_is_an_attendee %>
<%= button_to(
session_attendee_path(session_id: session.id, params: request.params[:starts_at], anchor: session_anchor(session)),
method: :delete, form: { class: "z-10 flex items-center", id: dom_id(session, "bookmark") }
) do %>
session_attendee_path(session_id: session.id, params: request.params[:starts_at], anchor: session_anchor(session)),
method: :delete, form: { class: "z-10 flex items-center" }, data: { test_id: dom_id(session, "bookmark") }
) do %>
<div class="p-2">
<%= inline_svg_tag("icons/bookmark-full.svg") %>
</div>
<% end %>
<% else %>
<%= button_to(
session_attendee_path(session_id: session.id, params: request.params[:starts_at], anchor: session_anchor(session)),
form: { class: "z-10 flex items-center", id: dom_id(session, "bookmark"), }
) do %>
session_attendee_path(session_id: session.id, params: request.params[:starts_at], anchor: session_anchor(session)),
form: { class: "z-10 flex items-center" }, data: { test_id: dom_id(session, "bookmark") }
) do %>
<div class="p-2">
<%= inline_svg_tag("icons/bookmark-outline.svg", class: "") %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/sessions/_card.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%# locals: (session:, user_is_an_attendee:, id_prefix: nil) %>

<div class="relative flex flex-col w-full p-5 mb-4 bg-white rounded-[20px]" id="<%= dom_id(session, id_prefix) %>">
<a href="<%= session_path(session) %>" class="absolute top-0 bottom-0 left-0 right-0 z-0"></a>
<div class="relative flex flex-col w-full p-5 mb-4 bg-white rounded-[20px]">
<a href="<%= session_path(session) %>" class="absolute top-0 bottom-0 left-0 right-0 z-0" data-test-id="<%= dom_id(session, id_prefix) %>"></a>

<%= render partial: "sessions/status", locals: { session: session } %>

Expand Down
3 changes: 2 additions & 1 deletion app/views/sessions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
class: [
"inline-flex items-center py-2 px-4 first:pl-0 rounded-lg min-w-fit",
"group hover:bg-[#FAE7E8]/[0.5] focus:bg-[#FAE7E8]/[0.5]"
]
],
data: { test_id: "speaker_#{speaker.id}" }
) do %>
<% if speaker.image&.attached? %>
<div class="relative flex flex-col items-center justify-center w-8 h-8 bg-center bg-no-repeat bg-cover rounded-full min-w-8 min-h-8" style="background-image: url(<%= url_for(speaker.image) %>)">
Expand Down
2 changes: 1 addition & 1 deletion app/views/user_sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<div class="flex flex-col items-center mb-10">
<%= link_to "Sign up", new_registration_path, class: "font-black italic underline text-white mb-5" %>
<%= link_to "View as guest", sessions_path, class: "font-black italic underline text-white mb-5" %>
<%= link_to "View as guest", sessions_path, class: "font-black italic underline text-white mb-5", data: { test_id: "view_as_guest_btn" } %>
</div>
</div>
</div>
Expand Down
51 changes: 30 additions & 21 deletions spec/system/agenda_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,29 @@
end

it "allows to add and remove sessions to their schedule" do
visit sessions_path
visit schedule_path
expect(page).to have_no_content(session.title)
expect(page).to have_content("You don't have any sessions in your schedule yet")

# Add a session to the schedule
find_dti("sessions_nav").click
find_dti("bookmark_session_#{session.id}").click

find("#bookmark_session_#{session.id}").click
expect(user.sessions).to include(session)
# The session should be added to the schedule
find_dti("schedule_nav").click
expect(page).to have_content(session.title)
expect(page).to have_no_content("No sessions match your current filters")

find("#bookmark_session_#{session.id}").click
expect(user.sessions).not_to include(session)
# Remove session from the schedule
find_dti("bookmark_session_#{session.id}").click
expect(page).to have_no_content(session.title)
expect(page).to have_content("No sessions match your current filters")
end

it "allows user to navigate to session details" do
visit sessions_path

find("#session_#{session.id}").click
find_dti("session_#{session.id}").click
expect(page).to have_current_path(session_path(session))
expect(page).to have_content(session.title)
expect(page).to have_content(session.description.to_plain_text)
Expand Down Expand Up @@ -105,32 +115,31 @@
end

context "when user is not logged in" do
it "redirects user to login" do
visit sessions_path
it "allows the user to use the guest flow" do
visit new_user_session_path
find_dti("view_as_guest_btn").click
expect(page).to have_current_path(sessions_path, ignore_query: true)

find("#bookmark_session_#{session.id}").click
expect(page).to have_current_path(new_user_session_path)
end

it "allows user to navigate to session details" do
visit sessions_path

find("#session_#{session.id}").click
# Session show
find_dti("session_#{session.id}").click
expect(page).to have_current_path(session_path(session))
expect(page).to have_content(session.title)
expect(page).to have_content(session.description.to_plain_text)
end

it "allows user to navigate to speaker details" do
visit sessions_path

# Speaker show
find_dti("speaker_#{speaker.id}").click
expect(page).to have_current_path(speaker_path(speaker.friendly_id))
expect(page).to have_content(speaker.name)
expect(page).to have_content(speaker.bio)

# "Back" button
find_dti("back_btn").click
expect(page).to have_current_path(session_path(session))
find_dti("back_btn").click
expect(page).to have_current_path(sessions_path)
end

context "when opening a private sessions" do
context "when opening a private session" do
let!(:private_session) { create(:session, conference: conference, public: false) }

it "does not show private sessions" do
Expand Down
4 changes: 2 additions & 2 deletions spec/system/schedule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
visit schedule_path
expect(page).to have_content(session.title)

find("#bookmark_session_#{session.id}").click
find_dti("bookmark_session_#{session.id}").click
expect(user.sessions).not_to include(session)
expect(page).to have_no_content(session.title)
end

it "allows user to navigate to session details" do
visit schedule_path

find("#schedule_session_#{session.id}").click
find_dti("schedule_session_#{session.id}").click
expect(page).to have_current_path(session_path(session))
expect(page).to have_content(session.title)
expect(page).to have_content(session.description.to_plain_text)
Expand Down

0 comments on commit c2c2096

Please sign in to comment.