Browse Source
* Reorder resources list * Update sales 23/24 resources * Update sales 22/23 resources * Fix typo and add missing paths * Change the wording * feat: update files, add 22/23 lettings form to local storage and add collection resources helper * feat: remove sales bu feature toggoe * refactor: lint * refactor: erblinting * feat: add tests for helper * feat: revert feature flag removal (will put in a separate PR) * refactor: update matadata helper --------- Co-authored-by: natdeanlewissoftwire <nat.dean-lewis@softwire.com>pull/1676/head
kosiakkatrina
2 years ago
committed by
GitHub
11 changed files with 133 additions and 18 deletions
@ -0,0 +1,15 @@
|
||||
module CollectionResourcesHelper |
||||
def file_type_size_and_pages(file, number_of_pages: nil) |
||||
extension_mapping = { |
||||
"xlsx" => "Microsoft Excel", |
||||
"pdf" => "PDF", |
||||
} |
||||
extension = File.extname(file)[1..] |
||||
|
||||
file_type = extension_mapping.fetch(extension, extension) |
||||
|
||||
file_size = number_to_human_size(File.size("public/files/#{file}"), precision: 0, significant: false) |
||||
file_pages = number_of_pages ? pluralize(number_of_pages, "page") : nil |
||||
[file_type, file_size, file_pages].compact.join(", ") |
||||
end |
||||
end |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,20 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe CollectionResourcesHelper do |
||||
let(:current_user) { create(:user, :data_coordinator) } |
||||
let(:user) { create(:user, :data_coordinator) } |
||||
|
||||
describe "when displaying file metadata" do |
||||
context "with pages" do |
||||
it "returns correct metadata" do |
||||
expect(file_type_size_and_pages("2023_24_lettings_paper_form.pdf", number_of_pages: 8)).to eq("PDF, 286 KB, 8 pages") |
||||
end |
||||
end |
||||
|
||||
context "without pages" do |
||||
it "returns correct metadata" do |
||||
expect(file_type_size_and_pages("bulk-upload-lettings-template-2023-24.xlsx")).to eq("Microsoft Excel, 15 KB") |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue