Skip to content

Commit

Permalink
HunJerBAH/APPEALS-17522: Create IssuesUpdate Task Model (#18465)
Browse files Browse the repository at this point in the history
* Created Issues Update task model and methods for formatting instructions

* jHoang/APPEALS-17511 (#18444)

* migration to add mst and pact status to request_issues

* schema update

* typo in migration

* typo in schema

* set default status

* Revert "schema update"

This reverts commit 0d5df1a.

* Revert "typo in schema"

This reverts commit 9a74e6e.

* +1

---------

Co-authored-by: Jonathan Hoang <trinhjoanthan.hoang@va.gov>
Co-authored-by: youfoundmanesh <maneshreddy.kommidi@va.gov>

* Justin/appeals 17512 (#18443)

* feature toggle mst_pact_identification

* toggle added to queue, intake, and hearings erb

* replaced bracket that was accidentally removed

* hearings feature toggle to camelCase to match

* removing merge problems

* APPEALS-17506: MST & PACT Components (#18451)

* APPEALS-17506: MST & PACT Components

* +1

* updated storybook test args for rendering badges

---------

Co-authored-by: HunJerBAH <Jeremy.Hunton@va.gov>

* added issueUpdateTask bool check

* refactored format_instructions method to store in nested array

* refactored instruction logic and updated rendering/styling of task instructions

* updated css styling to match wireframes

* refactored special issue format and created tests

---------

Co-authored-by: jonathanh-va <111081469+jonathanh-va@users.noreply.github.com>
Co-authored-by: Jonathan Hoang <trinhjoanthan.hoang@va.gov>
Co-authored-by: youfoundmanesh <maneshreddy.kommidi@va.gov>
Co-authored-by: sulak-j <95875751+sulak-j@users.noreply.github.com>
Co-authored-by: youfoundmanesh <129548081+youfoundmanesh@users.noreply.github.com>
  • Loading branch information
6 people authored Apr 21, 2023
1 parent 3bd8416 commit 528a0df
Show file tree
Hide file tree
Showing 3 changed files with 251 additions and 1 deletion.
41 changes: 41 additions & 0 deletions app/models/tasks/issues_update_task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

class IssuesUpdateTask < Task
validates :parent, presence: true

def label
"Issues Update Task"
end

def format_instructions(issue_category, original_mst, original_pact, edit_mst, edit_pact, edit_reason)
# format the instructions by loading an array and adding it to the instructions
edit_issue_format = []
edit_issue_format << issue_category
original_comment = "#{format_special_issues_text(original_mst, original_pact)}"
edit_issue_format << original_comment

# format edit
edit_issue_format << issue_category
updated_comment = "#{format_special_issues_text(edit_mst, edit_pact)}"
edit_issue_format << updated_comment

# add edit reason on the end
edit_issue_format << edit_reason

# add edit_issue_format into the instructions array for the task
instructions << edit_issue_format
save!
end

private

def format_special_issues_text(mst_status, pact_status)
# format the special issues comment to display the change in the special issues status(es)
s = "Special Issues:"

return s + " None" if !mst_status && !pact_status
return s + " MST, PACT" if mst_status && pact_status
return s + " MST" if mst_status
return s + " PACT" if pact_status
end
end
33 changes: 32 additions & 1 deletion client/app/queue/components/TaskRows.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ const isCancelled = (task) => {
return task.status === TASK_STATUSES.cancelled;
};

const issueUpdateTask = (task) =>{
return task.type === 'IssuesUpdateTask';
}

const tdClassNames = (timeline, task) => {
const containerClass = timeline ? taskInfoWithIconTimelineContainer : '';
const closedAtClass = task.closedAt ? null : <span className="greyDotTimelineStyling"></span>;
Expand Down Expand Up @@ -304,6 +308,32 @@ class TaskRows extends React.PureComponent {
return text.replace(/<br>|(?<! {2})\n/g, ' \n');
};

// formatting used for IssueUpdate task instructions.
const formatIssueUpdateBreaks = (text = '') => {
const divStyle = { marginTop: '1rem'}
const hStyle = { marginTop: '30px', marginBottom: '0rem', fontWeight: 'bold' };

if (Array.isArray(text)) {
return (
<div style={divStyle}>
<b>Edited Issue:</b>
<h5 style={hStyle}>Original:</h5>
<small>{text[0]}</small>
<br />
<small>{text[1]}</small>
<br />
<h5 style={hStyle}>Updated:</h5>
<small>{text[2]}</small>
<br />
<small>{text[3]}</small>
<br />
<h5 style={hStyle}>Reason for Change:</h5>
<small>{text[4]}</small>
</div>
);
}
};

// We specify the same 2.4rem margin-bottom as paragraphs to each set of instructions
// to ensure a consistent margin between instruction content and the "Hide" button
const divStyles = { marginBottom: '2.4rem' };
Expand All @@ -317,7 +347,8 @@ class TaskRows extends React.PureComponent {
style={divStyles}
className="task-instructions"
>
<ReactMarkdown>{formatBreaks(text)}</ReactMarkdown>
{issueUpdateTask(task) ? (<div>{formatIssueUpdateBreaks(text)}</div>) :
(<ReactMarkdown>{formatBreaks(text)}</ReactMarkdown>)}
</div>
</React.Fragment>
))}
Expand Down
178 changes: 178 additions & 0 deletions spec/models/issues_update_task_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# frozen_string_literal: true

describe IssuesUpdateTask do
let(:user) { create(:user) }
let(:bva_intake) { BvaIntake.singleton }
let(:root_task) { create(:root_task) }
let(:distribution_task) { create(:distribution_task, parent: root_task) }
let(:task_class) { IssuesUpdateTask }

before do
bva_intake.add_user(user)
User.authenticate!(user: user)
FeatureToggle.enable!(:mst_pact_identification)
end

describe ".verify_user_can_create" do
let(:params) { { appeal: root_task.appeal, parent_id: distribution_task&.id, type: task_class.name } }

context "when no root task exists for appeal" do
let(:distribution_task) { nil }

it "throws an error" do
expect { task_class.create!(
appeal: root_task.appeal,
parent_id: distribution_task&.id,
type: task_class.name,
assigned_to: bva_intake,
assigned_by: user) }.to raise_error(ActiveRecord::RecordInvalid)
end
end

context "proper params are sent" do
it "creates the new task" do
expect { task_class.create!(
appeal: root_task.appeal,
parent_id: distribution_task&.id,
type: task_class.name,
assigned_to: bva_intake,
assigned_by: user) }.to change{IssuesUpdateTask.count}.by(1)
end
end

# test contexts for successfully creating task when an appeal has a CC will go here once other tasks are made
end

describe ".format_instructions" do
let(:issues_update_task) do
task_class.create!(
appeal: root_task.appeal,
parent_id: distribution_task&.id,
type: task_class.name,
assigned_to: bva_intake,
assigned_by: user)
end

# clear the instructions after each run
after do
issues_update_task.instructions.clear
issues_update_task.save!
end

context "changes occur to the MST status on an issue" do
let(:params) do
{
issue_category: "test category",
original_mst: false,
original_pact: false,
edit_mst: true,
edit_pact: false,
edit_reason: "reason for edit here..."
}
end

subject { issues_update_task.format_instructions(
params[:issue_category],
params[:original_mst],
params[:original_pact],
params[:edit_mst],
params[:edit_pact],
params[:edit_reason]) }
it "formats the instructions with MST" do
expect(subject).to eql(true)
expect(issues_update_task.instructions[0][0]).to eql("test category")
expect(issues_update_task.instructions[0][1]).to eql("Special Issues: None")
expect(issues_update_task.instructions[0][2]).to eql("test category")
expect(issues_update_task.instructions[0][3]).to eql("Special Issues: MST")
expect(issues_update_task.instructions[0][4]).to eql("reason for edit here...")
end
end

context "changes occur to the PACT status on an issue" do
let(:params) do
{
issue_category: "test category",
original_mst: false,
original_pact: false,
edit_mst: false,
edit_pact: true,
edit_reason: "reason for edit here..."
}
end

subject { issues_update_task.format_instructions(
params[:issue_category],
params[:original_mst],
params[:original_pact],
params[:edit_mst],
params[:edit_pact],
params[:edit_reason]) }
it "formats the instructions with PACT" do
expect(subject).to eql(true)
expect(issues_update_task.instructions[0][0]).to eql("test category")
expect(issues_update_task.instructions[0][1]).to eql("Special Issues: None")
expect(issues_update_task.instructions[0][2]).to eql("test category")
expect(issues_update_task.instructions[0][3]).to eql("Special Issues: PACT")
expect(issues_update_task.instructions[0][4]).to eql("reason for edit here...")
end
end

context "changes occur to the MST and PACT status on an issue" do
let(:params) do
{
issue_category: "test category",
original_mst: false,
original_pact: false,
edit_mst: true,
edit_pact: true,
edit_reason: "reason for edit here..."
}
end

subject { issues_update_task.format_instructions(
params[:issue_category],
params[:original_mst],
params[:original_pact],
params[:edit_mst],
params[:edit_pact],
params[:edit_reason]) }
it "formats the instructions with MST and PACT" do
expect(subject).to eql(true)
expect(issues_update_task.instructions[0][0]).to eql("test category")
expect(issues_update_task.instructions[0][1]).to eql("Special Issues: None")
expect(issues_update_task.instructions[0][2]).to eql("test category")
expect(issues_update_task.instructions[0][3]).to eql("Special Issues: MST, PACT")
expect(issues_update_task.instructions[0][4]).to eql("reason for edit here...")
end
end

context "MST and PACT status on an issue are removed" do
let(:params) do
{
issue_category: "test category",
original_mst: true,
original_pact: true,
edit_mst: false,
edit_pact: false,
edit_reason: "reason for edit here..."
}
end

subject { issues_update_task.format_instructions(
params[:issue_category],
params[:original_mst],
params[:original_pact],
params[:edit_mst],
params[:edit_pact],
params[:edit_reason]) }
it "formats the instructions from MST and PACT to None" do
expect(subject).to eql(true)
expect(issues_update_task.instructions[0][0]).to eql("test category")
expect(issues_update_task.instructions[0][1]).to eql("Special Issues: MST, PACT")
expect(issues_update_task.instructions[0][2]).to eql("test category")
expect(issues_update_task.instructions[0][3]).to eql("Special Issues: None")
expect(issues_update_task.instructions[0][4]).to eql("reason for edit here...")
end
end
end
end

0 comments on commit 528a0df

Please sign in to comment.