RSpec.describe YouTube::Routes do
  before { require_rel '../../fixtures/pages/fake_youtube' }

  # Mock PageObject call which checks that the @browser object is in fact a Watir::Browser or selenium browser obj.
  # Without this, mocked_browser.is_a?(Watir::Browser) would return false and PageObject would raise an exception
  # that it does not know which platform to load.
  before(:each) { allow(PageObject::Platforms::WatirWebDriver).to receive(:is_for?).and_return(true) }

  let(:fixture_route) { [[FakeYouTube::FirstPage, :first_method], [FakeYouTube::LastPage]] }

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

  describe '#traverse' do
    it 'returns the expected url' do
      browser = instance_double(Watir::Browser)
      expect(browser).to receive(:goto).with('http://fakesite.com')
      returned_url = YouTube::Routes.new(browser, {}, fixture_route).traverse
      expect(returned_url).to eq 'http://fakesite.com/report-url-here'
    end
  end
end
