Skip to content

Commit

Permalink
Add functionality to sort announcements
Browse files Browse the repository at this point in the history
Test plan:
-announcements with a greater date should be at the top

fixes KNO-470

flag=past_announcements

Change-Id: I27c9809ab800a02fe2dbe9a7c6807f09f9ba3bc7
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/238101
Tested-by: Service Cloud Jenkins <[email protected]>
Reviewed-by: Rob Orton <[email protected]>
QA-Review: Rob Orton <[email protected]>
Product-Review: Rob Orton <[email protected]>
  • Loading branch information
drakeaharper committed May 22, 2020
1 parent 0743411 commit c0e4c24
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/account_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def self.for_user_and_account(user, root_account, include_past: false)
end
end

current
current.sort_by {|item| item[:end_at]}.reverse
end
end

Expand Down
22 changes: 22 additions & 0 deletions spec/models/account_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,28 @@
expect(AccountNotification.for_user_and_account(@unenrolled, Account.site_admin).map(&:id).sort).to eq [@a5.id, @a6.id]
end

it 'should sort' do
@announcement.destroy
role_ids = ["TeacherEnrollment", "AccountAdmin"].map{|name| Role.get_built_in_role(name).id}
account_notification(:role_ids => role_ids, :message => "Announcement 1")
@a1 = @announcement
account_notification(:account => @account, :role_ids => [nil], :message => "Announcement 2") #students not currently taking a course
@a2 = @announcement
account_notification(:account => @account, :message => "Announcement 3") # no roles, should go to all
@announcement[:end_at] = @announcement[:end_at] + 1.month
@a3 = @announcement

@unenrolled = @user
course_with_teacher(:account => @account)
@teacher = @user
account_admin_user(:account => @account)
@admin = @user
course_with_student(:course => @course).accept(true)
@student = @user

expect(AccountNotification.for_user_and_account(@teacher, @account)).to eq [@a3, @a1]
end

it "should allow closing an announcement" do
@user.close_announcement(@announcement)
expect(@user.get_preference(:closed_notifications)).to eq [@announcement.id]
Expand Down
4 changes: 2 additions & 2 deletions spec/selenium/dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ def disable_recent_activity_header_course_link
fj('span[role="menuitemradio"]:contains("Recent Activity")').click
messages = ff("#dashboard .account_notification .notification_message")
expect(messages.size).to eq 2
expect(messages[0].text).to eq a1.message
expect(messages[1].text).to eq a2.message
expect(messages[0].text).to eq a2.message
expect(messages[1].text).to eq a1.message
end

it "should interpolate the user's domain in global notifications" do
Expand Down

0 comments on commit c0e4c24

Please sign in to comment.