<commit_before># frozen_string_literal: true

#
# Copyright (C) 2021 - 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/k5_dashboard_page'
require_relative '../pages/k5_dashboard_common_page'
require_relative '../pages/k5_grades_tab_page'
require_relative '../../grades/setup/gradebook_setup'
require_relative '../pages/k5_schedule_tab_page'
require_relative '../pages/k5_resource_tab_page'
require_relative '../../../helpers/k5_common'

describe "observer k5 dashboard" do
  include_context "in-process server selenium tests"
  include K5DashboardPageObject
  include K5DashboardCommonPageObject
  include K5Common
  include K5ScheduleTabPageObject
  include K5GradesTabPageObject
  include GradebookSetup
  include K5ResourceTabPageObject

  before :once do
    Account.site_admin.enable_feature!(:k5_parent_support)
    student_setup
    observer_setup
  end

  before :each do
    user_session @observer
    driver.manage.delete_cookie('k5_observed_user_id')
  end

  context 'single observed student' do
    it 'defaults to the one observed student' do
      get "/"

      expect(element_value_for_attr(observed_student_dropdown,'value')).to eq('K5Student')
    end

    it 'shows the homeroom announcement and subject for the one observed student' do
      announcement_heading1 = "K5 Do this"
      announcement_content1 = "So happy to see all of you."
      new_announcement(@homeroom_course, announcement_heading1, announcement_content1)

      get "/"

      expect(dashboard_card_specific_subject('Science')).to be_displayed
      expect(announcement_title(announcement_heading1)).to be_displayed
    end

    it 'shows missing assignments on dashboard schedule tab' do
      skip("needs at least LS-2481")
      now = Time.zone.now
      create_dated_assignment(@subject_course, 'missing assignment1', 1.day.ago(now))
      create_dated_assignment(@subject_course, 'missing assignment2', 1.day.ago(now))

      get "/#schedule"

      expect(missing_data.text).to eq('Show 2 missing items')
    end

    it 'show the grades progress bar with the appropriate progress' do
      skip("LS-2582 grades not working right now")
      subject_grade = "75"

      assignment = create_and_submit_assignment(@subject_course, "Assignment 1", "new assignment", 100)
      assignment.grade_student(@student, grader: @homeroom_teacher, score: subject_grade, points_deducted: 0)

      get "/#grades"

      expect(grade_progress_bar(subject_grade)).to be_displayed
    end

    it 'shows the Important Info for the main resources tab' do
      important_info_text = "Show me what you can do"
      create_important_info_content(@homeroom_course, important_info_text)

      get "/#resources"
      expect(important_info_content).to include_text(important_info_text)
    end

    it 'shows the LTI resources for account and course on resources page' do
      lti_resource_name = 'Commons'
      create_lti_resource(lti_resource_name)

      get "/#resources"

      expect(k5_app_buttons[0].text).to eq lti_resource_name
    end
  end

  context 'multiple observed students' do
    before :once do
      @new_students = []
      2.times do |x|
        course_with_student(
          active_all: true,
          name: "My#{x + 1} Student",
          course: @homeroom_course
        )
        add_linked_observer(@student, @observer, root_account: @account)
        @new_students << @student
      end

      course_with_student(
        active_course: true,
        course_name: "Art",
        user: @new_students[0]
      )
      @art_course = @course

      course_with_student(
        active_all: true,
        user: @new_students[1],
        course: @subject_course
      )
    end

    it 'provides a dropdown for multiple observed students' do
      get "/"

      expect(observed_student_dropdown).to be_displayed

      expect(element_value_for_attr(observed_student_dropdown,'value')).to eq('K5Student')
    end

    it 'selects a student from the dropdown list' do
      get "/"

      click_observed_student_option('My1 Student')

      expect(element_value_for_attr(observed_student_dropdown,'value')).to eq('My1 Student')
      expect(dashboard_card_specific_subject('Art')).to be_displayed
    end

    it 'selects allows for searching for a student in dropdown list' do
      get "/"

      observed_student_dropdown.send_keys([:control, 'a'], :backspace, 'My2')
      click_observed_student_option('My2 Student')

      expect(element_value_for_attr(observed_student_dropdown,'value')).to eq('My2 Student')
      expect(dashboard_card_specific_subject('Science')).to be_displayed
    end

    it 'shows the observers name first if observer is also a student', ignore_js_errors: true do
      course_with_student(
        active_all: true,
        user: @observer,
        course: @art_course
      )

      get "/"

      expect(element_value_for_attr(observed_student_dropdown,'value')).to eq('Mom')
      expect(dashboard_card_specific_subject('Art')).to be_displayed
    end
  end
end<commit_msg>spec: observer subject dashboard selenium tests<commit_after># frozen_string_literal: true

#
# Copyright (C) 2021 - 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/k5_dashboard_page'
require_relative '../pages/k5_dashboard_common_page'
require_relative '../pages/k5_grades_tab_page'
require_relative '../../grades/setup/gradebook_setup'
require_relative '../pages/k5_schedule_tab_page'
require_relative '../pages/k5_resource_tab_page'
require_relative '../../../helpers/k5_common'

describe "observer k5 dashboard" do
  include_context "in-process server selenium tests"
  include K5DashboardPageObject
  include K5DashboardCommonPageObject
  include K5Common
  include K5ScheduleTabPageObject
  include K5GradesTabPageObject
  include GradebookSetup
  include K5ResourceTabPageObject

  before :once do
    Account.site_admin.enable_feature!(:k5_parent_support)
    student_setup
    observer_setup
  end

  before :each do
    user_session @observer
    driver.manage.delete_cookie('k5_observed_user_id')
  end

  context 'single observed student' do
    it 'defaults to the one observed student' do
      get "/"

      expect(element_value_for_attr(observed_student_dropdown,'value')).to eq('K5Student')
    end

    it 'shows the homeroom announcement and subject for the one observed student' do
      announcement_heading1 = "K5 Do this"
      announcement_content1 = "So happy to see all of you."
      new_announcement(@homeroom_course, announcement_heading1, announcement_content1)

      get "/"

      expect(dashboard_card_specific_subject('Science')).to be_displayed
      expect(announcement_title(announcement_heading1)).to be_displayed
    end

    it 'shows missing assignments on dashboard schedule tab' do
      skip("needs at least LS-2481")
      now = Time.zone.now
      create_dated_assignment(@subject_course, 'missing assignment1', 1.day.ago(now))
      create_dated_assignment(@subject_course, 'missing assignment2', 1.day.ago(now))

      get "/#schedule"

      expect(missing_data.text).to eq('Show 2 missing items')
    end

    it 'show the grades progress bar with the appropriate progress' do
      skip("LS-2582 grades not working right now")
      subject_grade = "75"

      assignment = create_and_submit_assignment(@subject_course, "Assignment 1", "new assignment", 100)
      assignment.grade_student(@student, grader: @homeroom_teacher, score: subject_grade, points_deducted: 0)

      get "/#grades"

      expect(grade_progress_bar(subject_grade)).to be_displayed
    end

    it 'shows the Important Info for the main resources tab' do
      important_info_text = "Show me what you can do"
      create_important_info_content(@homeroom_course, important_info_text)

      get "/#resources"
      expect(important_info_content).to include_text(important_info_text)
    end

    it 'shows the LTI resources for account and course on resources page' do
      lti_resource_name = 'Commons'
      create_lti_resource(lti_resource_name)

      get "/#resources"

      expect(k5_app_buttons[0].text).to eq lti_resource_name
    end
  end

  context 'multiple observed students' do
    before :once do
      @new_students = []
      2.times do |x|
        course_with_student(
          active_all: true,
          name: "My#{x + 1} Student",
          course: @homeroom_course
        )
        add_linked_observer(@student, @observer, root_account: @account)
        @new_students << @student
      end

      course_with_student(
        active_course: true,
        course_name: "Art",
        user: @new_students[0]
      )
      @art_course = @course

      course_with_student(
        active_all: true,
        user: @new_students[1],
        course: @subject_course
      )
    end

    it 'provides a dropdown for multiple observed students' do
      get "/"

      expect(observed_student_dropdown).to be_displayed

      expect(element_value_for_attr(observed_student_dropdown,'value')).to eq('K5Student')
    end

    it 'selects a student from the dropdown list' do
      get "/"

      click_observed_student_option('My1 Student')

      expect(element_value_for_attr(observed_student_dropdown,'value')).to eq('My1 Student')
      expect(dashboard_card_specific_subject('Art')).to be_displayed
    end

    it 'selects allows for searching for a student in dropdown list' do
      get "/"

      observed_student_dropdown.send_keys([:control, 'a'], :backspace, 'My2')
      click_observed_student_option('My2 Student')

      expect(element_value_for_attr(observed_student_dropdown,'value')).to eq('My2 Student')
      expect(dashboard_card_specific_subject('Science')).to be_displayed
    end

    it 'shows the observers name first if observer is also a student' do
      course_with_student(
        active_all: true,
        user: @observer,
        course: @art_course
      )

      get "/"

      expect(element_value_for_attr(observed_student_dropdown,'value')).to eq('Mom')
      expect(dashboard_card_specific_subject('Art')).to be_displayed
    end

    it 'shows the dropdown picker on subject dashboard and first student on list' do
      get "/courses/#{@subject_course.id}#home"

      expect(element_value_for_attr(observed_student_dropdown,'value')).to eq('K5Student')
    end

    it 'selects student from list on subject drop down menu', ignore_js_errors: true do
      get "/courses/#{@subject_course.id}#home"

      click_observed_student_option('My2 Student')

      expect(element_value_for_attr(observed_student_dropdown,'value')).to eq('My2 Student')
    end

    it 'allows for searching for a student in subject dropdown list', ignore_js_errors: true do
      get "/courses/#{@subject_course.id}#home"

      observed_student_dropdown.send_keys([:control, 'a'], :backspace, 'My2')
      click_observed_student_option('My2 Student')

      expect(element_value_for_attr(observed_student_dropdown,'value')).to eq('My2 Student')
    end
  end

  context 'k5 subject dashboard observee selections' do
    let (:wiki_page_data) { "Here's where we have content" }

    before :once do
      @subject_course.wiki_pages.create!(:title => "K5 Course Front Page", :body => wiki_page_data).set_as_front_page!
    end

    it 'has students front page displayed if there is one' do
      get "/courses/#{@subject_course.id}#home"

      expect(front_page_info.text).to eq(wiki_page_data)
    end

    it 'shows schedule info for course items' do
      skip("LS-2481 Planner work todo")
      create_dated_assignment(@subject_course, 'today assignment1', @now)

      get "/courses/#{@subject_course.id}#schedule"

      expect(today_header).to be_displayed
      expect(schedule_item.text).to include('today assignment1')
    end

    it 'shows late assignment as Missing' do
      skip("LS-2582 grades not working right now")
      create_dated_assignment(@subject_course, "assignment 2 missing", 1.day.ago(Time.zone.now), 15)

      get "/courses/#{@subject_course.id}#grades"

      expect(grades_assignments_list[0].text).to include("Missing")
    end

    it 'shows the Important Info for subject resources tab' do
      important_info_text = "Show me what you can do"
      create_important_info_content(@subject_course, important_info_text)
      create_lti_resource("fake LTI")
      get "/courses/#{@subject_course.id}#resources"

      expect(important_info_content).to include_text(important_info_text)
    end

    it 'shows the observers name first if observer is also a student' do
      course_with_student(
        active_all: true,
        user: @observer,
        course: @subject_course
      )

      get "/courses/#{@subject_course.id}#home"

      expect(element_value_for_attr(observed_student_dropdown,'value')).to eq('Mom')
      expect(front_page_info.text).to eq(wiki_page_data)
    end
  end
end
{'fraction_non_alphanumeric': 0.08849119332248709, 'fraction_numerical': 0.009973827544740752, 'mean_word_length': 3.6445466491458607, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3402184', 'n_tokens_mistral': 4296, 'n_tokens_neox': 4128, 'n_words': 1135}