Sha256: dce6c00dd2ca93b21f85cd984e2c68f7cff29fd570f701da45b42cc6f45d913e

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

# This file is part of Alexandria.
#
# See the file README.md for authorship and licensing information.

require_relative "../../spec_helper"

describe Alexandria::UI::ImportDialog do
  let(:parent) { Gtk::Window.new :toplevel }

  it "can be instantiated" do
    described_class.new parent
  end

  it "handles a selection change" do
    importdialog = described_class.new parent
    importdialog.dialog.signal_emit "selection_changed"
  end

  describe "#acquire" do
    let(:import_dialog) { described_class.new parent }
    let(:chooser) { import_dialog.dialog }

    before do
      allow(chooser).to receive(:filename).and_return("spec/data/isbns.txt")
      allow(Alexandria::BookProviders).to receive(:isbn_search)
        .and_raise Alexandria::BookProviders::SearchEmptyError
      allow(Alexandria::BookProviders).to receive(:isbn_search).with("0595371086")
        .and_return(an_artist_of_the_floating_world)
    end

    it "works when response is cancel" do
      allow(chooser).to receive(:run).and_return(Gtk::ResponseType::CANCEL)
      import_dialog.acquire { nil }
    end

    it "works when response is OK" do
      allow(chooser).to receive(:run).and_return(Gtk::ResponseType::OK)

      result = nil
      import_dialog.acquire { |*args| result = args }
      expect(result.first.to_a).to eq [an_artist_of_the_floating_world]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alexandria-book-collection-manager-0.7.9 spec/alexandria/ui/import_dialog_spec.rb