Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Merge branch 'main' into itams_fake
Browse files Browse the repository at this point in the history
  • Loading branch information
jduss4 committed Nov 1, 2021
2 parents c7038ab + 2e0ea08 commit 6d1bbf8
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 18 deletions.
14 changes: 14 additions & 0 deletions app/assets/stylesheets/complaints.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
padding: 0 1rem 1rem;
}

.summary-header {
background-color: #f0f0f0;
margin-bottom: 1rem;
a {
color: #2b6289;
text-decoration: none;
padding: 0 1rem;
}
}

.summary-body {
padding: 0 1rem;
}

.usa-process-list__item.usa-process-list__item-disc::before {
border: 0;
color: #1A4480;
Expand Down
4 changes: 2 additions & 2 deletions app/models/api/fake_data/complaint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def data
reopenedDate: datetime_string
},
links: {
self: "https://example.com/TODO",
html: "https://example.com/TODO"
self: "https://example.com/complaint/self/TODO",
html: "https://example.com/complaint/html/TODO"
}
}
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/api/fake_data/grantee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def data
links: {
self: "https://example.com/self/TODO",
html: "https://example.com/html/TODO"
},
relationships: {
issues: {
data: [
Api::FakeData::Complaint.new.data,
Api::FakeData::Complaint.new.data
]
}
}
}
end
Expand Down
37 changes: 35 additions & 2 deletions app/models/complaint.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Complaint
attr_reader :id, :attributes
attr_reader :id, :attributes, :links

EVENT_LABELS = {
issueLastUpdated: "Updated",
Expand All @@ -12,6 +12,15 @@ class Complaint
def initialize(hses_complaint)
@id = hses_complaint[:id]
@attributes = hses_complaint[:attributes].with_indifferent_access
@links = hses_complaint[:links].with_indifferent_access
end

def formatted_creation_date
creation_date&.strftime("%m/%d/%Y")
end

def formatted_issue_last_updated
issue_last_updated&.strftime("%m/%d/%Y")
end

def due_date?
Expand Down Expand Up @@ -42,6 +51,18 @@ def relative_due_date_html
end
end

def hses_link
links[:html]
end

def priority
attributes[:priority][:label]
end

def status
attributes[:status][:label]
end

def summary
attributes[:summary]
end
Expand All @@ -59,7 +80,19 @@ def due_date
end

def formatted_due_date
due_date.strftime("%m/%d/%Y")
due_date&.strftime("%m/%d/%Y")
end

def creation_date
Date.parse(attributes[:creationDate])
rescue
nil
end

def issue_last_updated
Date.parse(attributes[:issueLastUpdated])
rescue
nil
end

def relative_time_til_due
Expand Down
10 changes: 10 additions & 0 deletions app/models/grantee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def region
attributes[:region]
end

def complaints
relationships[:issues][:data].map do |complaint_hash|
Complaint.new(complaint_hash)
end
end

private

def attributes
Expand All @@ -40,4 +46,8 @@ def grantee_data
def links
grantee_data[:links] || {}
end

def relationships
grantee_data[:relationships] || {}
end
end
3 changes: 1 addition & 2 deletions app/views/complaints/_complaints_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</thead>
<tbody>
<% @complaints.each do |complaint| %>
<%= render 'complaints/complaints_table_detail', :complaint => complaint %>
<%= render "complaints/complaints_table_detail", complaint: complaint %>
<% end %>
</tbody>
</table>
Expand All @@ -27,4 +27,3 @@
<%= render partial: 'complaints/pagination', locals: {pagy: @pagy} %>

<p class="margin-bottom-3" id="caption">Complaints associated with this user. Data for illustration purposes only.</p>

4 changes: 2 additions & 2 deletions app/views/complaints/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<%# SUMMARY %>

<div class="grid-col-4">
<div class="summary-section">
<div class="summary-section summary-body">
<div class="ct-section-divider">
<h2>Summary</h2>
<p>
Expand Down Expand Up @@ -55,7 +55,7 @@
<%# STATUS AND TIMELINE %>

<div class="grid-col-8">
<div class="summary-section">
<div class="summary-section summary-body">
<h2 class="ct-section-divider ct-timeline__two-part-container">
<%= status(@complaint.attributes) %>
<span class="ct-timeline__date">
Expand Down
35 changes: 35 additions & 0 deletions app/views/grantees/_complaints_list_detail.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<div class="summary-section">
<div class="summary-header complaints-list-detail-header">
<a href="<%= complaint.hses_link %>" target="_blank" class="display-flex flex-justify flex-align-center">
<h2>Complaint #<%= complaint.id %></h2>
<div>
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
<use xlink:href="/assets/img/sprite.svg#arrow_forward"></use>
</svg>
</div>
</a>
</div>
<div class="summary-body">
<div class="grid-row grid-gap">
<div class="grid-col-7">
<div>
<span class="usa-tag"><%= complaint.priority %> </span>
<span class="usa-tag"><%= complaint.status %> </span>
</div>
<p class="usa-prose">
<%= complaint.summary %>
</p>
</div>
<div class="grid-col-5">
<div class="display-flex flex-justify">
<strong> Opened:</strong>
<span><%= complaint.formatted_creation_date %> </span>
</div>
<div class="display-flex flex-justify">
<strong> Last Updated:</strong>
<span><%= complaint.formatted_issue_last_updated %> </span>
</div>
</div>
</div>
</div>
</div>
12 changes: 4 additions & 8 deletions app/views/grantees/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="details-body grid-container">
<div class="grid-row grid-gap">
<div class="grid-col-4">
<div class="summary-section">
<div class="summary-section summary-body">
<div class="ct-section-divider">
<h2>Summary</h2>
<p class="display-flex flex-justify">
Expand All @@ -22,21 +22,17 @@
class="usa-button width-full" target="_blank">Open in HSES</a>
</div>
</div>
<div class="summary-section">
<div class="summary-section summary-body">
<div class="ct-section-divider">
<h2>Open Issues</h2>
</div>
</div>
</div>
<div class="grid-col-8">
<ul class="usa-process-list">
<% (1..@grantee.complaints_per_fy).each do |index| %>
<% @grantee.complaints.each do |complaint| %>
<li>
<div class="summary-section">
<div class="ct-section-divider">
<h2> Complaint <%= index %> </h2>
</div>
</div>
<%= render "complaints_list_detail", complaint: complaint %>
</li>
<% end %>
</ul>
Expand Down
16 changes: 16 additions & 0 deletions spec/models/grantee_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,20 @@
end
end
end

context "with associations" do
subject { described_class.new(id) }

before do
expect(ApiDelegator).to receive(:use).with("hses", "grantee", {id: id}).and_return delegator
expect(delegator).to receive(:request).and_return response
expect(response).to receive(:data).and_return hses_grantee
end

describe "complaints" do
it "delegates to the relationships" do
expect(subject.complaints.size).to eq 2
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

RSpec.describe "rendering complaints table" do
let(:complaint) { Api::FakeData::Complaint.new.data }

describe "a new complaint" do
it "has a bold id" do
complaint[:attributes][:creationDate] = 1.day.ago.strftime("%FT%TZ")
Expand Down
12 changes: 12 additions & 0 deletions spec/views/grantees/_complaints_list_detail.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require "rails_helper"

RSpec.describe "rendering complaints list" do
let(:hses_complaint) { Api::FakeData::Complaint.new.data }
let(:complaint) { Complaint.new(hses_complaint) }

it "displays a complaint card" do
render partial: "grantees/complaints_list_detail", locals: {complaint: complaint}
complaint_header = "<h2>Complaint ##{complaint.id}</h2>"
expect(rendered.squish).to match complaint_header
end
end
12 changes: 10 additions & 2 deletions spec/views/grantees/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
RSpec.describe "grantees/show", type: :view do
let(:id) { "fake-grantee-789" }
let(:grantee) { Grantee.new(id) }
let(:complaint) { grantee.complaints.first }

before do
assign(:grantee, grantee)
Expand Down Expand Up @@ -32,7 +33,14 @@
expect(rendered).to match "<h2>Open Issues</h2>"
end

it "displays the complaints list" do
expect(rendered).to match '<ul class="usa-process-list">'
describe "complaints list" do
it "displays the list" do
expect(rendered).to match '<ul class="usa-process-list">'
end

it "displays the complaint list item" do
complaint_header = "<h2>Complaint ##{complaint.id}</h2>"
expect(rendered).to match complaint_header
end
end
end

0 comments on commit 6d1bbf8

Please sign in to comment.