Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #109 from LBHackney-IT/ajax-related-repairs
Browse files Browse the repository at this point in the history
Ajaxify the related repairs tab
  • Loading branch information
Ben Wong authored Oct 31, 2018
2 parents 04f79d1 + bdebea3 commit 5244b5d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 56 deletions.
4 changes: 4 additions & 0 deletions app/controllers/api/work_orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def repairs_history
@work_order = Hackney::WorkOrder.find(reference)
end

def related_work_orders
@work_order = WorkOrderFacade.new(reference)
end

private

def reference
Expand Down
29 changes: 29 additions & 0 deletions app/views/api/work_orders/related_work_orders.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<h2 class="govuk-heading-l">
Related repairs
</h2>
<% if @work_order.related_properties.any? %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-full hackney-work-order-related__flex">
<% @work_order.related_properties.sort_by(&:address).each do |property| %>
<div class="hackney-work-order-related__property">
<p class="address">
<%= property.address %><%= '*' if property == @work_order.property %>
</p>
<ul>
<% @work_order.related_for_property(property).sort_by(&:created).reverse.each do |work_order| %>
<li>
<%= link_to work_order.reference,
work_order_path(work_order.reference) %>
<p class="date"><%= work_order.created.to_date.to_s(:govuk_date_short) %></p>
<p class="description"><%= work_order.problem_description %></p>
</li>
<% end %>
</ul>
</div>
<% end %>
</div>
</div>
<% else %>
<p class="govuk-body-s">There are no work orders related to this work order.</p>
<% end %>

38 changes: 10 additions & 28 deletions app/views/work_orders/_work_order_related.html.erb
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
<div class="govuk-tabs__panel hackney-work-order-tabs-info" id="related-tab">
<h2 class="govuk-heading-l">
Related repairs
</h2>
<% if work_order.related_properties.any? %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-full hackney-work-order-related__flex">
<% work_order.related_properties.sort_by(&:address).each do |property| %>
<div class="hackney-work-order-related__property">
<p class="address">
<%= property.address %><%= '*' if property == @work_order.property %>
</p>
<ul>
<% work_order.related_for_property(property).sort_by(&:created).reverse.each do |work_order| %>
<li>
<%= link_to work_order.reference,
work_order_path(work_order.reference) %>
<p class="date"><%= work_order.created.to_date.to_s(:govuk_date_short) %></p>
<p class="description"><%= work_order.problem_description %></p>
</li>
<% end %>
</ul>
</div>
<% end %>
</div>
</div>
<% else %>
<p class="govuk-body-s">There are no work orders related to this work order.</p>
<% end %>
<p class="govuk-caption-m ajax-loading">Loading related work orders data</p>
</div>

<script>
window.addEventListener("load", function() {
var endpoint = "/api/work_orders/<%= work_order.reference %>/related_work_orders"
var ajaxTab = document.getElementById('related-tab');

handleAjaxResponse(endpoint, ajaxTab);
})
</script>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
get :notes_and_appointments
get :documents
get :repairs_history
get :related_work_orders
end
end
end
Expand Down
45 changes: 17 additions & 28 deletions spec/features/work_order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@
stub_hackney_work_orders_for_property(reference: property_reference1)
stub_hackney_work_orders_for_property(reference: property_reference2)
stub_hackney_property_hierarchy(body: property_hierarchy_response)
stub_hackney_repairs_work_orders_by_reference
stub_hackney_repairs_work_orders_by_reference(
references: ["11235813"],
body: [work_order_response_payload("workOrderReference" => "11235813",
"problemDescription" => "A related work order")]
)

sign_in
end
Expand All @@ -51,6 +55,15 @@
work_order_response_payload("workOrderReference" => "87654321", "problemDescription" => "Problem 2"),
])

GraphModelImporter.new('test').import_work_order(work_order_ref: "11235813",
property_ref: property_reference1,
created: Time.current,
target_numbers: [])
GraphModelImporter.new('test').import_note(note_id: 1,
logged_at: Time.current,
work_order_reference: "11235813",
target_numbers: ['01551932'])

fill_in 'Search by work order reference or postcode', with: '01551932'
within('.hackney-search') do
click_on 'Search'
Expand Down Expand Up @@ -80,6 +93,9 @@
click_on('Possibly related')
expect(page).to have_content "01106923\n10 Feb 2014\n11:01am\nWork complete Plumbing PLM RECALL 01097105 FRED DICKENS: Tenant reports that kithcen sink is draining slowly again. REport back where blockag might be."

click_on('Related repairs')
expect(page).to have_content 'A related work order'

click_on('Documents')
expect(page).to have_link("Works order report", count: 3)
expect(page).to have_content 'You must be signed into the internal network to view the documents.'
Expand Down Expand Up @@ -117,20 +133,6 @@
work_order_response_payload("workOrderReference" => "87654321", "problemDescription" => "Problem 2"),
])

stub_hackney_repairs_work_orders_by_reference(
references: ["11235813"],
body: [work_order_response_payload("workOrderReference" => "11235813",
"problemDescription" => "A related work order")]
)
GraphModelImporter.new('test').import_work_order(work_order_ref: "11235813",
property_ref: property_reference1,
created: Time.current,
target_numbers: [])
GraphModelImporter.new('test').import_note(note_id: 1,
logged_at: Time.current,
work_order_reference: "11235813",
target_numbers: ['01551932'])

fill_in 'Search by work order reference or postcode', with: '01551932'
within('.hackney-search') do
click_on 'Search'
Expand All @@ -150,10 +152,6 @@
expect(page).to have_content 'Target date: 27 Jun 2018, 2:09pm'

expect(page).to have_content 'Notes and appointments'

within(find('h2', text: 'Related repairs').find(:xpath, '..')) do
expect(page).to have_content 'A related work order'
end
end

scenario 'Search for a work order by postcode' do
Expand Down Expand Up @@ -289,15 +287,6 @@
end

scenario 'The property is an estate' do
stub_hackney_repairs_work_orders
stub_hackney_repairs_repair_requests
stub_hackney_repairs_properties
stub_hackney_repairs_work_order_block_by_trade
stub_hackney_repairs_work_order_notes
stub_hackney_repairs_work_order_appointments
stub_hackney_repairs_work_order_latest_appointments
stub_hackney_work_orders_for_property
stub_hackney_work_orders_for_property(reference: property_reference1)
stub_hackney_work_orders_for_property(reference: property_reference2, body: work_orders_by_property_reference_payload__different_property)
stub_hackney_property_hierarchy(body: property_hierarchy_response_body__estate)

Expand Down

0 comments on commit 5244b5d

Please sign in to comment.