RSpec.describe YouTube::DownloadReportsPage do
  before(:each) { allow(PageObject::Platforms::WatirWebDriver).to receive(:is_for?).and_return(true) }

  describe '#initialize' do
    it 'does not raise an error' do
      browser = instance_double(Watir::Browser)
      expect { YouTube::DownloadReportsPage.new(browser) }.to_not raise_error
    end
  end

  describe '#fetch' do
    context 'default opts' do
      it 'does not raise an error' do
        # Using #receive_message_chain instead of monkey patching Watir::Browser lets us assert each :link, :li, and
        # :table element receives the correct message, but because we cannot allow the same chain more than once
        # (cannot chain #at_least(:once) to it), we have to use a simple #receive(:message), ending with #ordered,
        # and return doubles we can call the chained #click or #wait_until_present methods on. (Hint: this test is a
        # LOT more brittle.) Going to stick to monkey patching as it is a less brittle test and still allows us to call
        # the method-under-test.
        class Watir::Browser
          def click; end

          def visible?; end

          def present?; end

          def find; end

          def wait_until_present; end

          def href; end
        end
        # Use null object for mocked browser because we don't care about unexpected messages received.
        browser = instance_double(Watir::Browser).as_null_object

        # Not sure this is the right approach. May want to look into how watir-webdriver writes their unit tests, or
        # see what we can learn from watirspec... read https://github.com/watir/watir-webdriver#specs

        expect { YouTube::DownloadReportsPage.new(browser).fetch }.to_not raise_error
      end
    end
  end
end
