require "rails_helper"

module ExcelReports
  module IssuesAndConcernsReports
    RSpec.describe IssuesAndConcernsWorksheet 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 'Issues and Concerns Report'" do
          expect(described_class.new(workbook).title).to eq "Issues and Concerns Report"
        end
      end

      describe "#fill_content" do
        it "adds content from acquired media release" do
          presenter = instance_double(
            IssuesAndConcernsReportPresenter,
            project_name: "Broadcast across the nation",
            video_name: "The News",
            date_of_report: "Today",
            unreleased_appearances: [
              instance_double(UnreleasedAppearance, 
                              timecode_in: "timecode_in",
                              timecode_out: "timecode_out",
                              channel: "channel",
                              source_file_name: "source_file_name",
                              clip_name: "clip_name",
                              note_text: "Great notes",
                             )],
          )

          sheet = instance_double(Axlsx::Worksheet, :sheet)
          expect(sheet).to receive(:add_row).with(["ISSUES AND CONCERNS REPORT"])
          expect(sheet).to receive(:add_row).with(["Project Name", "Broadcast across the nation"])
          expect(sheet).to receive(:add_row).with(["Video Name", "The News"])
          expect(sheet).to receive(:add_row).with(["Date of Report", "Today"])
          expect(sheet).to receive(:add_row).with([])
          expect(sheet).to receive(:add_row).with(["Track", "TC In", "TC Out", "Clip Name", "Source File Name", "Notes"])
          expect(sheet).to receive(:add_row).with(["channel", "timecode_in", "timecode_out", "clip_name", "source_file_name", "Great notes"])

          described_class.new(workbook, presenter).fill_content(sheet)
        end
      end

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

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

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

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

      describe "#style" do
        it "sets sheet style" do
          sheet = instance_double(Axlsx::Worksheet, :sheet)
          expect(sheet).to receive(:add_style).with("A1", { b: true }, { sz: 14 })
          expect(sheet).to receive(:add_style).with(
            "A2:A4",
            {
              bg_color: "97CBFC",
              b: true,
              border: { :style => :thick, :color => "000000" },
              alignment: { :horizontal => :center, :wrap_text => true },
              sz: 12,
            }
          )
          expect(sheet).to receive(:add_style).with(
            "B2:B4",
            {
              border: { :style => :thick, :color => "000000" },
              alignment: { :wrap_text => true, :horizontal => :left },
              sz: 10,
            }
          )
          expect(sheet).to receive(:add_style).with(
            "A6:F6",
            {
              bg_color: "97CBFC",
              b: true,
              border: { :style => :thick, :color => "000000" },
              alignment: { :horizontal => :center, :vertical => :center, :wrap_text => true },
              sz: 8,
            }
          )
          expect(sheet).to receive(:add_style).at_least(1).with(
            "A7:F8",
            {
              border: { style: :thick, color: "000000" },
              alignment: { wrap_text: true },
              sz: 10
            }
          )

          presenter = instance_double(
            IssuesAndConcernsReportPresenter,
            unreleased_appearances: [
              instance_double(UnreleasedAppearance, timecode_in: "yesterday", notes: "Great notes"),
              instance_double(UnreleasedAppearance, timecode_in: "yesterday", notes: "Great notes"),
            ],
          )
          described_class.new(workbook, presenter).style(sheet)
        end
      end
    end
  end
end
