require "rails_helper"

module ExcelReports
  module GraphicReports
    module NatGeoTextGraphicsLogs
      RSpec.describe InternalProgramGfxLogSheet do
        let(:workbook) { instance_double(Axlsx::Workbook, :workbook) }
        let(:video) { build(:video, name: "My Video", number: 10) }
        let(:graphics_element) do
          build(:graphics_element, 
                graphic_type: "Logo",text: "Some Text", 
                timecode_in: "00:00:05:00", timecode_out: "00:00:10:00")
        end

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

        it_behaves_like "a worksheet"

        describe "#title" do
          it "returns the title of the sheet" do
            expect(subject.title).to eq "Internal Program GFX Log"
          end
        end

        describe "#fill_content" do
          it "adds content from the data" do
            sheet = instance_double(Axlsx::Worksheet, :sheet) 
            allow(sheet).to receive(:add_row)
            allow(BigMediaTime).to receive(:time_zone_now).and_return(Date.new(2019,10,4))

            subject.fill_content(sheet)

            expect(sheet).to have_received(:add_row).with(["", "Episode Title:", "My Video", "", "", "", "",])
            expect(sheet).to have_received(:add_row).with(["", "Episode Number:", "10", "", "", "", "",])
            expect(sheet).to have_received(:add_row).with(["", "Date:", "10/04/19", "", "", "", "",])
            expect(sheet).to have_received(:add_row).with(["Logo", "Some Text", "00:00:05:00", "00:00:10:00", "", "", "",])
          end
        end

        describe "#format" do
          it "sets sheet 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
