require "rails_helper"

module ExcelReports
  module VideoReports
    module DiscoveryProductionElementsLogs
      RSpec.describe LocationSheet do
        let(:workbook) { instance_double(Axlsx::Workbook, :workbook) }

        it_behaves_like "a worksheet" do
          subject { described_class.new(workbook) }
        end

        describe "#title" do
          it "returns 'Location'" do
            expect(described_class.new(workbook).title).to eq "Location"
          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",
                    time_elapsed: 1,
                    source_file_name: "source",
                    clip_name: "clip",
                    description: "restaurant",
                    video: build(:video, name: "My Video", number: 1),
                    releasable: build(:location_release, name: "Frank's Taco Shack")
                   )
            )
            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", 
              "My Video",
              "00:00:05:00", 
              "source - clip",
              "Frank's Taco Shack restaurant", 
            ])
          end
        end

        describe "#format" do
          let(:sheet) { instance_double(Axlsx::Worksheet, :sheet) }

          before :each do
            allow(sheet).to receive(:column_widths)
            allow(sheet).to receive(:merge_cells)
          end

          it "sets sheet column widths to 20, 20, 15, 20, 40" do
            expect(sheet).to receive(:column_widths).with(20, 20, 15, 20, 40)

            described_class.new(workbook).format(sheet)
          end
        end
      end
    end
  end
end
