require "rails_helper"

module ExcelReports
  module VideoReports
    module DiscoveryProductionElementsLogs
      RSpec.describe TalentSheet 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 'Talent'" do
            expect(described_class.new(workbook).title).to eq "Talent"
          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, 
                    video: build(:video, name: "My Video", number: 1),
                    releasable: build(:talent_release, person_first_name: "John", person_last_name: "Doe")
                   )
            )
            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",
              "",
              "John Doe",
            ])
          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, 30, 60" do
            expect(sheet).to receive(:column_widths).with(20, 20, 30, 60)

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