Skip to content

Commit

Permalink
Fix: Display "campaign over" if campaign in past (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
teesloane authored Apr 12, 2024
1 parent 1aeb7e0 commit 011954b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
11 changes: 11 additions & 0 deletions lib/bike_brigade_web/live/campaign_signup_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ defmodule BikeBrigadeWeb.CampaignSignupLive.Show do
Sign up
</.button>
<% end %>
<%= if campaign_in_past(@campaign) do %>
<.button
color={:secondary}
id={"#{@id}-task-over-#{@task.id}"}
size={:xsmall}
class="w-full md:w-28 cursor-not-allowed bg-neutral-100 text-neutral-800"
>
Campaign over
</.button>
<% end %>
</div>
"""
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</span>
</div>

<div class="flex flex-col justify-center px-4 py-2 border-b">
<div class="flex px-4 py-2 items-start border-b space-x-2">
<span>Dropoff Neighbourhood:</span>
<span><%= Locations.neighborhood(t.dropoff_location) %></span>
</div>
Expand Down
28 changes: 20 additions & 8 deletions test/bike_brigade_web/live/campaign_signup_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ defmodule BikeBrigadeWeb.CampaignSignupLiveTest do
end

test "It displays a campaign in a previous week; button says 'Completed'", ctx do
campaign =
fixture(:campaign, %{
program_id: ctx.program.id,
delivery_start: LocalizedDateTime.now() |> DateTime.add(-7, :day),
delivery_end:
LocalizedDateTime.now() |> DateTime.add(-7, :day) |> DateTime.add(60, :second)
})
campaign = make_campaign_in_past(ctx.program.id)

fixture(:task, %{campaign: campaign, rider: nil})

Expand All @@ -63,7 +57,7 @@ defmodule BikeBrigadeWeb.CampaignSignupLiveTest do
end

test "Campaigns with no tasks display correct copy", ctx do
fixture(:campaign, %{program_id: ctx.program.id,})
fixture(:campaign, %{program_id: ctx.program.id})
{:ok, _live, html} = live(ctx.conn, ~p"/campaigns/signup")
assert html =~ "Campaign not ready for signup"
end
Expand Down Expand Up @@ -133,6 +127,16 @@ defmodule BikeBrigadeWeb.CampaignSignupLiveTest do
assert html =~ "Unassign me"
end

test "Rider cannot signup for a task in the past", ctx do
campaign = make_campaign_in_past(ctx.program.id)
task = fixture(:task, %{campaign: campaign, rider: nil})

{:ok, live, html} = live(ctx.conn, ~p"/campaigns/signup/#{campaign.id}/")

assert html =~ "Campaign over"
assert live |> has_element?("#signup-btn-mobile-task-over-#{task.id}")
end

test "we see pertinent task information", ctx do
{:ok, _live, html} = live(ctx.conn, ~p"/campaigns/signup/#{ctx.campaign.id}/")
assert html =~ ctx.task.dropoff_name
Expand All @@ -159,4 +163,12 @@ defmodule BikeBrigadeWeb.CampaignSignupLiveTest do
refute render(live) =~ "Unassign me"
end
end

defp make_campaign_in_past(program_id) do
fixture(:campaign, %{
program_id: program_id,
delivery_start: LocalizedDateTime.now() |> DateTime.add(-7, :day),
delivery_end: LocalizedDateTime.now() |> DateTime.add(-7, :day) |> DateTime.add(60, :second)
})
end
end

0 comments on commit 011954b

Please sign in to comment.