<commit_before>require_relative '../common'
require_relative '../helpers/quizzes_common'

describe 'publishing a quiz' do
  include_context "in-process server selenium tests"

  let(:quiz_helper) { Class.new { extend QuizzesCommon } }

  context 'as a teacher' do
    before(:each) do
      course_with_teacher_logged_in
      @quiz = quiz_helper.create_quiz_with_due_date(course: @course)
      @quiz.workflow_state = 'unavailable'
      @quiz.save!
    end

    context 'when on the quiz show page' do
      before(:each) do
        get "/courses/#{@course.id}/quizzes/#{@quiz.id}"
        f('#quiz-publish-link').click
      end

      context 'before the ajax calls finish' do
        it 'temporarily changes the button text to |Publishing...|', priority: "1", test_id: 398935 do
          expect(fj('.publish-text', '#quiz-publish-link').text).to include_text 'Publishing...'
        end
      end

      context 'after the ajax calls finish' do
        before(:each) { wait_for_ajaximations }

        it 'changes the button\'s text to \'Published\'', priority: "1", test_id: 140649 do
          driver.mouse.move_to f('#footer')
          expect(f('#quiz-publish-link').text.strip!.split("\n")[0]).to eq 'Published'
        end

        it 'changes the button text on hover to |Unpublish|', priority: "1", test_id: 398936 do
          expect(f('#quiz-publish-link').text.strip!.split("\n")[0]).to eq 'Unpublish'
        end

        it 'removes the \'This quiz is unpublished\' message', priority: "1", test_id: 398937 do
          expect(fj('.unpublished_warning', '.alert')).to be_nil
        end

        it 'adds links to the right sidebar', priority: "1", test_id: 398938 do
          links_text = []
          ffj('li', 'ul.page-action-list').each do |link|
            # also remove the trademark (TM) unicode character<commit_msg>spec: stabilize quizzes_publish_quiz_teacher_spec<commit_after>require_relative '../common'
require_relative '../helpers/quizzes_common'

describe 'publishing a quiz' do
  include_context "in-process server selenium tests"

  let(:quiz_helper) { Class.new { extend QuizzesCommon } }

  context 'as a teacher' do
    before(:each) do
      course_with_teacher_logged_in
      @quiz = quiz_helper.create_quiz_with_due_date(course: @course)
      @quiz.workflow_state = 'unavailable'
      @quiz.save!
    end

    context 'when on the quiz show page' do
      before(:each) do
        get "/courses/#{@course.id}/quizzes/#{@quiz.id}"
        f('#quiz-publish-link').click
      end

      context 'before the ajax calls finish' do
        it 'temporarily changes the button text to |Publishing...|', priority: "1", test_id: 398935 do
          expect(fj('.publish-text', '#quiz-publish-link').text).to include_text 'Publishing...'
        end
      end

      context 'after the ajax calls finish' do
        before(:each) do
          wait_for_ajaximations
          wait = Selenium::WebDriver::Wait.new(timeout: 5)
          wait.until do
            f('#quiz-publish-link').present? &&
            f('#quiz-publish-link').text.present? &&
            f('#quiz-publish-link').text.strip!.split("\n") != []
          end
        end

        it 'changes the button\'s text to \'Published\'', priority: "1", test_id: 140649 do
          driver.mouse.move_to f('#footer')
          expect(f('#quiz-publish-link').text.strip!.split("\n")[0]).to eq 'Published'
        end

        it 'changes the button text on hover to |Unpublish|', priority: "1", test_id: 398936 do
          expect(f('#quiz-publish-link').text.strip!.split("\n")[0]).to eq 'Unpublish'
        end

        it 'removes the \'This quiz is unpublished\' message', priority: "1", test_id: 398937 do
          expect(fj('.unpublished_warning', '.alert')).to be_nil
        end

        it 'adds links to the right sidebar', priority: "1", test_id: 398938 do
          links_text = []
          ffj('li', 'ul.page-action-list').each do |link|
            # also remove the trademark (TM) unicode character
{'fraction_non_alphanumeric': 0.13612565445026178, 'fraction_numerical': 0.018698578908002993, 'mean_word_length': 2.6605839416058394, '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': '6125012', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1225, 'n_words': 330}