21 changed files with 604 additions and 122 deletions
			
			
		@ -1,35 +1,37 @@
					 | 
				
			||||
<%= govuk_table do |table| %> | 
				
			||||
  <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> | 
				
			||||
    <% if searched.present? %> | 
				
			||||
      <strong><%= pagy.count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= total_count %></strong> total organisations. <%= govuk_link_to("Clear search", request.path) %> | 
				
			||||
    <% else %> | 
				
			||||
      <strong><%= pagy.count %></strong> total organisations. | 
				
			||||
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>"> | 
				
			||||
  <%= govuk_table do |table| %> | 
				
			||||
    <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> | 
				
			||||
      <% if searched.present? %> | 
				
			||||
        <strong><%= pagy.count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= total_count %></strong> total organisations. <%= govuk_link_to("Clear search", request.path) %> | 
				
			||||
      <% else %> | 
				
			||||
        <strong><%= pagy.count %></strong> total organisations. | 
				
			||||
      <% end %> | 
				
			||||
    <% end %> | 
				
			||||
  <% end %> | 
				
			||||
  <%= table.head do |head| %> | 
				
			||||
    <%= head.row do |row| %> | 
				
			||||
      <% row.cell(header: true, text: "Name", html_attributes: { | 
				
			||||
        scope: "col", | 
				
			||||
      }) %> | 
				
			||||
      <% row.cell(header: true, text: "Registration number", html_attributes: { | 
				
			||||
        scope: "col", | 
				
			||||
      }) %> | 
				
			||||
      <% row.cell(header: true, text: "Type", html_attributes: { | 
				
			||||
        scope: "col", | 
				
			||||
      }) %> | 
				
			||||
    <%= table.head do |head| %> | 
				
			||||
      <%= head.row do |row| %> | 
				
			||||
        <% row.cell(header: true, text: "Name", html_attributes: { | 
				
			||||
          scope: "col", | 
				
			||||
        }) %> | 
				
			||||
        <% row.cell(header: true, text: "Registration number", html_attributes: { | 
				
			||||
          scope: "col", | 
				
			||||
        }) %> | 
				
			||||
        <% row.cell(header: true, text: "Type", html_attributes: { | 
				
			||||
          scope: "col", | 
				
			||||
        }) %> | 
				
			||||
      <% end %> | 
				
			||||
    <% end %> | 
				
			||||
  <% end %> | 
				
			||||
  <% @organisations.each do |organisation| %> | 
				
			||||
    <%= table.body do |body| %> | 
				
			||||
      <%= body.row do |row| %> | 
				
			||||
        <% row.cell(header: true, html_attributes: { | 
				
			||||
          scope: "row", | 
				
			||||
        }) do %> | 
				
			||||
          <%= govuk_link_to(organisation.name, "organisations/#{organisation.id}/logs") %> | 
				
			||||
    <% @organisations.each do |organisation| %> | 
				
			||||
      <%= table.body do |body| %> | 
				
			||||
        <%= body.row do |row| %> | 
				
			||||
          <% row.cell(header: true, html_attributes: { | 
				
			||||
            scope: "row", | 
				
			||||
          }) do %> | 
				
			||||
            <%= govuk_link_to(organisation.name, "organisations/#{organisation.id}/logs") %> | 
				
			||||
          <% end %> | 
				
			||||
          <% row.cell(text: organisation.housing_registration_no) %> | 
				
			||||
          <% row.cell(text: organisation.display_provider_type) %> | 
				
			||||
        <% end %> | 
				
			||||
        <% row.cell(text: organisation.housing_registration_no) %> | 
				
			||||
        <% row.cell(text: organisation.display_provider_type) %> | 
				
			||||
      <% end %> | 
				
			||||
    <% end %> | 
				
			||||
  <% end %> | 
				
			||||
<% end %> | 
				
			||||
</section> | 
				
			||||
					 | 
				
			||||
@ -1,54 +1,56 @@
					 | 
				
			||||
<%= govuk_table do |table| %> | 
				
			||||
  <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> | 
				
			||||
    <span class="govuk-!-margin-right-4"> | 
				
			||||
      <% if searched.present? %> | 
				
			||||
        <strong><%= pagy.count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= total_count %></strong> total users. <%= govuk_link_to("Clear search", request.path) %> | 
				
			||||
      <% else %> | 
				
			||||
        <strong><%= pagy.count %></strong> total users. | 
				
			||||
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>"> | 
				
			||||
  <%= govuk_table do |table| %> | 
				
			||||
    <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> | 
				
			||||
      <span class="govuk-!-margin-right-4"> | 
				
			||||
        <% if searched.present? %> | 
				
			||||
          <strong><%= pagy.count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= total_count %></strong> total users. <%= govuk_link_to("Clear search", request.path) %> | 
				
			||||
        <% else %> | 
				
			||||
          <strong><%= pagy.count %></strong> total users. | 
				
			||||
        <% end %> | 
				
			||||
      </span> | 
				
			||||
      <% if current_user.support? %> | 
				
			||||
        <% query = searched.present? ? "?search=#{searched}" : nil %> | 
				
			||||
        <%= govuk_link_to "Download (CSV)", "/users.csv#{query}", type: "text/csv" %> | 
				
			||||
      <% end %> | 
				
			||||
    </span> | 
				
			||||
    <% if current_user.support? %> | 
				
			||||
      <% query = searched.present? ? "?search=#{searched}" : nil %> | 
				
			||||
      <%= govuk_link_to "Download (CSV)", "/users.csv#{query}", type: "text/csv" %> | 
				
			||||
    <% end %> | 
				
			||||
  <% end %> | 
				
			||||
  <%= table.head do |head| %> | 
				
			||||
    <%= head.row do |row| %> | 
				
			||||
      <% row.cell(header: true, text: "Name and email adress", html_attributes: { | 
				
			||||
        scope: "col", | 
				
			||||
      }) %> | 
				
			||||
      <% row.cell(header: true, text: "Organisation and role", html_attributes: { | 
				
			||||
        scope: "col", | 
				
			||||
      }) %> | 
				
			||||
      <% row.cell(header: true, text: "Last logged in", html_attributes: { | 
				
			||||
        scope: "col", | 
				
			||||
      }) %> | 
				
			||||
    <%= table.head do |head| %> | 
				
			||||
      <%= head.row do |row| %> | 
				
			||||
        <% row.cell(header: true, text: "Name and email adress", html_attributes: { | 
				
			||||
          scope: "col", | 
				
			||||
        }) %> | 
				
			||||
        <% row.cell(header: true, text: "Organisation and role", html_attributes: { | 
				
			||||
          scope: "col", | 
				
			||||
        }) %> | 
				
			||||
        <% row.cell(header: true, text: "Last logged in", html_attributes: { | 
				
			||||
          scope: "col", | 
				
			||||
        }) %> | 
				
			||||
      <% end %> | 
				
			||||
    <% end %> | 
				
			||||
  <% end %> | 
				
			||||
  <% users.each do |user| %> | 
				
			||||
    <%= table.body do |body| %> | 
				
			||||
      <%= body.row do |row| %> | 
				
			||||
        <% row.cell(header: true, html_attributes: { | 
				
			||||
          scope: "row", | 
				
			||||
        }) do %> | 
				
			||||
          <%= simple_format(user_cell(user), {}, wrapper_tag: "span") %> | 
				
			||||
          <% if user.is_data_protection_officer? || user.is_key_contact? %> | 
				
			||||
            <br> | 
				
			||||
    <% users.each do |user| %> | 
				
			||||
      <%= table.body do |body| %> | 
				
			||||
        <%= body.row do |row| %> | 
				
			||||
          <% row.cell(header: true, html_attributes: { | 
				
			||||
            scope: "row", | 
				
			||||
          }) do %> | 
				
			||||
            <%= simple_format(user_cell(user), {}, wrapper_tag: "span") %> | 
				
			||||
            <% if user.is_data_protection_officer? || user.is_key_contact? %> | 
				
			||||
              <br> | 
				
			||||
            <% end %> | 
				
			||||
            <%= user.is_data_protection_officer? ? govuk_tag( | 
				
			||||
              classes: "app-tag--small", | 
				
			||||
              colour: "turquoise", | 
				
			||||
              text: "Data protection officer", | 
				
			||||
            ) : "" %> | 
				
			||||
            <%= user.is_key_contact? ? govuk_tag( | 
				
			||||
              classes: "app-tag--small", | 
				
			||||
              colour: "turquoise", | 
				
			||||
              text: "Key contact", | 
				
			||||
            ) : "" %> | 
				
			||||
          <% end %> | 
				
			||||
          <%= user.is_data_protection_officer? ? govuk_tag( | 
				
			||||
            classes: "app-tag--small", | 
				
			||||
            colour: "turquoise", | 
				
			||||
            text: "Data protection officer", | 
				
			||||
          ) : "" %> | 
				
			||||
          <%= user.is_key_contact? ? govuk_tag( | 
				
			||||
            classes: "app-tag--small", | 
				
			||||
            colour: "turquoise", | 
				
			||||
            text: "Key contact", | 
				
			||||
          ) : "" %> | 
				
			||||
          <% row.cell(text: simple_format(org_cell(user), {}, wrapper_tag: "div")) %> | 
				
			||||
          <% row.cell(text: user.last_sign_in_at&.to_formatted_s(:govuk_date)) %> | 
				
			||||
        <% end %> | 
				
			||||
        <% row.cell(text: simple_format(org_cell(user), {}, wrapper_tag: "div")) %> | 
				
			||||
        <% row.cell(text: user.last_sign_in_at&.to_formatted_s(:govuk_date)) %> | 
				
			||||
      <% end %> | 
				
			||||
    <% end %> | 
				
			||||
  <% end %> | 
				
			||||
<% end %> | 
				
			||||
</section> | 
				
			||||
					 | 
				
			||||
@ -0,0 +1,59 @@
					 | 
				
			||||
require "rails_helper" | 
				
			||||
 | 
				
			||||
RSpec.describe "Log Features" do | 
				
			||||
  context "when searching for specific logs" do | 
				
			||||
    context "when I am logged in and there are logs in the database" do | 
				
			||||
      let(:user) { FactoryBot.create(:user, last_sign_in_at: Time.zone.now) } | 
				
			||||
      let!(:log_to_search) { FactoryBot.create(:case_log, owning_organisation: user.organisation) } | 
				
			||||
      let!(:same_organisation_log) { FactoryBot.create(:case_log, owning_organisation: user.organisation) } | 
				
			||||
      let!(:another_organisation_log) { FactoryBot.create(:case_log) } | 
				
			||||
 | 
				
			||||
      before do | 
				
			||||
        visit("/logs") | 
				
			||||
        fill_in("user[email]", with: user.email) | 
				
			||||
        fill_in("user[password]", with: user.password) | 
				
			||||
        click_button("Sign in") | 
				
			||||
      end | 
				
			||||
 | 
				
			||||
      it "displays the logs belonging to the same organisation" do | 
				
			||||
        expect(page).to have_content(log_to_search.id) | 
				
			||||
        expect(page).to have_content(same_organisation_log.id) | 
				
			||||
        expect(page).not_to have_content(another_organisation_log.id) | 
				
			||||
      end | 
				
			||||
 | 
				
			||||
      context "when I search for a specific log" do | 
				
			||||
        it "there is a search bar with a message and search button for logs" do | 
				
			||||
          expect(page).to have_field("search") | 
				
			||||
          expect(page).to have_content("Search by log ID, tenant code, property reference or postcode") | 
				
			||||
          expect(page).to have_button("Search") | 
				
			||||
        end | 
				
			||||
 | 
				
			||||
        context "when I fill in search information and press the search button" do | 
				
			||||
          before do | 
				
			||||
            fill_in("search", with: log_to_search.id) | 
				
			||||
            click_button("Search") | 
				
			||||
          end | 
				
			||||
 | 
				
			||||
          it "displays log matching the log ID" do | 
				
			||||
            expect(page).to have_content(log_to_search.id) | 
				
			||||
            expect(page).not_to have_content(same_organisation_log.id) | 
				
			||||
            expect(page).not_to have_content(another_organisation_log.id) | 
				
			||||
          end | 
				
			||||
 | 
				
			||||
          context "when I want to clear results" do | 
				
			||||
            it "there is link to clear the search results" do | 
				
			||||
              expect(page).to have_link("Clear search") | 
				
			||||
            end | 
				
			||||
 | 
				
			||||
            it "displays the logs belonging to the same organisation after I clear the search result after I clear the search resultss" do | 
				
			||||
              click_link("Clear search") | 
				
			||||
              expect(page).to have_content(log_to_search.id) | 
				
			||||
              expect(page).to have_content(same_organisation_log.id) | 
				
			||||
              expect(page).not_to have_content(another_organisation_log.id) | 
				
			||||
            end | 
				
			||||
          end | 
				
			||||
        end | 
				
			||||
      end | 
				
			||||
    end | 
				
			||||
  end | 
				
			||||
end | 
				
			||||
					Loading…
					
					
				
		Reference in new issue