-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2237 from NCCE/2900-implement-teach-computing-pri…
…mary-dashboard---pending-completed-states Creating new pending/complete state components
- Loading branch information
Showing
27 changed files
with
409 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
20 changes: 20 additions & 0 deletions
20
app/components/programme_status_component/programme_status_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
19 changes: 19 additions & 0 deletions
19
app/components/programme_status_component/programme_status_component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
previews/components/cms_split_horizontal_card_component_preview.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.