|
4 | 4 |
|
5 | 5 | describe Hyrax::Forms::CollectionForm do |
6 | 6 |
|
7 | | - describe "#terms" do |
8 | | - subject { described_class.terms } |
| 7 | + let(:model) { Collection.new } |
| 8 | + let(:user) { create(:user) } |
| 9 | + let(:ability) { Ability.new(user) } |
| 10 | + let(:config) { Blacklight::Solr::Configuration.new } |
| 11 | + let(:repository) { Blacklight::Solr::Repository.new(:config) } |
| 12 | + let(:subject) { described_class.new(model, ability, repository) } |
| 13 | + |
| 14 | + let( :expected_required_fields ) { %i[ |
| 15 | + title |
| 16 | + creator |
| 17 | + description |
| 18 | + subject_discipline |
| 19 | + ] } |
9 | 20 |
|
10 | | - it { is_expected.to eq %i[ |
| 21 | + let( :expected_terms ) { %i[ |
11 | 22 | authoremail |
12 | 23 | based_near |
13 | 24 | collection_type_gid |
|
34 | 45 | thumbnail_id |
35 | 46 | title |
36 | 47 | visibility |
37 | | - ] } |
| 48 | + ] } |
| 49 | + |
| 50 | + let( :expected_default_work_primary_terms ) { %i[ |
| 51 | + title |
| 52 | + creator |
| 53 | + description |
| 54 | + keyword |
| 55 | + subject_discipline |
| 56 | + language |
| 57 | + referenced_by |
| 58 | + ] } |
| 59 | + |
| 60 | + describe "delegates methods to model:" do |
| 61 | + [:id, :depositor, :permissions, :human_readable_type, :member_ids, :nestable?].each do |
| 62 | + |method| |
| 63 | + it "#{method}" do |
| 64 | + expect(subject).to delegate_method(method).to(:model) |
| 65 | + end |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + describe "delegates method to Hyrax::CollectionsController" do |
| 70 | + it "#blacklight_config" do |
| 71 | + skip "Add test here" |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + describe "#terms" do |
| 76 | + subject { described_class.terms } |
| 77 | + |
| 78 | + it "equals array" do |
| 79 | + is_expected.to eq expected_terms |
| 80 | + end |
38 | 81 | end |
39 | 82 |
|
| 83 | + describe "#required_fields" do |
| 84 | + subject { described_class.required_fields } |
| 85 | + |
| 86 | + it "equals array" do |
| 87 | + is_expected.to eq expected_required_fields |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + describe "#permission_template" do |
| 92 | + before { |
| 93 | + allow(Hyrax::PermissionTemplate).to receive(:find_or_create_by).with(source_id: anything).and_return OpenStruct.new( attributes: {} ) |
| 94 | + } |
| 95 | + it "calls PermissionTemplate" do |
| 96 | + expect(Hyrax::PermissionTemplate).to receive(:find_or_create_by).with(source_id: anything).and_return OpenStruct.new( attributes: {} ) |
| 97 | + subject.permission_template |
| 98 | + end |
| 99 | + |
| 100 | + it "calls PermissionTemplateForm.new" do |
| 101 | + skip "Add a test" |
| 102 | + end |
| 103 | + end |
| 104 | + |
| 105 | + describe "#select_files" do |
| 106 | + before { |
| 107 | + allow(subject).to receive(:all_files_with_access).and_return [["apples", 3], ["bananas", 2], ["oranges", 1]] |
| 108 | + } |
| 109 | + |
| 110 | + it "calls all_files_with_access and creates a Hash from the result" do |
| 111 | + expect(subject).to receive(:all_files_with_access) |
| 112 | + expect(subject.select_files).to eq Hash[[["apples", 3], ["bananas", 2], ["oranges", 1]]] |
| 113 | + end |
| 114 | + end |
| 115 | + |
| 116 | + describe "#primary_terms" do |
| 117 | + it "equals array" do |
| 118 | + expect(subject.primary_terms).to eq expected_default_work_primary_terms |
| 119 | + end |
| 120 | + end |
| 121 | + |
| 122 | + describe "#secondary_terms" do |
| 123 | + it "returns empty array" do |
| 124 | + expect(subject.secondary_terms).to be_blank |
| 125 | + end |
| 126 | + end |
| 127 | + |
| 128 | + describe "#relative_url_root" do |
| 129 | + context "when DeepBlueDocs::Application.config.relative_url_root has value" do |
| 130 | + before { |
| 131 | + allow(::DeepBlueDocs::Application.config).to receive(:relative_url_root).and_return "rootin' tootin'" |
| 132 | + } |
| 133 | + it "returns DeepBlueDocs::Application.config.relative_url_root" do |
| 134 | + expect(subject.relative_url_root).to eq "rootin' tootin'" |
| 135 | + end |
| 136 | + end |
| 137 | + |
| 138 | + context "when DeepBlueDocs::Application.config.relative_url_root has no value" do |
| 139 | + before { |
| 140 | + allow(::DeepBlueDocs::Application.config).to receive(:relative_url_root).and_return nil |
| 141 | + } |
| 142 | + it "returns empty string" do |
| 143 | + expect(subject.relative_url_root).to eq "" |
| 144 | + end |
| 145 | + end |
| 146 | + end |
| 147 | + |
| 148 | + describe "#banner_info" do |
| 149 | + before { |
| 150 | + allow(subject).to receive(:id).and_return 202 |
| 151 | + } |
| 152 | + it "calls branding_banner_info" do |
| 153 | + expect(subject).to receive(:branding_banner_info).with(id: 202) |
| 154 | + subject.banner_info |
| 155 | + end |
| 156 | + end |
| 157 | + |
| 158 | + describe "#logo_info" do |
| 159 | + before { |
| 160 | + allow(subject).to receive(:id).and_return 303 |
| 161 | + } |
| 162 | + it "calls branding_logo_info" do |
| 163 | + expect(subject).to receive(:branding_logo_info).with(id: 303) |
| 164 | + subject.logo_info |
| 165 | + end |
| 166 | + end |
| 167 | + |
| 168 | + describe "#display_additional_fields?" do |
| 169 | + context "secondary terms present" do |
| 170 | + before { |
| 171 | + allow(subject).to receive(:secondary_terms).and_return ["title"] |
| 172 | + } |
| 173 | + it "returns true" do |
| 174 | + expect(subject.display_additional_fields?).to eq true |
| 175 | + end |
| 176 | + end |
| 177 | + |
| 178 | + context "secondary terms not present" do |
| 179 | + before { |
| 180 | + allow(subject).to receive(:secondary_terms).and_return [] |
| 181 | + } |
| 182 | + it "returns false" do |
| 183 | + expect(subject.display_additional_fields?).to eq false |
| 184 | + end |
| 185 | + end |
| 186 | + end |
| 187 | + |
| 188 | + describe "#thumbnail_title" do |
| 189 | + context "when model.thumbnail is nil" do |
| 190 | + before { |
| 191 | + allow(model).to receive(:thumbnail).and_return( nil ) |
| 192 | + } |
| 193 | + it "returns nil" do |
| 194 | + expect(subject.thumbnail_title).to be_blank |
| 195 | + end |
| 196 | + end |
| 197 | + |
| 198 | + context "when model.thumbnail is not nil" do |
| 199 | + before { |
| 200 | + allow(model).to receive(:thumbnail).and_return OpenStruct.new( title: ["rutabaga", "cauliflower", "tomato"] ) |
| 201 | + } |
| 202 | + it "returns model.thumbnail.title.first" do |
| 203 | + expect(subject.thumbnail_title).to eq "rutabaga" |
| 204 | + end |
| 205 | + end |
| 206 | + end |
| 207 | + |
| 208 | + describe "#list_parent_collections" do |
| 209 | + before { |
| 210 | + allow(model).to receive(:member_of_collections).and_return(["sunflower", "bluebell", "petunia"]) |
| 211 | + } |
| 212 | + it "returns collection.member_of_collections" do |
| 213 | + expect(subject.list_parent_collections).to eq ["sunflower", "bluebell", "petunia"] |
| 214 | + end |
| 215 | + end |
| 216 | + |
| 217 | + describe "#list_child_collections" do |
| 218 | + before { |
| 219 | + allow(subject.membership_service_class).to receive(:new) |
| 220 | + .with(scope: anything, collection: model, params: anything) |
| 221 | + .and_return OpenStruct.new( available_member_subcollections: OpenStruct.new(documents: ["vanilla", "saffron", "nutmeg"]) ) |
| 222 | + } |
| 223 | + |
| 224 | + it "returns documents from collection_member_service.available_member_subcollections" do |
| 225 | + expect(subject.list_child_collections).to eq ["vanilla", "saffron", "nutmeg"] |
| 226 | + end |
| 227 | + end |
| 228 | + |
| 229 | + pending "#available_parent_collections" |
| 230 | + |
40 | 231 | end |
0 commit comments