Skip to content

Commit

Permalink
Add new module indicator tag
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-coggin committed Nov 23, 2023
1 parent 2aeffca commit 737addb
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
10 changes: 10 additions & 0 deletions app/assets/stylesheets/card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ Progress bar
max-width: 300px;
}

.govuk-tag--ey {
width: min-content;
margin: 5px 0;
}

&-container {
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -108,6 +113,11 @@ Progress bar
.bar-ball {
background-color: govuk-colour('yellow');
}

.govuk-tag {
background-color: govuk-colour('light-grey');
color: govuk-colour('blue');
}
}

&:hover &-link--retake {
Expand Down
11 changes: 8 additions & 3 deletions app/services/course_progress.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def completed_modules
end
end

# @return [Array<Training::Module>] Modules released since user's last visit
def new_modules
available_modules.select { |mod| new_module?(mod) }
end

# @return [Boolean]
def course_completed?
published_modules.all? { |mod| completed?(mod) }
Expand Down Expand Up @@ -61,10 +66,10 @@ def completed?(mod)
# @param mod [Training::Module]
# @return [Boolean] module released since user's last visit
def new_module?(mod)
return false unless user.visits.any?
return false unless user.visits.count > 1

mod_release = ModuleRelease.find_by(module_position: mod.position)
last_visit = user.visits.last
last_visit = user.visits.order(started_at: :desc).second
last_visit.started_at < mod_release.first_published_at
end

Expand Down
3 changes: 2 additions & 1 deletion app/views/learning/_card.html.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.card
.card-container
= training_module_image(mod)

- if current_user.course.new_module?(mod)
span.govuk-tag.govuk-tag--ey NEW
h3.govuk-heading-s
= govuk_link_to mod.card_title, training_module_path(mod.name), no_visited_state: true, class: 'card-link--header'

Expand Down
5 changes: 4 additions & 1 deletion app/views/learning/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
hr.govuk-section-break.govuk-section-break--visible.govuk-section-break--l
#available.govuk-grid-row
.govuk-grid-column-full
h2.govuk-heading-m Available modules
h2.govuk-heading-m
| Available modules
- if current_user.course.new_modules.any?
span.govuk-tag class="govuk-!-margin-left-1" NEW MODULE AVAILABLE
- if current_user.course.available_modules.any?
.grid-container
- current_user.course.available_modules.each do |mod|
Expand Down
37 changes: 37 additions & 0 deletions spec/services/course_progress_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

include_context 'with progress'

before do
create(:release, id: 1)
create(:module_release, release_id: 1, module_position: 1, name: 'alpha', first_published_at: 2.days.ago)
create(:release, id: 2)
create(:module_release, release_id: 2, module_position: 2, name: 'bravo', first_published_at: 3.days.ago)
create(:release, id: 3)
create(:module_release, release_id: 3, module_position: 3, name: 'charlie', first_published_at: 2.minutes.ago)
end

describe '#course_completed?' do
it 'is false for new users' do
expect(course.course_completed?).to be false
Expand Down Expand Up @@ -93,4 +102,32 @@
end
end
end

describe '#new_modules' do
context 'with a new user' do
it 'returns no modules' do
expect(course.new_modules).to be_empty
end
end

context 'with a user who has visited before' do
before do
create :visit,
id: 1,
visitor_token: '123',
user_id: user.id,
started_at: 1.day.ago

create :visit,
id: 2,
visitor_token: '456',
user_id: user.id,
started_at: 1.minute.ago
end

it 'returns modules released since the user\'s last visit' do
expect(course.new_modules.map(&:name)).to eq %w[charlie]
end
end
end
end

0 comments on commit 737addb

Please sign in to comment.