<commit_before>module Mohawk
  module Adapters
    module UIA
      class MenuItem < Control
        class MenuItemNotFound < StandardError; end

        def select
          menu_item.as(:invoke).invoke
        end

        def click
          menu_item.click
        end

        def exist?
          !!menu_item
        rescue MenuItemNotFound
          false
        end

        private
        def menu_item
          current_item = @parent
          path.each_with_index do |menu_item, index|
            current_item = current_item.filter(control_type: :menu_item, name: menu_item).first
            raise MenuItemNotFound, menu_item unless current_item
            try_to_expand current_item unless index == path.count - 1
          end
          current_item
        end

        def path
          @locator[:path]
        end

        def try_to_expand(item)
          case
            when item.patterns.include?(:expand_collapse)
              item.as(:expand_collapse).expand
            else
              item.as(:invoke).invoke
          end
        end
      end
    end
  end
end<commit_msg>use #click_center for menu item<commit_after>module Mohawk
  module Adapters
    module UIA
      class MenuItem < Control
        class MenuItemNotFound < StandardError; end

        def select
          menu_item.as(:invoke).invoke
        end

        def click
          menu_item.click_center
        end

        def exist?
          !!menu_item
        rescue MenuItemNotFound
          false
        end

        private
        def menu_item
          current_item = @parent
          path.each_with_index do |menu_item, index|
            current_item = current_item.filter(control_type: :menu_item, name: menu_item).first
            raise MenuItemNotFound, menu_item unless current_item
            try_to_expand current_item unless index == path.count - 1
          end
          current_item
        end

        def path
          @locator[:path]
        end

        def try_to_expand(item)
          case
            when item.patterns.include?(:expand_collapse)
              item.as(:expand_collapse).expand
            else
              item.as(:invoke).invoke
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.051224944320712694, 'fraction_numerical': 0.0008908685968819599, 'mean_word_length': 1.532130777903044, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2539315', 'n_tokens_mistral': 592, 'n_tokens_neox': 577, 'n_words': 151}