require 'spec_helper'

RSpec.describe 'Conversation page' do
  let(:driver) { EprSpecHelper.driver }

  before do
    pr_url = 'https://github.com/tobyhs/enhanced_pull_request/pull/1'
    driver.get(pr_url) unless driver.current_url == pr_url
  end

  context 'when clicking on the Outdated Diff Comments buttons' do
    it 'shows and hides the comments on the outdated diffs' do
      outdated_comments = driver.find_elements(:css, '#r55944545, #discussion_r84420650')

      [
        ['epr-show-outdated-comments', true],
        ['epr-hide-outdated-comments', false],
      ].each do |class_name, displayed|
        expect {
          driver.find_element(:class, class_name).click
        }.to change {
          outdated_comments.map(&:displayed?).uniq
        }.from([!displayed]).to([displayed])
      end
    end
  end
end

require 'spec_helper'

RSpec.describe 'Conversation page' do
  let(:driver) { EprSpecHelper.driver }

  before do
    pr_url = 'https://github.com/tobyhs/enhanced_pull_request/pull/1'
    driver.get(pr_url) unless driver.current_url == pr_url
  end

  context 'when clicking on the Outdated Diff Comments buttons' do
    it 'shows and hides the comments on the outdated diffs' do
      driver.find_element(:class, 'epr-show-outdated-comments').click
      outdated_comment = nil
      Selenium::WebDriver::Wait.new.until do
        outdated_comment = driver.find_element(:id, 'discussion_r84420650')
      end
      expect(outdated_comment).to be_displayed

      driver.find_element(:class, 'epr-hide-outdated-comments').click
      expect(outdated_comment).not_to be_displayed
    end
  end
end

Fix outdated diff comments test
Fix outdated diff comments test

It looks like GitHub now loads some of these outdated comments via AJAX
and not on the initial page load.
