Browse Source
* spec for item_label * class for item_label * using helper to derrive plurality * using helper in other views * better test name * test for title format functionality * code for title format * test for title format support user and all high level titles * renamed helper * failing test viewing logs for specific org as support user * code for title format with sub nav for support user * code for title format coordinator user * correct titles for coordinator user * switched users to using helper * rubocop * correct title for support about org * massive refacotring * cleaner code * correct title for support users in about section * refactored name * refactored test namesCLDC-1219-create-single-org-migration-task
J G
3 years ago
committed by
GitHub
9 changed files with 159 additions and 38 deletions
@ -0,0 +1,20 @@
|
||||
module TitleHelper |
||||
def format_label(count, item) |
||||
count > 1 ? item.pluralize : item |
||||
end |
||||
|
||||
def format_title(searched, page_title, current_user, item_label, count, organisation_name) |
||||
if searched.present? |
||||
actual_title = support_sab_nav?(current_user, organisation_name) ? organisation_name : page_title |
||||
"#{actual_title} (#{count} #{item_label} matching ‘#{searched}’)" |
||||
else |
||||
support_sab_nav?(current_user, organisation_name) ? "#{organisation_name} (#{page_title})" : page_title |
||||
end |
||||
end |
||||
|
||||
private |
||||
|
||||
def support_sab_nav?(current_user, organisation_name) |
||||
current_user.support? && organisation_name |
||||
end |
||||
end |
@ -0,0 +1,122 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe TitleHelper do |
||||
describe "#format_label" do |
||||
let(:item) { "organisation" } |
||||
|
||||
it "returns singular when count is 1" do |
||||
expect(format_label(1, item)).to eq("organisation") |
||||
end |
||||
|
||||
it "returns plural when count greater than 1" do |
||||
expect(format_label(2, item)).to eq("organisations") |
||||
end |
||||
end |
||||
|
||||
describe "#format_title" do |
||||
let(:page_title) { "Title" } |
||||
let(:item_label) { "label" } |
||||
let(:search_item) { nil } |
||||
let(:count) { 1 } |
||||
let(:organisation_name) { nil } |
||||
|
||||
context "when provider user" do |
||||
let(:user) { FactoryBot.create(:user) } |
||||
|
||||
context "when any specific path" do |
||||
let(:page_title) { "Users" } |
||||
let(:organisation_name) { nil } |
||||
|
||||
context "when search is missing" do |
||||
let(:expected_title) { page_title } |
||||
|
||||
it "returns expected title" do |
||||
expect(format_title(nil, page_title, user, item_label, count, organisation_name)).to eq(expected_title) |
||||
end |
||||
|
||||
context "when search is present" do |
||||
let(:search_item) { "foobar" } |
||||
let(:expected_title) { "#{page_title} (#{count} #{item_label} matching ‘#{search_item}’)" } |
||||
|
||||
it "returns expected title" do |
||||
expect(format_title(search_item, page_title, user, item_label, count, organisation_name)).to eq(expected_title) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when coordinator user" do |
||||
let(:user) { FactoryBot.create(:user, :data_coordinator) } |
||||
|
||||
context "when any specific path" do |
||||
let(:page_title) { "Users" } |
||||
let(:organisation_name) { nil } |
||||
|
||||
context "when search is missing" do |
||||
let(:expected_title) { page_title } |
||||
|
||||
it "returns expected title" do |
||||
expect(format_title(nil, page_title, user, item_label, count, organisation_name)).to eq(expected_title) |
||||
end |
||||
|
||||
context "when search is present" do |
||||
let(:search_item) { "foobar" } |
||||
let(:expected_title) { "#{page_title} (#{count} #{item_label} matching ‘#{search_item}’)" } |
||||
|
||||
it "returns expected title" do |
||||
expect(format_title(search_item, page_title, user, item_label, count, organisation_name)).to eq(expected_title) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when support user" do |
||||
let(:user) { FactoryBot.create(:user, :support) } |
||||
|
||||
context "when no organisation is specified" do |
||||
let(:page_title) { "Organisations" } |
||||
|
||||
context "when search is missing" do |
||||
let(:expected_title) { page_title } |
||||
|
||||
it "returns expected title" do |
||||
expect(format_title(nil, page_title, user, item_label, count, organisation_name)).to eq(expected_title) |
||||
end |
||||
end |
||||
|
||||
context "when search is present" do |
||||
let(:search_item) { "foobar" } |
||||
let(:expected_title) { "#{page_title} (#{count} #{item_label} matching ‘#{search_item}’)" } |
||||
|
||||
it "returns expected title" do |
||||
expect(format_title(search_item, page_title, user, item_label, count, organisation_name)).to eq(expected_title) |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when organisation is specified" do |
||||
let(:page_title) { "Organisations" } |
||||
let(:organisation_name) { "Some Name" } |
||||
|
||||
context "when search is missing" do |
||||
let(:expected_title) { "#{organisation_name} (#{page_title})" } |
||||
|
||||
it "returns expected title" do |
||||
expect(format_title(nil, page_title, user, item_label, count, organisation_name)).to eq(expected_title) |
||||
end |
||||
end |
||||
|
||||
context "when search is present" do |
||||
let(:search_item) { "foobar" } |
||||
let(:expected_title) { "#{organisation_name} (#{count} #{item_label} matching ‘#{search_item}’)" } |
||||
|
||||
it "returns expected title" do |
||||
expect(format_title(search_item, page_title, user, item_label, count, organisation_name)).to eq(expected_title) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue