Sha256: 88c93d95ce1b32c72fc4ce629460aab98310beca4eee1604b1fdea29c7e33fc1

Contents?: true

Size: 1.98 KB

Versions: 5

Compression:

Stored size: 1.98 KB

Contents

describe 'collections/_form_for_select_collection.html.erb', type: :view do
  let(:collections) {
    [
      build(:collection, id: '1234', create_date: Time.zone.parse('Thu, 13 Aug 2015 14:20:22 +0100')),
      build(:collection, id: '1235', create_date: Time.zone.parse('Thu, 13 Aug 2015 14:18:22 +0100')),
      build(:collection, id: '1236', create_date: Time.zone.parse('Thu, 13 Aug 2015 14:16:22 +0100')),
      build(:collection, id: '1237', create_date: Time.zone.parse('Thu, 13 Aug 2015 14:29:22 +0100'))
    ]
  }
  let(:solr_collections) {
    collections.map do |c|
      SolrDocument.new(c.to_solr).tap do |sd|
        sd['system_create_dtsi'] = c.create_date.to_s
      end
    end
  }

  let(:doc) { Nokogiri::HTML(rendered) }

  before { allow(view).to receive(:user_collections).and_return(solr_collections) }

  it "sorts the collections" do
    render
    collection_ids = doc.xpath("//input[@class='collection-selector']/@id").map(&:to_s)
    expect(collection_ids).to eql(["id_1237", "id_1234", "id_1235", "id_1236"])
  end

  it "selects the right collection when instructed to do so" do
    assign(:add_files_to_collection, collections[2].id)
    render
    expect(rendered).not_to have_selector "#id_#{collections[0].id}[checked='checked']"
    expect(rendered).not_to have_selector "#id_#{collections[1].id}[checked='checked']"
    expect(rendered).not_to have_selector "#id_#{collections[3].id}[checked='checked']"
    expect(rendered).to have_selector "#id_#{collections[2].id}[checked='checked']"
  end

  it "selects the first collection when nothing else specified" do
    # first when sorted by create date, so not index 0
    render
    expect(rendered).not_to have_selector "#id_#{collections[0].id}[checked='checked']"
    expect(rendered).not_to have_selector "#id_#{collections[1].id}[checked='checked']"
    expect(rendered).not_to have_selector "#id_#{collections[2].id}[checked='checked']"
    expect(rendered).to have_selector "#id_#{collections[3].id}[checked='checked']"
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sufia-7.1.0 spec/views/collections/_form_for_select_collection.html.erb_spec.rb
sufia-7.0.0 spec/views/collections/_form_for_select_collection.html.erb_spec.rb
sufia-7.0.0.rc2 spec/views/collections/_form_for_select_collection.html.erb_spec.rb
sufia-7.0.0.rc1 spec/views/collections/_form_for_select_collection.html.erb_spec.rb
sufia-7.0.0.beta4 spec/views/collections/_form_for_select_collection.html.erb_spec.rb