-
Notifications
You must be signed in to change notification settings - Fork 2
New Curriculum Key stages component #2380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
msquance-stem
merged 4 commits into
main
from
3018-curriculum-embed-component-for-strapi
Apr 2, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,29 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class Cms::CurriculumKeyStagesComponent < ViewComponent::Base | ||
| delegate :cms_color_theme_class, to: :helpers | ||
|
|
||
| def initialize(title:, background_color:) | ||
| @title = title | ||
| @background_color = background_color | ||
|
|
||
| @key_stages = begin | ||
| CurriculumClient::Queries::KeyStage.all.key_stages | ||
| rescue | ||
| [] | ||
| end | ||
| end | ||
|
|
||
| def box_classes(key_stage) | ||
| classes = ["curriculum-card"] | ||
| classes << if ["1", "2"].include?(key_stage.level) | ||
| cms_color_theme_class("orange", "left") | ||
| else | ||
| cms_color_theme_class("green", "left") | ||
| end | ||
| end | ||
|
|
||
| def render? | ||
| @key_stages.any? | ||
| end | ||
| end |
24 changes: 24 additions & 0 deletions
24
app/components/cms/curriculum_key_stages_component/curriculum_key_stages_component.html.erb
This file contains hidden or 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,24 @@ | ||
| <%= render GovGridRowComponent.new(background_color: @background_color, additional_classes: "cms-curriculum-key-stages") do |row| %> | ||
| <%= row.with_column("full") do %> | ||
| <h2 class="govuk-heading-m"><%= @title %></h2> | ||
| <div class="govuk-grid-row"> | ||
| <% @key_stages.each do |key_stage| %> | ||
| <div class="govuk-grid-column-one-quarter"> | ||
| <%= content_tag :div, class: box_classes(key_stage) do %> | ||
| <h3 class="govuk-heading-m curriculum-card__title"> | ||
| <%= link_to key_stage.title, curriculum_key_stage_units_path(key_stage_slug: key_stage.slug), class: 'govuk-link ncce-link' %> | ||
| </h3> | ||
| <p class="govuk-body-s curriculum-card__details"> | ||
| <span class='curriculum-card__year'><strong>Year <%= key_stage.years %></strong>, </span> | ||
| <span class='curriculum-card__age'>Age <%= key_stage.ages %></span> | ||
| </p> | ||
| <p class='govuk-body-s curriculum-card__counts'> | ||
| <span class='curriculum-card__unit'>Units: <%= key_stage.unit_count %></span> | ||
| <span class='curriculum-card__lesson'>Lessons: <%= key_stage.lesson_count %></span> | ||
| </p> | ||
| <% end %> | ||
| </div> | ||
| <% end %> | ||
| </div> | ||
| <% end %> | ||
| <% end %> |
57 changes: 57 additions & 0 deletions
57
app/components/cms/curriculum_key_stages_component/curriculum_key_stages_component.scss
This file contains hidden or 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,57 @@ | ||
| .cms-curriculum-key-stages { | ||
|
|
||
| .curriculum-card { | ||
| background-color: $concrete; | ||
| border-left-style: solid; | ||
| border-left-width: 9px; | ||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: center; | ||
|
|
||
| padding: 20px 10px; | ||
| position: relative; | ||
|
|
||
| @include govuk-media-query($from: tablet) { | ||
| margin-bottom: 0; | ||
| min-height: 5.5rem; | ||
| } | ||
|
|
||
| @include govuk-media-query($from: desktop) { | ||
| padding: 20px 10px 20px 25px; | ||
| min-height: inherit; | ||
| } | ||
|
|
||
| &__title { | ||
| font-weight: 500; | ||
| margin-bottom: 0.5rem; | ||
| margin-top: 0; | ||
|
|
||
| @include govuk-media-query($from: desktop) { | ||
| margin-bottom: 1rem; | ||
| } | ||
| } | ||
|
|
||
| &__details { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| margin-bottom: 0; | ||
| flex-direction: row; | ||
|
|
||
| @include govuk-media-query($from: tablet) { | ||
| flex-direction: column; | ||
| } | ||
|
|
||
| @include govuk-media-query($from: desktop) { | ||
| flex-direction: row; | ||
| } | ||
| } | ||
|
|
||
| &__counts { | ||
| padding-top: 16px; | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| margin-bottom: 0; | ||
| flex-direction: column; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
18 changes: 18 additions & 0 deletions
18
app/services/cms/dynamic_components/blocks/curriculum_key_stages.rb
This file contains hidden or 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,18 @@ | ||
| module Cms | ||
| module DynamicComponents | ||
| module Blocks | ||
| class CurriculumKeyStages | ||
| attr_accessor :title, :background_color | ||
|
|
||
| def initialize(title:, background_color:) | ||
| @title = title | ||
| @background_color = background_color | ||
| end | ||
|
|
||
| def render | ||
| Cms::CurriculumKeyStagesComponent.new(title:, background_color:) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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
18 changes: 18 additions & 0 deletions
18
app/services/cms/providers/strapi/mocks/dynamic_components/blocks/curriculum_key_stages.rb
This file contains hidden or 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,18 @@ | ||
| module Cms | ||
| module Providers | ||
| module Strapi | ||
| module Mocks | ||
| module DynamicComponents | ||
| module Blocks | ||
| class CurriculumKeyStages < StrapiMock | ||
| strapi_component "blocks.curriculum-key-stages" | ||
|
|
||
| attribute(:title) { Faker::Lorem.sentence } | ||
| attribute(:bkColor) { nil } | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
22 changes: 22 additions & 0 deletions
22
app/services/cms/providers/strapi/queries/components/blocks/curriculum_key_stages.rb
This file contains hidden or 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,22 @@ | ||
| module Cms | ||
| module Providers | ||
| module Strapi | ||
| module Queries | ||
| module Components | ||
| module Blocks | ||
| class CurriculumKeyStages < BaseComponentQuery | ||
| def self.name = "ComponentBlocksCurriculumKeyStages" | ||
|
|
||
| def self.base_fields | ||
| <<~GRAPHQL.freeze | ||
| cks__title: title | ||
| bkColor | ||
| GRAPHQL | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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
7 changes: 7 additions & 0 deletions
7
previews/components/cms/curriculum_key_stage_component_preview.rb
This file contains hidden or 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,7 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class Cms::CurriculumKeyStagesComponentPreview < ViewComponent::Preview | ||
| def default | ||
| render(Cms::CurriculumKeyStagesComponent.new(title: "title", bk_color: "bk_color")) | ||
| end | ||
| end |
66 changes: 66 additions & 0 deletions
66
spec/components/cms/curriculum_key_stage_component_spec.rb
This file contains hidden or 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,66 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "rails_helper" | ||
|
|
||
| RSpec.describe Cms::CurriculumKeyStagesComponent, type: :component do | ||
| let(:key_stages_json_response) { File.new("spec/support/curriculum/responses/key_stages.json").read } | ||
|
|
||
| before do | ||
| client = CurriculumClient::Connection.connect(ENV.fetch("CURRICULUM_TEST_SCHEMA_PATH")) | ||
| allow(CurriculumClient::Connection).to receive(:connect).and_return(client) | ||
| end | ||
|
|
||
| context "when curriculum is enabled" do | ||
| before do | ||
| stub_a_valid_request(key_stages_json_response) | ||
| render_inline(described_class.new( | ||
| title: "Choose resources by key stage", | ||
| background_color: nil | ||
| )) | ||
| end | ||
| it "renders the title" do | ||
| expect(page).to have_css("h2.govuk-heading-m", text: "Choose resources by key stage") | ||
| end | ||
| it "renders the key stages" do | ||
| expect(page).to have_css(".curriculum-card", count: 4) | ||
| end | ||
|
|
||
| it "sets key_stage 1 and 2 cards to orange" do | ||
| expect(page).to have_css(".cms-color-theme__border--orange-left", text: "Key Stage 1") | ||
| expect(page).to have_css(".cms-color-theme__border--orange-left", text: "Key Stage 2") | ||
| end | ||
|
|
||
| it "sets key_stage 3 and 4 cards to green" do | ||
| expect(page).to have_css(".cms-color-theme__border--green-left", text: "Key Stage 3") | ||
| expect(page).to have_css(".cms-color-theme__border--green-left", text: "Key Stage 4") | ||
| end | ||
| end | ||
|
|
||
| context "when curriculum returns no keyStages" do | ||
| before do | ||
| stub_a_valid_request("{\"data\": { \"keyStages\": [] }}") | ||
| render_inline(described_class.new( | ||
| title: "Choose resources by key stage", | ||
| background_color: nil | ||
| )) | ||
| end | ||
|
|
||
| it "does not render the title" do | ||
| expect(page).not_to have_css("h2.govuk-heading-m", text: "Choose resources by key stage") | ||
| end | ||
| end | ||
|
|
||
| context "when curriculum returns an error" do | ||
| before do | ||
| stub_an_invalid_request | ||
| render_inline(described_class.new( | ||
| title: "Choose resources by key stage", | ||
| background_color: nil | ||
| )) | ||
| end | ||
|
|
||
| it "renders the title" do | ||
| expect(page).not_to have_css("h2.govuk-heading-m", text: "Choose resources by key stage") | ||
| end | ||
| end | ||
| end | ||
18 changes: 18 additions & 0 deletions
18
spec/services/cms/dynamic_components/blocks/curriculum_key_stages_spec.rb
This file contains hidden or 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,18 @@ | ||
| require "rails_helper" | ||
|
|
||
| RSpec.describe Cms::DynamicComponents::Blocks::CurriculumKeyStages do | ||
| let(:key_stages_json_response) { File.new("spec/support/curriculum/responses/key_stages.json").read } | ||
|
|
||
| before do | ||
| client = CurriculumClient::Connection.connect(ENV.fetch("CURRICULUM_TEST_SCHEMA_PATH")) | ||
| allow(CurriculumClient::Connection).to receive(:connect).and_return(client) | ||
| stub_a_valid_request(key_stages_json_response) | ||
| @comp = Cms::Providers::Strapi::Factories::ComponentFactory.process_component( | ||
| Cms::Mocks::DynamicComponents::Blocks::CurriculumKeyStages.generate_raw_data | ||
| ) | ||
| end | ||
|
|
||
| it "should render as Cms::CurriculumKeyStagesComponent" do | ||
| expect(@comp.render).to be_a(Cms::CurriculumKeyStagesComponent) | ||
| end | ||
| end |
9 changes: 9 additions & 0 deletions
9
spec/services/cms/providers/strapi/queries/components/blocks/curriculum_key_stages_spec.rb
This file contains hidden or 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,9 @@ | ||
| require "rails_helper" | ||
|
|
||
| RSpec.describe Cms::Providers::Strapi::Queries::Components::Blocks::CurriculumKeyStages do | ||
| it_should_behave_like "a strapi graphql component", | ||
| %w[ | ||
| title | ||
| bkColor | ||
| ] | ||
| end |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a space between the end and the next context block - very nit picky!