require_relative '../teachers'

module Teachers
  class ClassManagerPage < Page
    def self.path
      Teachers.classrooms_path
    end

    [['Create a Class',  :create_class],
     ['Invite Students', :invite_students],
     ['Manage Classes',  :manage_classes]].each do |pair|
      text, sym = pair

      module_eval_str __LINE__, %{
        def has_#{sym}?
          has_link? '#{text}'
        end
      }
    end

    [['Activity Planner', :activity_planner],
     ['Classes',    :classes],
     ['Student Reports',        :student_reports]
    ].each do |pair|
      text, sym = pair

      module_eval_str __LINE__, %{
        def self.#{sym}_tab_pair
          #{pair}
        end

        def select_#{sym}
          click_link '#{text}'
        end
      }
    end
  end
end

require_relative '../teachers'

module Teachers
  class ClassManagerPage < Page
    def self.path
      Teachers.classrooms_path
    end

    [['Create a Class',  :create_class],
     ['Invite Students', :invite_students],
     ['Manage Classes',  :manage_classes]].each do |pair|
      text, sym = pair

      module_eval_str __LINE__, %{
        def has_#{sym}?
          has_link? '#{text}'
        end
      }
    end

    [['Activity Planner', :activity_planner],
     ['Classes',    :classes],
     ['Student Reports',        :student_reports]
    ].each do |pair|
      text, sym = pair

      module_eval_str __LINE__, %{
        def self.#{sym}_tab_pair
          #{pair}
        end

        def select_#{sym}
          first(:link, '#{text}').click
        end
      }
    end
  end
end

Resolve ambiguous match spec error in class_manager
Resolve ambiguous match spec error in class_manager

Resolve spec error:

  Create-a-Class page when signed in as a Teacher with no existing classes selecting the Classes tab navigates to create-a-class

  Failure/Error: end

  Capybara::Ambiguous:
    Ambiguous match, found 2 elements matching link "Classes"

  Shared Example Group: :navigates_to_create_class called from ./spec/features/teacher/class_manager/create_class_spec.rb:87
   # ./spec/support/pages/page.rb:33:in `select_classes'
   # ./spec/features/teacher/class_manager/create_class_spec.rb:86:in `block (5 levels) in <top (required)>'

Following commit ffa87bd87d63f2eff9d7ac08bac63eee6422f628
the app/views/teachers/shared/_scorebook_tabs.html.erb creates two
'Classes' links, one which is for mobile.

To avoid the Capybara ambiguous match error be more specific and ensure
match on the first found link only.

Fixes spec:
  - spec/features/teacher/class_manager/create_class_spec.rb
