<commit_before>require 'rails_helper'

feature "AdditionOfEstimationsAndItems", :type => :feature do
  let(:user) { FactoryGirl.create(:user_with_nonempty_estimations) }
  let(:estimation) { user.estimations.first }

  let(:new_estimation_title) { 'Kapandlya' }
  let(:new_estimation_value) { 7 }

  let(:old_estimation_value) { estimation.estimation_items.first.value }

  before(:each) do
    login_as user
    visit estimation_path(estimation)
  end

  scenario 'I can modify the estimation item title', :js do
    expect(page).not_to have_text new_estimation_title

    page.find('span.editable.title', text: estimation.estimation_items.first.title).click
    expect(page).to have_css('.editable-inline')

    page.find('.editable-inline .editable-input input').set new_estimation_title
    page.find('.editable-inline .editable-submit').click

    wait_for_ajax

    expect(page).to have_text new_estimation_title

    visit current_path
    expect(page).to have_text new_estimation_title
  end

  scenario 'I can modify estimation item value', :js do
    expect(page).not_to have_text new_estimation_value

    page.find('span.editable.value', text: estimation.estimation_items.first.value).click
    page.find('.editable-inline .editable-input input').set new_estimation_value
    page.find('.editable-inline .editable-submit').click

    wait_for_ajax

    expect(page).to have_text new_estimation_value
    expect(page).to have_text '7 + 7 = 14'
  end

  scenario 'AJAX-added items are editable', :js do

    fill_in 'estimation_item_value', with: new_estimation_value
    fill_in 'estimation_item_title', with: new_estimation_title
    click_button 'Add estimation item'

    wait_for_ajax

    expect(page).to have_css('span.editable.value', count: estimation.estimation_items.count)
    expect(page).to have_css('span.editable.title', count: estimation.estimation_items.count)
    expect(page).to have_css('span.editable.quantity', count: estimation.estimation_items.count)

    page.find('span.editable', text: estimation.estimation_items.last.value).click
    
    expect(page).to have_css('.editable-inline')
  end

  scenario 'I can mark estimation item as fixed', :js do
    find(:css, '.toggle-fixed').click

    expect(page).to have_text "#{old_estimation_value} + 0 = #{old_estimation_value}"
  end

  scenario 'I can set the number for a batch', :js do
    page.find('span.editable.quantity').click
    page.find('.editable-inline .editable-input input').set '4'
    page.find('.editable-inline .editable-submit').click

    expect(page).to have_text "#{4*old_estimation_value} + #{2*old_estimation_value} = #{6*old_estimation_value}"
  end

  scenario 'I can see updated total when estimation or count has been changed', :js do

    page.find('span.editable.quantity').click
    page.find('.editable-inline .editable-input input').set '20'
    page.find('.editable-inline .editable-submit').click

    page.find('span.editable.value').click
    page.find('.editable-inline .editable-input input').set '17'
    page.find('.editable-inline .editable-submit').click

    wait_for_ajax

    expect(page).to have_text '= 340'
  end
end<commit_msg>Woraround to sleep a little bit more<commit_after>require 'rails_helper'

feature "AdditionOfEstimationsAndItems", :type => :feature do
  let(:user) { FactoryGirl.create(:user_with_nonempty_estimations) }
  let(:estimation) { user.estimations.first }

  let(:new_estimation_title) { 'Kapandlya' }
  let(:new_estimation_value) { 7 }

  let(:old_estimation_value) { estimation.estimation_items.first.value }

  before(:each) do
    login_as user
    visit estimation_path(estimation)
  end

  scenario 'I can modify the estimation item title', :js do
    expect(page).not_to have_text new_estimation_title

    page.find('span.editable.title', text: estimation.estimation_items.first.title).click
    expect(page).to have_css('.editable-inline')

    page.find('.editable-inline .editable-input input').set new_estimation_title
    page.find('.editable-inline .editable-submit').click

    wait_for_ajax

    expect(page).to have_text new_estimation_title

    visit current_path
    expect(page).to have_text new_estimation_title
  end

  scenario 'I can modify estimation item value', :js do
    expect(page).not_to have_text new_estimation_value

    page.find('span.editable.value', text: estimation.estimation_items.first.value).click
    page.find('.editable-inline .editable-input input').set new_estimation_value
    page.find('.editable-inline .editable-submit').click

    wait_for_ajax

    expect(page).to have_text new_estimation_value
    expect(page).to have_text '7 + 7 = 14'
  end

  scenario 'AJAX-added items are editable', :js do

    fill_in 'estimation_item_value', with: new_estimation_value
    fill_in 'estimation_item_title', with: new_estimation_title
    click_button 'Add estimation item'

    wait_for_ajax

    expect(page).to have_css('span.editable.value', count: estimation.estimation_items.count)
    expect(page).to have_css('span.editable.title', count: estimation.estimation_items.count)
    expect(page).to have_css('span.editable.quantity', count: estimation.estimation_items.count)

    page.find('span.editable', text: estimation.estimation_items.last.value).click
    
    expect(page).to have_css('.editable-inline')
  end

  scenario 'I can mark estimation item as fixed', :js do
    find(:css, '.toggle-fixed').click

    expect(page).to have_text "#{old_estimation_value} + 0 = #{old_estimation_value}"
  end

  scenario 'I can set the number for a batch', :js do
    page.find('span.editable.quantity').click
    page.find('.editable-inline .editable-input input').set '4'
    page.find('.editable-inline .editable-submit').click

    expect(page).to have_text "#{4*old_estimation_value} + #{2*old_estimation_value} = #{6*old_estimation_value}"
  end

  scenario 'I can see updated total when estimation or count has been changed', :js do

    page.find('span.editable.quantity').click
    page.find('.editable-inline .editable-input input').set '20'
    page.find('.editable-inline .editable-submit').click

    page.find('span.editable.value').click
    page.find('.editable-inline .editable-input input').set '17'
    page.find('.editable-inline .editable-submit').click

    wait_for_ajax
    sleep(1)

    expect(page).to have_text '= 340'
  end
end
{'fraction_non_alphanumeric': 0.12036455059710874, 'fraction_numerical': 0.005499685732243872, 'mean_word_length': 4.357744107744108, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6327937', 'n_tokens_mistral': 2093, 'n_tokens_neox': 2014, 'n_words': 414}