Skip to content
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

Chrisbdetlef/appeals 34018 #19971

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/controllers/case_distribution_levers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class CaseDistributionLeversController < ApplicationController
before_action :verify_access

def acd_lever_index
@acd_levers = CaseDistributionLever.all.to_json
@acd_history = CaseDistributionAuditLeverEntry.past_year.to_json
@acd_levers = CaseDistributionLever.all
@acd_history = CaseDistributionAuditLeverEntry.past_year
@user_is_an_acd_admin = current_user.admin?

render "index"
Expand All @@ -17,7 +17,7 @@ def update_levers_and_history
end

if errors.empty?
render json: { successful: true }
render json: { errors: [], successful: true }
else
render json: { errors: errors, successful: false }
end
Expand Down
8 changes: 5 additions & 3 deletions app/views/case_distribution_levers/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<% content_for :full_page_content do %>
<%= react_component("CaseflowDistributionContent", props: {
param1: "here"
<%= react_component("CaseflowDistribution", props: {
acd_levers: @acd_levers,
acd_history: @acd_history,
user_is_an_acd_admin: @user_is_an_acd_admin
}) %>
<% end %>
HELLLOOOOO

28 changes: 28 additions & 0 deletions client/app/caseflowDistribution/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import PropTypes from 'prop-types';

import CaseflowDistributionContent from './pages/CaseflowDistributionApp';

class CaseflowDistribution extends React.PureComponent {
render() {
console.log("this.props:", this.props)
const {acd_levers, acd_history} = this.props
return (
<div>
<h1>Hello world from CaseflowDistribution index</h1>
<h2>Levers</h2>
<div>{JSON.stringify(acd_levers)}</div>
<div>{JSON.stringify(acd_history)}</div>
<div>{JSON.stringify(acd_history)}</div>
</div>
)
}
}

CaseflowDistribution.propTypes = {
acd_levers: PropTypes.array,
acd_history: PropTypes.array,
user_is_an_acd_admin: PropTypes.bool
}

export default CaseflowDistribution;
18 changes: 12 additions & 6 deletions client/app/caseflowDistribution/pages/CaseflowDistributionApp.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import React from 'react';
import PropTypes from 'prop-types';

const CaseflowDistributionContent = ({param1}) => {
return (
class CaseflowDistributionContent extends React.PureComponent {
render() {
<div className="cf-app-segment cf-app-segment--alt">
<div> {/*Wrapper*/}
<h1>Hello World</h1>
<h1>Hello World From CaseflowDistributionContent</h1>
{this.props.acd_levers.map((lever) => {
<div>{lever.item}</div>
})}
</div>
</div>
);
};

}
}

CaseflowDistributionContent.propTypes = {
param1: PropTypes.any,
acd_levers: PropTypes.array,
acd_history: PropTypes.array,
user_is_an_acd_admin: PropTypes.bool
};

export default CaseflowDistributionContent;
4 changes: 2 additions & 2 deletions client/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import Inbox from 'app/inbox';
import Explain from 'app/explain';
import MPISearch from 'app/mpi/MPISearch';
import Admin from 'app/admin';
import CaseflowDistributionContent from 'app/caseflowDistribution'
import CaseflowDistribution from 'app/caseflowDistribution';

const COMPONENTS = {
// New Version 2.0 Root Component
Expand Down Expand Up @@ -89,7 +89,7 @@ const COMPONENTS = {
Explain,
MPISearch,
Admin,
CaseflowDistributionContent
CaseflowDistribution
};

const componentWrapper = (component) => (props, railsContext, domNodeId) => {
Expand Down
48 changes: 36 additions & 12 deletions spec/controllers/case_distribution_levers_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# frozen_string_literal: true


RSpec.describe CaseDistributionLeversController, :all_dbs, type: :controller do
let!(:admin_user) { User.authenticate!(roles: ["Admin"]) }
let!(:lever_user) { create(:lever_user) }
# //let!(:group_user) { User.authenticate!(roles: ["LeverGroupUser"]) }

let!(:lever1) {create(:case_distribution_lever,
item: "lever_1",
Expand Down Expand Up @@ -41,37 +38,64 @@
update_value: 55,
case_distribution_lever: lever2
)}
let!(:old_audit_lever_entry) {create(:case_distribution_audit_lever_entry,
user: lever_user,
user_name: "john smith",
created_at: "2020-07-01 10:11:01",
title: 'Lever 1',
previous_value: 42,
update_value: 55,
case_distribution_lever: lever2
)}

let!(:levers) {[lever1, lever2]}
let!(:lever_history) {[audit_lever_entry1, audit_lever_entry2]}

before do
end

describe "GET acd_lever_index", :type => :request do
it "redirects the user to the unauthorized page if they are not authorized" do

User.authenticate!(user: create(:user))
get "/acd-controls"

expect(response.status).to eq 302
expect(response.body).to match(/unauthorized/)
end

it "renders a page with the correct levers when user is allowed to view the page" do
it "renders a page with the correct levers, lever history, and user admin status when user is allowed to view the page" do
User.authenticate!(user: lever_user)
get "/acd-controls"

request_levers = @controller.view_assigns["acd_levers"]
request_history = @controller.view_assigns["acd_history"]
request_user_is_an_admin = @controller.view_assigns["user_is_an_acd_admin"]

expect(response.status).to eq 200
expect(response.body).to eq(2)
expect(request_levers.count).to eq(2)
expect(request_levers).to include(lever1)
expect(request_levers).to include(lever2)
expect(request_history.count).to eq(2)
expect(request_history).to include(audit_lever_entry1)
expect(request_history).to include(audit_lever_entry2)
expect(request_history).not_to include(old_audit_lever_entry)
expect(request_user_is_an_admin).to be_falsey
end

it "renders a page with the correct levers when user is an admin" do
User.authenticate!(roles: ["Admin"])
it "renders a page with the correct levers, lever history, and user admin status when user is an admin" do
User.authenticate!(roles: ["System Admin"])
get "/acd-controls"

request_levers = @controller.view_assigns["acd_levers"]
request_history = @controller.view_assigns["acd_history"]
request_user_is_an_admin = @controller.view_assigns["user_is_an_acd_admin"]

expect(response.status).to eq 200
expect(user.roles).to eq(2)
expect(request_levers.count).to eq(2)
expect(request_levers).to include(lever1)
expect(request_levers).to include(lever2)
expect(request_history.count).to eq(2)
expect(request_history).to include(audit_lever_entry1)
expect(request_history).to include(audit_lever_entry2)
expect(request_history).not_to include(old_audit_lever_entry)
expect(request_user_is_an_admin).to be_truthy
end
end

Expand Down
Loading