Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/components/cpd_course_item_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ def initialize(activity:, current_user:)
@current_user = current_user

@course = Achiever::Course::Template.maybe_find_by_activity_code(activity.stem_activity_code) if activity.stem_activity_code.present?
@achievement = current_user.achievements.to_a.find { _1.activity_id == activity.id }
@achievements = current_user.achievements.where(activity: @activity.id)

@achievement_state = if @achievements.in_state(:complete).any?
:complete
elsif @achievements.in_state(:enrolled).any?
:in_progress
else
:not_started
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
<div class="cpd-course-item__links">


<% if @achievement %>
<div class="status-tag">
<%= @achievement.complete? ? 'Completed' : 'In progress' %>
</div>

<% if @achievement_state == :complete %>
<div class="status-tag">Completed</div>
<% elsif @achievement_state == :in_progress %>
<div class="status-tag">In progress</div>
<% else %>
<%= link_to "Book now", course_path(id: @activity.stem_activity_code, name: @activity.slug),
class: "govuk-button button" %>
Expand Down
72 changes: 71 additions & 1 deletion spec/components/cpd_course_item_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@
end
end

context "with dropped achievement" do
let!(:achievement) { create(:dropped_achievement, user: current_user, activity:) }

before do
render_inline(described_class.new(activity:, current_user:))
end

it "should render the element" do
expect(page).to have_css(".cpd-course-item")
end

it "should render title" do
expect(page).to have_css(".govuk-body", text: activity.title)
end

it "should render the book now button" do
expect(page).to have_link("Book now", href: "/courses/#{activity.stem_activity_code}/#{activity.slug}")
end
end

context "when complete" do
let!(:achievement) { create(:completed_achievement, user: current_user, activity:) }

Expand All @@ -60,12 +80,62 @@
render_inline(described_class.new(activity:, current_user:))
end

it "should show completed flag" do
it "should show in progress flag" do
expect(page).to have_css(".status-tag", text: "In progress")
end

it "should not show book button" do
expect(page).not_to have_link("Book now", href: "/courses/#{activity.stem_activity_code}/#{activity.slug}")
end
end

context "with dropped achievement and completed" do
let!(:achievement) { create(:dropped_achievement, user: current_user, activity:) }
let!(:achievement) { create(:completed_achievement, user: current_user, activity:) }

before do
render_inline(described_class.new(activity:, current_user:))
end

it "should render the element" do
expect(page).to have_css(".cpd-course-item")
end

it "should render title" do
expect(page).to have_css(".govuk-body", text: activity.title)
end

it "should not show book button" do
expect(page).not_to have_link("Book now", href: "/courses/#{activity.stem_activity_code}/#{activity.slug}")
end

it "should show completed flag" do
expect(page).to have_css(".status-tag", text: "Completed")
end
end

context "with dropped achievement and in_progress" do
let!(:achievement) { create(:dropped_achievement, user: current_user, activity:) }
let!(:achievement) { create(:achievement, user: current_user, activity:) }

before do
render_inline(described_class.new(activity:, current_user:))
end

it "should render the element" do
expect(page).to have_css(".cpd-course-item")
end

it "should render title" do
expect(page).to have_css(".govuk-body", text: activity.title)
end

it "should not show book button" do
expect(page).not_to have_link("Book now", href: "/courses/#{activity.stem_activity_code}/#{activity.slug}")
end

it "should show in progress flag" do
expect(page).to have_css(".status-tag", text: "In progress")
end
end
end