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

describe "Wiki Pages" do
  include_examples "in-process server selenium tests"

  context "Navigation" do
    before do
      account_model
      course_with_teacher_logged_in :account => @account
    end

    it "should navigate to pages tab with no front page set", priority: "1", test_id: 126843 do
      @course.wiki.wiki_pages.create!(title: 'Page1')
      @course.wiki.wiki_pages.create!(title: 'Page2')
      get "/courses/#{@course.id}"
      f('.pages').click()
      expect(driver.current_url).to include("/courses/#{@course.id}/pages")
      expect(driver.current_url).not_to include("/courses/#{@course.id}/wiki")
      get "/courses/#{@course.id}/wiki"
      expect(driver.current_url).to include("/courses/#{@course.id}/pages")
      expect(driver.current_url).not_to include("/courses/#{@course.id}/wiki")
    end

    it "should navigate to front page when set", priority: "1", test_id: 126844 do
      front = @course.wiki.wiki_pages.create!(title: 'Front')
      front.set_as_front_page!
      front.save!
      get "/courses/#{@course.id}"
      f('.pages').click()
      expect(driver.current_url).not_to include("/courses/#{@course.id}/pages")
      expect(driver.current_url).to include("/courses/#{@course.id}/wiki")
      expect(f('span.front-page.label')).to include_text 'Front Page'
      get "/courses/#{@course.id}/pages"
      expect(driver.current_url).to include("/courses/#{@course.id}/pages")
      expect(driver.current_url).not_to include("/courses/#{@course.id}/wiki")
    end

    it "navigates to the wiki pages edit page from the show page" do
      wikiPage = @course.wiki.wiki_pages.create!(:title => "Foo")
      edit_url = edit_course_wiki_page_url(@course, wikiPage)
      get course_wiki_page_path(@course, wikiPage)

      f(".edit-wiki").click

      keep_trying_until { expect(driver.current_url).to eq edit_url }
    end

    it "should alert a teacher when accessing a non-existant page", priority: "1", test_id: 126842 do
      get "/courses/#{@course.id}/pages/fake"<commit_msg>add should have correct front page UI elements when set as home page spec<commit_after>require File.expand_path(File.dirname(__FILE__) + '/common')
require File.expand_path(File.dirname(__FILE__) + '/helpers/wiki_and_tiny_common')
require File.expand_path(File.dirname(__FILE__) + '/helpers/public_courses_context')

describe "Wiki Pages" do
  include_examples "in-process server selenium tests"

  context "Navigation" do
    before do
      account_model
      course_with_teacher_logged_in :account => @account
    end

    it "should navigate to pages tab with no front page set", priority: "1", test_id: 126843 do
      @course.wiki.wiki_pages.create!(title: 'Page1')
      @course.wiki.wiki_pages.create!(title: 'Page2')
      get "/courses/#{@course.id}"
      f('.pages').click()
      expect(driver.current_url).to include("/courses/#{@course.id}/pages")
      expect(driver.current_url).not_to include("/courses/#{@course.id}/wiki")
      get "/courses/#{@course.id}/wiki"
      expect(driver.current_url).to include("/courses/#{@course.id}/pages")
      expect(driver.current_url).not_to include("/courses/#{@course.id}/wiki")
    end

    it "should navigate to front page when set", priority: "1", test_id: 126844 do
      front = @course.wiki.wiki_pages.create!(title: 'Front')
      front.set_as_front_page!
      front.save!
      get "/courses/#{@course.id}"
      f('.pages').click()
      expect(driver.current_url).not_to include("/courses/#{@course.id}/pages")
      expect(driver.current_url).to include("/courses/#{@course.id}/wiki")
      expect(f('span.front-page.label')).to include_text 'Front Page'
      get "/courses/#{@course.id}/pages"
      expect(driver.current_url).to include("/courses/#{@course.id}/pages")
      expect(driver.current_url).not_to include("/courses/#{@course.id}/wiki")
    end

    it "should have correct front page UI elements when set as home page", priority: "1", test_id: 126848 do
      front = @course.wiki.wiki_pages.create!(title: 'Front')
      front.set_as_front_page!
      front.save!
      get "/courses/#{@course.id}/wiki"
      f('.home').click()
      # setting front-page as home page
      fj('.btn.button-sidebar-wide:contains("Choose Home Page")').click()
      fj('input[type=radio][value=wiki]').click()
      fj('button.btn.btn-primary.button_type_submit.ui-button.ui-widget.ui-state-default.ui-corner-all.ui-button-text-only').click()
      f('.home').click()
      wait_for_ajaximations
      # validations
      expect(element_exists('.al-trigger')).to be_truthy
      expect(f('.course-title')).to include_text 'Unnamed Course'
      expect(element_exists('span.front-page.label')).to be_falsey
      expect(element_exists('button.btn.btn-published')).to be_falsey
      f('.al-trigger').click()
      expect(element_exists('.icon-trash')).to be_falsey
      expect(element_exists('.icon-clock')).to be_truthy
    end

    it "navigates to the wiki pages edit page from the show page" do
      wikiPage = @course.wiki.wiki_pages.create!(:title => "Foo")
      edit_url = edit_course_wiki_page_url(@course, wikiPage)
      get course_wiki_page_path(@course, wikiPage)

      f(".edit-wiki").click

      keep_trying_until { expect(driver.current_url).to eq edit_url }
    end

    it "should alert a teacher when accessing a non-existant page", priority: "1", test_id: 126842 do
      get "/courses/#{@course.id}/pages/fake"
{'fraction_non_alphanumeric': 0.15296602710790355, 'fraction_numerical': 0.009329343425453265, 'mean_word_length': 3.707539353769677, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1342829', 'n_tokens_mistral': 1869, 'n_tokens_neox': 1813, 'n_words': 353}