<commit_before>#
# Copyright (C) 2017 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

require_relative '../common'
require_relative 'pages/student_planner_page'
require_relative '../admin/pages/student_context_tray_page'
require_relative '../assignments/page_objects/assignment_page'

describe "student planner" do
  include_context "in-process server selenium tests"
  include PlannerPageObject

  before :once do
    Account.default.enable_feature!(:student_planner)
    course_with_teacher(active_all: true, new_user: true, user_name: 'PlannerTeacher', course_name: 'Planner Course')
    @student1 = User.create!(name: 'Student 1')
    @course.enroll_student(@student1).accept!
  end

  before :each do
    user_session(@student1)
  end

  it "shows no due date assigned when no assignments are created.", priority: "1", test_id: 3265570 do
    go_to_list_view
    validate_no_due_dates_assigned
  end

  it "navigates to the dashcard view from no due dates assigned page.", priority: "1", test_id: 3281739 do
    go_to_list_view
    switch_to_dashcard_view

    expect(dashboard_card_container).to contain_css("[aria-label='#{@course.name}']")
    expect(dashboard_card_header_content).to contain_css("h2[title='#{@course.name}']")
  end

  it "shows and navigates to announcements page from student planner", priority: "1", test_id: 3259302 do
    announcement = @course.announcements.create!(title: 'Hi there!', message: 'Announcement time!')
    go_to_list_view
    validate_object_displayed(@course.name,'Announcement')
    validate_link_to_url(announcement, 'discussion_topics')
  end

  it "shows and navigates to the calendar events page", priority: "1", test_id: 3488530 do
    event = CalendarEvent.new(title: "New event", start_at: 1.minute.from_now)
    event.context = @course
    event.save!
    go_to_list_view
    validate_object_displayed(@course.name,'Calendar Event')
    validate_link_to_calendar(event)
  end

  it "shows course images when the feature is enabled", priority: "1", test_id: 3306206 do
    Account.default.enable_feature!(:course_card_images)
    @course_root = Folder.root_folders(@course).first
    @course_attachment = @course_root.attachments.create!(:context => @course,
                                                          :uploaded_data => jpeg_data_frd, :filename => 'course.jpg',
                                                          :display_name => 'course.jpg')
    @course.image_id = @course_attachment.id
    @course.save!
    @course.announcements.create!(title: 'Hi there!', message: 'Announcement time!')
    go_to_list_view
    validate_object_displayed(@course.name,'Announcement')
    elem = f("a[href='/courses/#{@course.id}']")
    url = driver.current_url
    # validate the background image url
    expect(elem[:style]).
      to include("#{url}courses/#{@course.id}/files/#{@course_attachment.id}/download?verifier=#{@course_attachment.uuid}")

  end

  context "responsive layout" do
    before :each do
      resize_screen_to_default
    end
    after :each do
      resize_screen_to_default
    end

    it "changes layout on browser resize" do
      go_to_list_view

      expect(f('.large.ic-Dashboard-header__layout')).to be
      expect(f('.large.PlannerApp')).to be

      dimension = driver.manage.window.size
      driver.manage.window.resize_to(800, dimension.height)
      expect(f('.medium.ic-Dashboard-header__layout')).to be
      expect(f('.medium.PlannerApp')).to be

      driver.manage.window.resize_to(500, dimension.height)
      expect(f('.small.ic-Dashboard-header__layout')).to be
      expect(f('.small.PlannerApp')).to be
    end
  end

  context "wiki_pages" do
    before :once do
      @wiki_page = @course.wiki_pages.create!(title: 'Page1', todo_date: Time.zone.now + 2.days)
    end

    it 'shows the date in the index page' do
      get "/courses/#{@course.id}/pages/"
      wait_for_ajaximations
      expect(f('a[data-sort-field="todo_date"]')).to be_displayed
      expect(f('tbody.collectionViewItems')).to include_text(format_time_for_view(@wiki_page.todo_date))
    end

    it 'shows the date in the show page' do
      get "/courses/#{@course.id}/pages/#{@wiki_page.id}/"
      expect(f('.show-content')).to include_text(format_time_for_view(@wiki_page.todo_date))
    end
  end

  context "Quizzes" do
    before :once do<commit_msg>spec: set minutes to avoid minutes == 0 situation<commit_after>#
# Copyright (C) 2017 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

require_relative '../common'
require_relative 'pages/student_planner_page'
require_relative '../admin/pages/student_context_tray_page'
require_relative '../assignments/page_objects/assignment_page'

describe "student planner" do
  include_context "in-process server selenium tests"
  include PlannerPageObject

  before :once do
    Account.default.enable_feature!(:student_planner)
    course_with_teacher(active_all: true, new_user: true, user_name: 'PlannerTeacher', course_name: 'Planner Course')
    @student1 = User.create!(name: 'Student 1')
    @course.enroll_student(@student1).accept!
  end

  before :each do
    user_session(@student1)
  end

  it "shows no due date assigned when no assignments are created.", priority: "1", test_id: 3265570 do
    go_to_list_view
    validate_no_due_dates_assigned
  end

  it "navigates to the dashcard view from no due dates assigned page.", priority: "1", test_id: 3281739 do
    go_to_list_view
    switch_to_dashcard_view

    expect(dashboard_card_container).to contain_css("[aria-label='#{@course.name}']")
    expect(dashboard_card_header_content).to contain_css("h2[title='#{@course.name}']")
  end

  it "shows and navigates to announcements page from student planner", priority: "1", test_id: 3259302 do
    announcement = @course.announcements.create!(title: 'Hi there!', message: 'Announcement time!')
    go_to_list_view
    validate_object_displayed(@course.name,'Announcement')
    validate_link_to_url(announcement, 'discussion_topics')
  end

  it "shows and navigates to the calendar events page", priority: "1", test_id: 3488530 do
    event = CalendarEvent.new(title: "New event", start_at: 1.minute.from_now)
    event.context = @course
    event.save!
    go_to_list_view
    validate_object_displayed(@course.name,'Calendar Event')
    validate_link_to_calendar(event)
  end

  it "shows course images when the feature is enabled", priority: "1", test_id: 3306206 do
    Account.default.enable_feature!(:course_card_images)
    @course_root = Folder.root_folders(@course).first
    @course_attachment = @course_root.attachments.create!(:context => @course,
                                                          :uploaded_data => jpeg_data_frd, :filename => 'course.jpg',
                                                          :display_name => 'course.jpg')
    @course.image_id = @course_attachment.id
    @course.save!
    @course.announcements.create!(title: 'Hi there!', message: 'Announcement time!')
    go_to_list_view
    validate_object_displayed(@course.name,'Announcement')
    elem = f("a[href='/courses/#{@course.id}']")
    url = driver.current_url
    # validate the background image url
    expect(elem[:style]).
      to include("#{url}courses/#{@course.id}/files/#{@course_attachment.id}/download?verifier=#{@course_attachment.uuid}")

  end

  context "responsive layout" do
    before :each do
      resize_screen_to_default
    end
    after :each do
      resize_screen_to_default
    end

    it "changes layout on browser resize" do
      go_to_list_view

      expect(f('.large.ic-Dashboard-header__layout')).to be
      expect(f('.large.PlannerApp')).to be

      dimension = driver.manage.window.size
      driver.manage.window.resize_to(800, dimension.height)
      expect(f('.medium.ic-Dashboard-header__layout')).to be
      expect(f('.medium.PlannerApp')).to be

      driver.manage.window.resize_to(500, dimension.height)
      expect(f('.small.ic-Dashboard-header__layout')).to be
      expect(f('.small.PlannerApp')).to be
    end
  end

  context "wiki_pages" do
    before :once do
      @wiki_page = @course.wiki_pages.create!(title: 'Page1', todo_date: DateTime.current.change({min: 5}) + 2.days)
    end

    it 'shows the date in the index page' do
      get "/courses/#{@course.id}/pages/"
      wait_for_ajaximations
      expect(f('a[data-sort-field="todo_date"]')).to be_displayed
      expect(f('tbody.collectionViewItems')).to include_text(format_time_for_view(@wiki_page.todo_date))
    end

    it 'shows the date in the show page' do
      get "/courses/#{@course.id}/pages/#{@wiki_page.id}/"
      expect(f('.show-content')).to include_text(format_time_for_view(@wiki_page.todo_date))
    end
  end

  context "Quizzes" do
    before :once do
{'fraction_non_alphanumeric': 0.11133400200601805, 'fraction_numerical': 0.012036108324974924, 'mean_word_length': 3.761700095510984, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4220599', 'n_tokens_mistral': 3163, 'n_tokens_neox': 3060, 'n_words': 785}