require "rails_helper"

module ExcelReports
  module VideoReports
    module NatGeoLegalBinderLogs
      RSpec.describe LocationReleaseLogSheet, type: :model do
        let(:workbook) { instance_double(Axlsx::Workbook, :workbook) }

        subject { described_class.new(workbook, []) }

        it_behaves_like "a worksheet"

        describe "#title" do
          it "returns the title of the sheet" do
            expect(subject.title).to eq "Location Release Log"
          end
        end

        describe "#fill_content" do
          it "adds content from the data" do
            sheet = instance_double(Axlsx::Worksheet, :sheet) 
            releasable_datum = ReleasableDataAdapter.new(
              build(:video_release_confirmation, 
                    timecode_in: "00:00:05:00",
                    releasable: build(:location_release, 
                                      applicable_medium: ApplicableMedium.last,
                                      territory: Territory.last,
                                      term: Term.last,
                                      restriction: Restriction.last,
                                      name: "My Location", 
                                      address_street1: "123 Main Street",
                                      address_city: "New York",
                                      address_state: "NY",
                                      address_zip: "10000")
                   )
            )
            allow(sheet).to receive(:add_row)

            release_log = described_class.new(workbook, [releasable_datum])
            release_log.fill_content(sheet)

            expect(sheet).to have_received(:add_row).with([
              1, 
              "00:00:05:00", 
              "My Location\n123 Main Street, New York, NY 10000", 
              "", 
              "All", "Worldwide", "In perpetuity", "", "None",
            ])
          end
        end

        describe "#format" do
          it "sets column widths and merges cells" do
            sheet = instance_double(Axlsx::Worksheet, :sheet)
            allow(sheet).to receive(:column_widths)
            allow(sheet).to receive(:merge_cells)

            subject.format(sheet)

            expect(sheet).to have_received(:column_widths)
            expect(sheet).to have_received(:merge_cells).at_least(1).times
          end
        end

        describe "#style" do
          it "sets sheet style" do
            sheet = instance_double(Axlsx::Worksheet, :sheet)
            allow(sheet).to receive(:add_style)

            subject.style(sheet)

            expect(sheet).to have_received(:add_style).at_least(1).times
          end
        end
      end
    end
  end
end
