Skip to content

Commit b016742

Browse files
Merge pull request #2365 from NCCE/3015-i-belong-dropped-achievement-showing-as-in-progress
I Belong dashboard Fix - Dropped Activity
2 parents e132516 + 0ed29b3 commit b016742

File tree

3 files changed

+85
-6
lines changed

3 files changed

+85
-6
lines changed

app/components/cpd_course_item_component.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ def initialize(activity:, current_user:)
1010
@current_user = current_user
1111

1212
@course = Achiever::Course::Template.maybe_find_by_activity_code(activity.stem_activity_code) if activity.stem_activity_code.present?
13-
@achievement = current_user.achievements.to_a.find { _1.activity_id == activity.id }
13+
@achievements = current_user.achievements.where(activity: @activity.id)
14+
15+
@achievement_state = if @achievements.in_state(:complete).any?
16+
:complete
17+
elsif @achievements.in_state(:enrolled).any?
18+
:in_progress
19+
else
20+
:not_started
21+
end
1422
end
1523
end

app/components/cpd_course_item_component/cpd_course_item_component.html.erb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
<div class="cpd-course-item__links">
2626

2727

28-
<% if @achievement %>
29-
<div class="status-tag">
30-
<%= @achievement.complete? ? 'Completed' : 'In progress' %>
31-
</div>
28+
29+
<% if @achievement_state == :complete %>
30+
<div class="status-tag">Completed</div>
31+
<% elsif @achievement_state == :in_progress %>
32+
<div class="status-tag">In progress</div>
3233
<% else %>
3334
<%= link_to "Book now", course_path(id: @activity.stem_activity_code, name: @activity.slug),
3435
class: "govuk-button button" %>

spec/components/cpd_course_item_component_spec.rb

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@
3737
end
3838
end
3939

40+
context "with dropped achievement" do
41+
let!(:achievement) { create(:dropped_achievement, user: current_user, activity:) }
42+
43+
before do
44+
render_inline(described_class.new(activity:, current_user:))
45+
end
46+
47+
it "should render the element" do
48+
expect(page).to have_css(".cpd-course-item")
49+
end
50+
51+
it "should render title" do
52+
expect(page).to have_css(".govuk-body", text: activity.title)
53+
end
54+
55+
it "should render the book now button" do
56+
expect(page).to have_link("Book now", href: "/courses/#{activity.stem_activity_code}/#{activity.slug}")
57+
end
58+
end
59+
4060
context "when complete" do
4161
let!(:achievement) { create(:completed_achievement, user: current_user, activity:) }
4262

@@ -60,12 +80,62 @@
6080
render_inline(described_class.new(activity:, current_user:))
6181
end
6282

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

6787
it "should not show book button" do
6888
expect(page).not_to have_link("Book now", href: "/courses/#{activity.stem_activity_code}/#{activity.slug}")
6989
end
7090
end
91+
92+
context "with dropped achievement and completed" do
93+
let!(:achievement) { create(:dropped_achievement, user: current_user, activity:) }
94+
let!(:achievement) { create(:completed_achievement, user: current_user, activity:) }
95+
96+
before do
97+
render_inline(described_class.new(activity:, current_user:))
98+
end
99+
100+
it "should render the element" do
101+
expect(page).to have_css(".cpd-course-item")
102+
end
103+
104+
it "should render title" do
105+
expect(page).to have_css(".govuk-body", text: activity.title)
106+
end
107+
108+
it "should not show book button" do
109+
expect(page).not_to have_link("Book now", href: "/courses/#{activity.stem_activity_code}/#{activity.slug}")
110+
end
111+
112+
it "should show completed flag" do
113+
expect(page).to have_css(".status-tag", text: "Completed")
114+
end
115+
end
116+
117+
context "with dropped achievement and in_progress" do
118+
let!(:achievement) { create(:dropped_achievement, user: current_user, activity:) }
119+
let!(:achievement) { create(:achievement, user: current_user, activity:) }
120+
121+
before do
122+
render_inline(described_class.new(activity:, current_user:))
123+
end
124+
125+
it "should render the element" do
126+
expect(page).to have_css(".cpd-course-item")
127+
end
128+
129+
it "should render title" do
130+
expect(page).to have_css(".govuk-body", text: activity.title)
131+
end
132+
133+
it "should not show book button" do
134+
expect(page).not_to have_link("Book now", href: "/courses/#{activity.stem_activity_code}/#{activity.slug}")
135+
end
136+
137+
it "should show in progress flag" do
138+
expect(page).to have_css(".status-tag", text: "In progress")
139+
end
140+
end
71141
end

0 commit comments

Comments
 (0)