<commit_before>require 'spec_helper'
require 'support/line_comment_replies_shared_examples'

RSpec.describe 'Files changed page' do
  let(:driver) { EprSpecHelper.driver }
  let(:pr_url) do
    'https://github.com/tobyhs/enhanced_pull_request/pull/1/files'
  end

  before do
    driver.get(pr_url) unless driver.current_url == pr_url
  end

  it_behaves_like 'a page with line comment replies'

  context 'after clicking a one-file diff link' do
    before do
      driver.find_element(:id, 'one-file-diff-btn').click
      link = "#{pr_url}?eprFocus=sandbox/hello.rb"
      driver.find_element(:css, %(a[href="#{link}"])).click
    end

    it 'has a title with the file name' do
      Selenium::WebDriver::Wait.new(
        message: 'Title does not contain the file name'
      ).until { driver.title.start_with?('sandbox/hello.rb') }
    end

    it 'only shows the diff of the selected file' do
      Selenium::WebDriver::Wait.new.until do
        !driver.
          find_element(:css, '.file-header[data-path="sandbox/hello.py"]').
          displayed?
      end
      expect(
        driver.find_element(:css, '.file-header[data-path="sandbox/hello.rb"]')
      ).to be_displayed
    end
  end<commit_msg>Improve flakiness of one-file diff tests<commit_after>require 'spec_helper'
require 'support/line_comment_replies_shared_examples'

RSpec.describe 'Files changed page' do
  let(:driver) { EprSpecHelper.driver }
  let(:pr_url) do
    'https://github.com/tobyhs/enhanced_pull_request/pull/1/files'
  end

  before do
    driver.get(pr_url) unless driver.current_url == pr_url
  end

  it_behaves_like 'a page with line comment replies'

  it 'has one-file diff links' do
    unless driver.find_element(:class, 'epr-one-file-diff').displayed?
      driver.find_element(:id, 'one-file-diff-btn').click
    end
    link = "#{pr_url}?eprFocus=sandbox/hello.rb"
    expect(driver.find_element(:css, %(a[href="#{link}"]))).to be_displayed
  end

  context 'on a one-file diff page' do
    let(:file) { 'sandbox/hello.rb' }

    let(:pr_url) do
      'https://github.com/tobyhs/enhanced_pull_request/pull/1/files' \
        "?eprFocus=#{file}"
    end

    it 'has a title with the file name' do
      Selenium::WebDriver::Wait.new(
        message: 'Title does not contain the file name'
      ).until { driver.title.start_with?(file) }
    end

    it 'only shows the diff of the selected file' do
      Selenium::WebDriver::Wait.new.until do
        !driver.
          find_element(:css, '.file-header[data-path="sandbox/hello.py"]').
          displayed?
      end

      expect(
        driver.find_element(:css, %(.file-header[data-path="#{file}"]))
      ).to be_displayed
    end
  end
{'fraction_non_alphanumeric': 0.13019287833827894, 'fraction_numerical': 0.001112759643916914, 'mean_word_length': 3.1301684532924963, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, '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': '5294319', 'n_tokens_mistral': 934, 'n_tokens_neox': 901, 'n_words': 201}