<commit_before>#
# Copyright (C) 2012 - 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 File.expand_path(File.dirname(__FILE__) + '/common')

describe "profile communication settings new ui" do
  include_context "in-process server selenium tests"

  before :each do
    Account.site_admin.enable_feature!(:notification_update_account_ui)

    Notification.create(:name => "Conversation Message", :category => "DiscussionEntry")
    Notification.create(:name => "Added To Conversation", :category => "Discussion")
    Notification.create(:name => "GradingStuff1", :category => "Grading")
    @sub_comment = Notification.create(:name => "Submission Comment1", :category => "Submission Comment")

    course_with_teacher_logged_in
  end

  it "should render" do
    get "/profile/communication"
    expect(f('#breadcrumbs')).to include_text('Account Notification Settings')
    expect(f("h1").text).to eq "Account Notification Settings"
    expect(fj("div:contains('Account-level notifications apply to all courses.')")).to be
  end

  it "should display the users email address as channel" do
    get "/profile/communication"
    expect(fj("th[scope='col'] span:contains('email')")).to be
    expect(fj("th[scope='col'] span:contains('<EMAIL>')")).to be
  end

  it "should display an SMS number as channel" do
    communication_channel(@user, {username: '<EMAIL>', path_type: 'sms', active_cc: true})
    get "/profile/communication"
    expect(fj("span:contains('sms')")).to be
    expect(fxpath("//span[contains(text(),'8011235555@vtext')]")).to be
  end<commit_msg>spec: finish new /profile/communication tests<commit_after>#
# Copyright (C) 2012 - 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 File.expand_path(File.dirname(__FILE__) + '/common')

describe "profile communication settings new ui" do
  include_context "in-process server selenium tests"

  before :once do
    Account.site_admin.enable_feature!(:notification_update_account_ui)
    Notification.create(:name => "Conversation Message", :category => "DiscussionEntry")
    Notification.create(:name => "Added To Conversation", :category => "Discussion")
    Notification.create(:name => "GradingStuff1", :category => "Grading")
    @sub_comment = Notification.create(:name => "Submission Comment1", :category => "Submission Comment")
  end
  
  context "as teacher" do
    before :each do
      course_with_teacher_logged_in
    end
    
    it "should render" do
      get "/profile/communication"
      expect(f('#breadcrumbs')).to include_text('Account Notification Settings')
      expect(f("h1").text).to eq "Account Notification Settings"
      expect(fj("div:contains('Account-level notifications apply to all courses.')")).to be
    end

    it "should display the users email address as channel" do
      get "/profile/communication"
      expect(fj("th[scope='col'] span:contains('email')")).to be
      expect(fj("th[scope='col'] span:contains('<EMAIL>')")).to be
    end

    it "should display an SMS number as channel" do
      communication_channel(@user, {username: '<EMAIL>', path_type: 'sms', active_cc: true})
      get "/profile/communication"
      expect(fj("span:contains('sms')")).to be
      expect(fxpath("//span[contains(text(),'8011235555@vtext')]")).to be
    end

    it "should save a user-pref checkbox change" do
      Account.default.settings[:allow_sending_scores_in_emails] = true
      Account.default.save!
      # set the user's initial user preference and verify checked or unchecked
      @user.preferences[:send_scores_in_emails] = false
      @user.save!

      get "/profile/communication"
      f("tr[data-testid='grading'] label").click
      wait_for_ajaximations
      # test data stored
      @user.reload
      expect(@user.preferences[:send_scores_in_emails]).to eq true
    end
  end

  it "should render for a user with no enrollments" do
    user_logged_in(:username => '<EMAIL>')
    get "/profile/communication"
    expect(fj("th[scope='col'] span:contains('email')")).to be
    expect(fj("th[scope='col'] span:contains('<EMAIL>')")).to be
  end
{'fraction_non_alphanumeric': 0.11957751791776688, 'fraction_numerical': 0.0067898906073179935, 'mean_word_length': 4.313627254509018, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 28, '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': '5519526', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1496, 'n_words': 497}