Skip to content

Commit

Permalink
Merge pull request #2237 from NCCE/2900-implement-teach-computing-pri…
Browse files Browse the repository at this point in the history
…mary-dashboard---pending-completed-states

Creating new pending/complete state components
  • Loading branch information
msquance-stem authored Dec 16, 2024
2 parents 0e224e0 + 4cf5041 commit d811cae
Show file tree
Hide file tree
Showing 27 changed files with 409 additions and 26 deletions.
28 changes: 28 additions & 0 deletions app/components/programme_status_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

class ProgrammeStatusComponent < ViewComponent::Base
def initialize(user_programme_enrolment:)
@user_programme_enrolment = user_programme_enrolment
@cms_programme_model = Cms::Collections::Programme.get(@user_programme_enrolment.programme.slug)
end

def render?
@user_programme_enrolment.in_state?(:pending) || @user_programme_enrolment.in_state?(:complete)
end

def title
if @user_programme_enrolment.in_state?(:pending)
@cms_programme_model.status_pending_title.value
else
@cms_programme_model.status_completed_title.value
end
end

def content
if @user_programme_enrolment.in_state?(:pending)
@cms_programme_model.status_pending_text
else
@cms_programme_model.status_completed_text
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

<%= render GovGridRowComponent.new(additional_classes: "programme-status-wrapper", background_color: "white") do |row| %>
<%= row.with_column("two-thirds") do %>
<div class="programme-status-wrapper__title-row">
<h2 class="govuk-heading-m"><%= title %></h2>
<% if @user_programme_enrolment.in_state?(:complete) %>
<%= image_pack_tag "media/images/icons/programme_completed_icon.svg" %>
<% end %>
</div>
<%= render content.render %>
<% end %>
<%= row.with_column("one-third") do %>
<% if @user_programme_enrolment.in_state?(:complete) %>
<div class="programme-status-wrapper__button-container">
<%= link_to 'Download your certificate', @user_programme_enrolment.programme.certificate_path,
class: 'govuk-button button', role: 'button' %></p>
</div>
<% end %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.programme-status-wrapper {

&__title-row {
display: flex;
flex-direction: row;
align-items: center;
margin-bottom: 15px;
gap: 20px;

h2 {
margin-bottom: 0;
}
}

&__button-container {
padding-top: 50px;
text-align: center;
}
}
4 changes: 0 additions & 4 deletions app/models/programme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ def user_is_eligible?(user)
true
end

def enrichment_enabled?
false
end

def programme_objectives
programme_activity_groupings.includes(:programme_activities).order(:sort_key)
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/programmes/a_level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@ def achievement_type
def enrolment_confirmation_required?
false
end

def certificate_path
certificate_a_level_path
end
end
end
4 changes: 4 additions & 0 deletions app/models/programmes/cs_accelerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,9 @@ def achievement_type
def enrolment_confirmation_required?
false
end

def certificate_path
certificate_cs_accelerator_certificate_path
end
end
end
4 changes: 4 additions & 0 deletions app/models/programmes/i_belong.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,9 @@ def achievement_type
def enrolment_confirmation_required?
false
end

def certificate_path
certificate_i_belong_path
end
end
end
8 changes: 4 additions & 4 deletions app/models/programmes/primary_certificate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ def pathways?
true
end

def enrichment_enabled?
true
end

def send_pending_mail?
true
end
Expand All @@ -57,5 +53,9 @@ def achievement_type
def enrolment_confirmation_required?
true
end

def certificate_path
certificate_primary_certificate_path
end
end
end
8 changes: 4 additions & 4 deletions app/models/programmes/secondary_certificate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ def pathways?
true
end

def enrichment_enabled?
true
end

def programme_objectives
[
ProgrammeObjectives::ProgrammeCompletionRequired.new(
Expand All @@ -68,5 +64,9 @@ def achievement_type
def enrolment_confirmation_required?
false
end

def certificate_path
certificate_secondary_certificate_path
end
end
end
33 changes: 33 additions & 0 deletions app/services/cms/collections/programme.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Cms
module Collections
class Programme < Resource
def to_search_record(index_time)
raise NotImplementedError
end

def self.is_collection = true

def self.collection_attribute_mappings
[]
end

def self.resource_attribute_mappings
[
{model: Models::Slug, key: nil, param_name: :slug},
{model: Models::TextField, key: :statusPendingTitle},
{model: Models::TextBlock, key: :statusPendingText, with_wrapper: false},
{model: Models::TextField, key: :statusCompletedTitle},
{model: Models::TextBlock, key: :statusCompletedText, with_wrapper: false}
]
end

def self.cache_expiry
15.minutes
end

def self.resource_key
"programmes"
end
end
end
end
15 changes: 15 additions & 0 deletions app/services/cms/models/text_field.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Cms
module Models
class TextField
attr_accessor :value

def initialize(value:)
@value = value
end

def render
# has no render method, this exists just to provide data to model
end
end
end
end
9 changes: 8 additions & 1 deletion app/services/cms/providers/strapi/factories/model_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ def self.process_model(mapping, all_data)
to_seo(strapi_data)
elsif model_class == Models::Slug
model_class.new(slug: strapi_data[:slug])
elsif model_class == Models::TextField
model_class.new(value: strapi_data)
elsif model_class == Models::FeaturedImage
to_featured_image(strapi_data[:data][:attributes]) if strapi_data[:data]
elsif model_class == Models::TextBlock
to_content_block(strapi_data)
with_wrapper = if mapping.key?(:with_wrapper)
mapping[:with_wrapper]
else
true
end
to_content_block(strapi_data, with_wrapper:)
elsif model_class == Models::SimpleTitle
model_class.new(title: strapi_data)
elsif model_class == Models::Aside
Expand Down
15 changes: 15 additions & 0 deletions app/services/cms/providers/strapi/mocks/programme.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Cms
module Providers
module Strapi
module Mocks
class Programme < StrapiMock
attribute(:slug) { Faker::Internet.slug }
attribute(:statusPendingTitle) { Faker::Internet.slug }
attribute(:statusPendingText) { RichBlocks.generate_data }
attribute(:statusCompletedTitle) { Faker::Internet.slug }
attribute(:statusCompletedText) { RichBlocks.generate_data }
end
end
end
end
end
20 changes: 20 additions & 0 deletions app/services/cms/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ def to_search_record(index_time)
raise NotImplementedError
end

def respond_to_missing?(method_name, include_private = false)
self.class.param_indexes.key?(method_name) || super
end

def method_missing(method_name)
index = self.class.param_indexes[method_name]
data_models[index]
end

def self.param_name(mapping)
return mapping[:param_name] if mapping.has_key?(:param_name)
mapping[:key].to_s.underscore.to_sym
end

def self.param_indexes
resource_attribute_mappings.each_with_object({}).with_index do |(mapping, indexes), index|
indexes[param_name(mapping)] = index
end
end

def self.is_collection = false

def self.resource_attribute_mappings
Expand Down
6 changes: 6 additions & 0 deletions app/webpacker/images/icons/programme_completed_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

class CmsSplitHorizontialCardComponentPreview < ViewComponent::Preview
class CmsSplitHorizontalCardComponentPreview < ViewComponent::Preview
def default
render(CmsSplitHorizontialCardComponent.new(
render(CmsSplitHorizontalCardComponent.new(
section_title: Faker::Lorem.sentence,
card_content: Cms::Mocks::RichBlocks.as_model,
aside_content: Cms::Mocks::RichBlocks.as_model,
Expand Down
27 changes: 27 additions & 0 deletions previews/components/programme_status_component_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class ProgrammeStatusComponentPreview < ViewComponent::Preview
class UPEMock
def initialize(status)
@status = status
end

def in_state?(status)
@status == status
end

def programme = Programme.primary_certificate
end

def pending
user_programme_enrolment = UPEMock.new(:pending)
render(
ProgrammeStatusComponent.new(user_programme_enrolment:)
)
end

def complete
user_programme_enrolment = UPEMock.new(:complete)
render(
ProgrammeStatusComponent.new(user_programme_enrolment:)
)
end
end
60 changes: 60 additions & 0 deletions spec/components/programme_status_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require "rails_helper"

RSpec.describe ProgrammeStatusComponent, type: :component do
let(:programme) { create(:primary_certificate) }

before do
stub_strapi_programme(programme.slug, programme: Cms::Mocks::Programme.generate_raw_data(
status_pending_title: "Pending title",
status_completed_title: "Completed title"
))
end

context "Enrolment enrolled" do
let(:user_programme_enrolment) { create(:user_programme_enrolment, programme:) }

before do
render_inline(described_class.new(user_programme_enrolment:))
end

it "should not render" do
expect(page).not_to have_css(".programme-status-wrapper")
end
end

context "Enrolment Pending" do
let(:user_programme_enrolment) { create(:pending_enrolment, programme:) }

before do
render_inline(described_class.new(user_programme_enrolment:))
end

it "should render the wrapper" do
expect(page).to have_css(".programme-status-wrapper")
end

it "should render the correct heading" do
expect(page).to have_css("h2.govuk-heading-m", text: "Pending title")
end
end

context "Enrolment completed" do
let(:user_programme_enrolment) { create(:completed_enrolment, programme:) }

before do
render_inline(described_class.new(user_programme_enrolment:))
end

it "should render the wrapper" do
expect(page).to have_css(".programme-status-wrapper")
end

it "should render the correct heading" do
expect(page).to have_css("h2.govuk-heading-m", text: "Completed title")
end

it "should render cerficate button" do
expect(page).to have_link("Download your certificate", href: "/certificate/primary-certificate/view-certificate")
end
end
end
8 changes: 0 additions & 8 deletions spec/models/programme_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,6 @@
end
end

describe "#enrichment_enabled?" do
let(:programme) { create(:programme) }

it "should return false" do
expect(programme.enrichment_enabled?).to be false
end
end

describe "#certificate_name" do
it "should return not implemented error" do
expect { generic_programme.certificate_name }.to raise_error(NotImplementedError)
Expand Down
Loading

0 comments on commit d811cae

Please sign in to comment.