<commit_before>require File.expand_path(File.dirname(__FILE__) + '/common')

shared_examples_for "equation editor selenium tests" do
  it_should_behave_like "in-process server selenium tests"
  
  it "should support multiple equation editors on the same page" do
    course_with_teacher_logged_in
    
    get "/courses/#{@course.id}/quizzes"
    driver.find_element(:partial_link_text, "Create a New Quiz").click
    
    driver.current_url.should match %r{/courses/\d+/quizzes/(\d+)\/edit}
    driver.current_url =~ %r{/courses/\d+/quizzes/(\d+)\/edit}
    quiz_id = $1.to_i
    quiz_id.should be > 0
    quiz = Quiz.find(quiz_id)


    def save_question_and_wait(question)
      question.find_element(:css, "button[type='submit']").click
      keep_trying_until { question.find_element(:css, ".loading_image_holder").nil? rescue true }
    end
    
    new_question_link = driver.find_element(:link, "New Question")
    2.times do |time|
      new_question_link.click
      
      questions = find_all_with_jquery(".question_holder:visible")
      questions.length.should eql(time + 1)
      question = questions[time]
      
      wait_for_tiny(question.find_element(:css, 'textarea.question_content'))
      question.find_element(:css, '.mce_instructure_equation').click
  
      equation_editor = find_with_jquery("#instructure_equation_prompt:visible")
      equation_editor.find_element(:css, 'button').click
      question.find_element(:link, "Switch Views").click
      question.find_element(:css, 'textarea.question_content').attribute(:value).should include('<img class="equation_image" title="1+1" src="http://latex.codecogs.com/gif.latex?1+1" alt="1+1" />')
      save_question_and_wait(question)
<commit_msg>Updated spec for issue #5112, codecogs images<commit_after>require File.expand_path(File.dirname(__FILE__) + '/common')

shared_examples_for "equation editor selenium tests" do
  it_should_behave_like "in-process server selenium tests"
  
  it "should support multiple equation editors on the same page" do
    course_with_teacher_logged_in
    
    get "/courses/#{@course.id}/quizzes"
    driver.find_element(:partial_link_text, "Create a New Quiz").click
    
    driver.current_url.should match %r{/courses/\d+/quizzes/(\d+)\/edit}
    driver.current_url =~ %r{/courses/\d+/quizzes/(\d+)\/edit}
    quiz_id = $1.to_i
    quiz_id.should be > 0
    quiz = Quiz.find(quiz_id)


    def save_question_and_wait(question)
      question.find_element(:css, "button[type='submit']").click
      keep_trying_until { question.find_element(:css, ".loading_image_holder").nil? rescue true }
    end
    
    new_question_link = driver.find_element(:link, "New Question")
    2.times do |time|
      new_question_link.click
      
      questions = find_all_with_jquery(".question_holder:visible")
      questions.length.should eql(time + 1)
      question = questions[time]
      
      wait_for_tiny(question.find_element(:css, 'textarea.question_content'))
      question.find_element(:css, '.mce_instructure_equation').click
  
      equation_editor = find_with_jquery("#instructure_equation_prompt:visible")
      equation_editor.find_element(:css, 'button').click
      question.find_element(:link, "Switch Views").click
      question.find_element(:css, 'textarea.question_content').attribute(:value).should include('<img class="equation_image" title="1+1" src="/equation_images/1%2B1" alt="1+1" />')
      save_question_and_wait(question)

{'fraction_non_alphanumeric': 0.12770875469517481, 'fraction_numerical': 0.00722334585379948, 'mean_word_length': 4.174887892376682, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5192212', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1105, 'n_words': 184}