<commit_before>module PageModels
  module SearchResultsActions
    def switch_to_grid_view
      return if search_results_page.current_view == :grid

      search_results_page.wait_for_grid_view_button
      search_results_page.wait_until_grid_view_button_visible
      puts 'Switching to grid view of book results'
      search_results_page.grid_view_button.click
      wait_until('Search results page is displayed in Grid view') { search_results_page.current_view == :grid }
    end

    def switch_to_list_view
      return if search_results_page.current_view == :list

      search_results_page.wait_for_list_view_button
      search_results_page.wait_until_list_view_button_visible
      puts 'Switching to list view of book results'
      search_results_page.list_view_button.click
      wait_until('Search results page is displayed in List view') { search_results_page.current_view == :list }
    end

    def switch_to_view(view)
      books_section.wait_for_books
      fail 'No search results returned' unless search_results_page.no_results_message.empty?
      if view.to_sym == :list
        switch_to_list_view
      elsif view.to_sym == :grid
        switch_to_grid_view
      elsif view.to_sym == :none
        # Do nothing on purpose
      else
        fail "Unsupported view for book results: #{view}"
      end
    end
  end
end

World(PageModels::SearchResultsActions)<commit_msg>Fixing negative search cases<commit_after>module PageModels
  module SearchResultsActions
    def switch_to_grid_view
      fail 'No search results returned' unless search_results_page.no_results_message.empty?
      return if search_results_page.current_view == :grid

      search_results_page.wait_for_grid_view_button
      search_results_page.wait_until_grid_view_button_visible
      puts 'Switching to grid view of book results'
      search_results_page.grid_view_button.click
      wait_until('Search results page is displayed in Grid view') { search_results_page.current_view == :grid }
    end

    def switch_to_list_view
      fail 'No search results returned' unless search_results_page.no_results_message.empty?
      return if search_results_page.current_view == :list

      search_results_page.wait_for_list_view_button
      search_results_page.wait_until_list_view_button_visible
      puts 'Switching to list view of book results'
      search_results_page.list_view_button.click
      wait_until('Search results page is displayed in List view') { search_results_page.current_view == :list }
    end

    def switch_to_view(view)
      books_section.wait_for_books

      case view.to_sym
      when :list
        switch_to_list_view
      when :grid
        switch_to_grid_view
      when :none
        # Do nothing on purpose
      else
        fail "Unsupported view for book results: #{view}"
      end
    end
  end
end

World(PageModels::SearchResultsActions)
{'fraction_non_alphanumeric': 0.05025996533795494, 'fraction_numerical': 0.0, 'mean_word_length': 3.5664556962025316, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7321413', 'n_tokens_mistral': 838, 'n_tokens_neox': 833, 'n_words': 204}