-
Notifications
You must be signed in to change notification settings - Fork 193
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 #9841 from alphagov/content-modelling/828-addition…
…al-workflow-iterations (828) Additional workflow iterations
- Loading branch information
Showing
17 changed files
with
178 additions
and
89 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
31 changes: 31 additions & 0 deletions
31
lib/engines/content_block_manager/app/controllers/concerns/workflow.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Workflow | ||
class Step < Data.define(:name, :show_action, :update_action) | ||
ALL = [ | ||
Step.new(:edit_draft, :edit_draft, nil), | ||
Step.new(:review_links, :review_links, :redirect_to_next_step), | ||
Step.new(:schedule_publishing, :schedule_publishing, :validate_schedule), | ||
Step.new(:internal_note, :internal_note, :update_internal_note), | ||
Step.new(:change_note, :change_note, :update_change_note), | ||
Step.new(:review, :review, :validate_review_page), | ||
Step.new(:confirmation, :confirmation, nil), | ||
].freeze | ||
|
||
def self.by_name(name) | ||
ALL.find { |step| step.name == name.to_sym } | ||
end | ||
|
||
def previous_step | ||
ALL[index - 1] | ||
end | ||
|
||
def next_step | ||
ALL[index + 1] | ||
end | ||
|
||
private | ||
|
||
def index | ||
ALL.find_index { |step| step.name == name.to_sym } | ||
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
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
15 changes: 15 additions & 0 deletions
15
lib/engines/content_block_manager/app/helpers/workflow_helper.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module WorkflowHelper | ||
def back_path(content_block_edition, current_step) | ||
if current_step == "review" && content_block_edition.document.is_new_block? | ||
content_block_manager.content_block_manager_content_block_documents_path | ||
else | ||
step = Workflow::Step.by_name(current_step)&.previous_step | ||
return nil unless step | ||
|
||
content_block_manager.content_block_manager_content_block_workflow_path( | ||
content_block_edition, | ||
step: step.name, | ||
) | ||
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
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
46 changes: 46 additions & 0 deletions
46
lib/engines/content_block_manager/test/unit/app/controllers/concerns/workflow_test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require "test_helper" | ||
|
||
class ContentBlockManager::ContentBlock::WorkflowTest < ActiveSupport::TestCase | ||
extend Minitest::Spec::DSL | ||
|
||
describe "Step" do | ||
describe ".by_name" do | ||
it "returns a step by its name" do | ||
step = Workflow::Step.by_name("review_links") | ||
|
||
assert_equal step&.name, :review_links | ||
end | ||
end | ||
|
||
describe "#next_step" do | ||
[ | ||
%i[edit_draft review_links], | ||
%i[review_links schedule_publishing], | ||
%i[schedule_publishing internal_note], | ||
%i[internal_note change_note], | ||
%i[change_note review], | ||
%i[review confirmation], | ||
].each do |current_step, expected_step| | ||
it "returns #{expected_step} step when the current step is #{current_step}" do | ||
step = Workflow::Step.by_name(current_step) | ||
assert_equal step&.next_step&.name, expected_step | ||
end | ||
end | ||
end | ||
|
||
describe "#previous_step" do | ||
[ | ||
%i[review_links edit_draft], | ||
%i[schedule_publishing review_links], | ||
%i[internal_note schedule_publishing], | ||
%i[change_note internal_note], | ||
%i[review change_note], | ||
].each do |current_step, expected_step| | ||
it "returns #{expected_step} step when the current step is #{current_step}" do | ||
step = Workflow::Step.by_name(current_step) | ||
assert_equal step&.previous_step&.name, expected_step | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.