Store SRGB view ungraded in GB user preferences
closes EVAL-624 flag=view_ungraded_as_zero Test plan: - Enable the "View Ungraded as Zero View in Gradebook" feature - Open the Network tab in your browser's developer tools - Open Individual Gradebook for a course - Check that enabling/disabling the "Treat Ungraded as 0" checkbox sends a request to the gradebook_settings URL for the course containing the corresponding true/false value - Check that your changes to the setting persist between reloads of the page - In a Rails console, check that the preference value for that user/course is set appropriately: > UserPreferenceValue.find_by( user_id: <user ID>, key: "gradebook_settings", sub_key: Shard.global_id_for(<course ID>) ) should return a hash including the correct value for "view_ungraded_as_zero" - Check that the setting is synced between New Gradebook and Individual Gradebook when you switch between them (note that any already-open windows will need to be reloaded to pick up the changes) - Disable the "View Ungraded as Zero View in Gradebook" feature - Open Individual Gradebook and check that toggling the setting does *not* send a request to the server, but the value persists between reloads of that particular browser - Check that an old IG setting is honored when enabling the feature and immediately opening IG: - Disable the feature flag - Create a new course, or use one for which you've never set the preference - Open Individual Gradebook and enable the setting - Enable the feature flag - Open New Gradebook for the course and verify that the "View Ungraded as 0" menu item is *not* checked (do not enable it yet!) - Open Individual Gradebook and verify that the setting *is* checked - From this point on, any change in either of the gradebooks should update the value for both of them Change-Id: I2f2921f1ded63a2daa7c83b30d8b879b86fd1a28 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/248896 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Product-Review: Jody Sailor Reviewed-by: Spencer Olson <solson@instructure.com> Reviewed-by: Gary Mei <gmei@instructure.com> QA-Review: Kai Bjorkman <kbjorkman@instructure.com>
This commit is contained in:
parent
6eee1dad02
commit
07391ca949
|
@ -1175,17 +1175,43 @@ const ScreenreaderGradebookController = Ember.ObjectController.extend({
|
|||
'submissions.content.length'
|
||||
),
|
||||
|
||||
includeUngradedAssignments: (() =>
|
||||
userSettings.contextGet('include_ungraded_assignments') || false)
|
||||
includeUngradedAssignments: function() {
|
||||
const localValue = userSettings.contextGet('include_ungraded_assignments') || false
|
||||
if (!this.saveViewUngradedAsZeroToServer()) {
|
||||
return localValue
|
||||
}
|
||||
|
||||
// Prefer the setting we got from the server, but fall back to the value in
|
||||
// userSettings if there is no server value
|
||||
const savedValue = get(window, 'ENV.GRADEBOOK_OPTIONS.settings.view_ungraded_as_zero')
|
||||
return savedValue != null ? savedValue === 'true' : localValue
|
||||
}
|
||||
.property()
|
||||
.volatile(),
|
||||
|
||||
showAttendance: (() => userSettings.contextGet('show_attendance')).property().volatile(),
|
||||
|
||||
updateIncludeUngradedAssignmentsSetting: function() {
|
||||
if (this.saveViewUngradedAsZeroToServer()) {
|
||||
ajax.request({
|
||||
dataType: 'json',
|
||||
type: 'put',
|
||||
url: `/api/v1/courses/${ENV.GRADEBOOK_OPTIONS.context_id}/gradebook_settings`,
|
||||
data: {
|
||||
gradebook_settings: {
|
||||
view_ungraded_as_zero: this.get('includeUngradedAssignments') ? 'true' : 'false'
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
userSettings.contextSet('include_ungraded_assignments', this.get('includeUngradedAssignments'))
|
||||
}.observes('includeUngradedAssignments'),
|
||||
|
||||
saveViewUngradedAsZeroToServer() {
|
||||
return !!get(window, 'ENV.GRADEBOOK_OPTIONS.save_view_ungraded_as_zero_to_server')
|
||||
},
|
||||
|
||||
assignmentGroupsHash() {
|
||||
const ags = {}
|
||||
if (!this.get('assignment_groups')) {
|
||||
|
|
|
@ -1107,16 +1107,53 @@ QUnit.module('ScreenReader Gradebook', suiteHooks => {
|
|||
QUnit.module('includeUngradedAssignments', hooks => {
|
||||
hooks.beforeEach(() => {
|
||||
initializeApp()
|
||||
|
||||
window.ENV.GRADEBOOK_OPTIONS = {}
|
||||
window.ENV.GRADEBOOK_OPTIONS.settings = {}
|
||||
})
|
||||
|
||||
test('returns true when include_ungraded_assignments is true', () => {
|
||||
userSettings.contextGet.withArgs('include_ungraded_assignments').returns(true)
|
||||
strictEqual(srgb.get('includeUngradedAssignments'), true)
|
||||
QUnit.module('when storing in Gradebook preferences', gbHooks => {
|
||||
gbHooks.beforeEach(() => {
|
||||
window.ENV.GRADEBOOK_OPTIONS.save_view_ungraded_as_zero_to_server = true
|
||||
})
|
||||
|
||||
test('returns true when the setting is passed as "true"', () => {
|
||||
window.ENV.GRADEBOOK_OPTIONS.settings.view_ungraded_as_zero = 'true'
|
||||
userSettings.contextGet.withArgs('include_ungraded_assignments').returns(false)
|
||||
strictEqual(srgb.get('includeUngradedAssignments'), true)
|
||||
})
|
||||
|
||||
test('returns false when the setting is passed as "false"', () => {
|
||||
window.ENV.GRADEBOOK_OPTIONS.settings.view_ungraded_as_zero = 'false'
|
||||
userSettings.contextGet.withArgs('include_ungraded_assignments').returns(true)
|
||||
strictEqual(srgb.get('includeUngradedAssignments'), false)
|
||||
})
|
||||
|
||||
test('falls back to the value in localStorage when no setting value is present', () => {
|
||||
userSettings.contextGet.withArgs('include_ungraded_assignments').returns(true)
|
||||
strictEqual(srgb.get('includeUngradedAssignments'), true)
|
||||
})
|
||||
|
||||
test('returns false if no value exists in localStorage or in settings', () => {
|
||||
strictEqual(srgb.get('includeUngradedAssignments'), false)
|
||||
})
|
||||
|
||||
test('returns the last-set value after being set', () => {
|
||||
srgb.set('includeUngradedAssignments', true)
|
||||
strictEqual(srgb.get('includeUngradedAssignments'), true)
|
||||
})
|
||||
})
|
||||
|
||||
test('returns false when include_ungraded_assignments is false', () => {
|
||||
userSettings.contextGet.withArgs('include_ungraded_assignments').returns(false)
|
||||
strictEqual(srgb.get('includeUngradedAssignments'), false)
|
||||
QUnit.module('when storing settings locally', () => {
|
||||
test('returns true when include_ungraded_assignments is true', () => {
|
||||
userSettings.contextGet.withArgs('include_ungraded_assignments').returns(true)
|
||||
strictEqual(srgb.get('includeUngradedAssignments'), true)
|
||||
})
|
||||
|
||||
test('returns false when include_ungraded_assignments is false', () => {
|
||||
userSettings.contextGet.withArgs('include_ungraded_assignments').returns(false)
|
||||
strictEqual(srgb.get('includeUngradedAssignments'), false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -1125,6 +1162,43 @@ QUnit.module('ScreenReader Gradebook', suiteHooks => {
|
|||
initializeApp()
|
||||
})
|
||||
|
||||
QUnit.module('when storing settings in Gradebook preferences', gbHooks => {
|
||||
gbHooks.beforeEach(() => {
|
||||
window.ENV.GRADEBOOK_OPTIONS.save_view_ungraded_as_zero_to_server = true
|
||||
|
||||
const url = `/api/v1/courses/${ENV.GRADEBOOK_OPTIONS.context_id}/gradebook_settings`
|
||||
ajax.defineFixture(url, {
|
||||
response: [],
|
||||
textStatus: 'success'
|
||||
})
|
||||
})
|
||||
|
||||
test('updateIncludeUngradedAssignmentsSetting uses the Gradebook settings endpoint', () => {
|
||||
const ajaxRequestSpy = sandbox.stub(ajax, 'request')
|
||||
const url = `/api/v1/courses/${ENV.GRADEBOOK_OPTIONS.context_id}/gradebook_settings`
|
||||
srgb.set('includeUngradedAssignments', false)
|
||||
strictEqual(ajaxRequestSpy.firstCall.args[0].url, url)
|
||||
})
|
||||
|
||||
test('updateIncludeUngradedAssignmentsSetting passes the updated setting state', () => {
|
||||
const ajaxRequestSpy = sandbox.stub(ajax, 'request')
|
||||
srgb.set('includeUngradedAssignments', false)
|
||||
deepEqual(ajaxRequestSpy.firstCall.args[0].data, {
|
||||
gradebook_settings: {
|
||||
view_ungraded_as_zero: 'false'
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
QUnit.module('when storing settings locally', () => {
|
||||
test('updateIncludeUngradedAssignmentsSetting does not call the Gradebook settings endpoint', () => {
|
||||
const ajaxRequestSpy = sandbox.stub(ajax, 'request')
|
||||
srgb.set('includeUngradedAssignments', false)
|
||||
equal(ajaxRequestSpy.callCount, 0)
|
||||
})
|
||||
})
|
||||
|
||||
test('changing includeUngradedAssignments calls updateIncludeUngradedAssignmentsSetting', () => {
|
||||
const updateIncludeUngradedAssignmentsSettingStub = sinon.stub(
|
||||
srgb,
|
||||
|
|
|
@ -388,6 +388,7 @@ class GradebooksController < ApplicationController
|
|||
|
||||
gradebook_options = {
|
||||
active_grading_periods: active_grading_periods_json,
|
||||
allow_view_ungraded_as_zero: allow_view_ungraded_as_zero?,
|
||||
# TODO: remove `api_max_per_page` with TALLY-831
|
||||
api_max_per_page: per_page,
|
||||
|
||||
|
@ -482,8 +483,7 @@ class GradebooksController < ApplicationController
|
|||
submissions_url: api_v1_course_student_submissions_url(@context, grouped: '1'),
|
||||
teacher_notes: teacher_notes && custom_gradebook_column_json(teacher_notes, @current_user, session),
|
||||
user_asset_string: @current_user&.asset_string,
|
||||
version: params.fetch(:version, nil),
|
||||
allow_view_ungraded_as_zero: Account.site_admin.feature_enabled?(:view_ungraded_as_zero)
|
||||
version: params.fetch(:version, nil)
|
||||
}
|
||||
|
||||
js_env({
|
||||
|
@ -584,6 +584,7 @@ class GradebooksController < ApplicationController
|
|||
publish_to_sis_url: context_url(@context, :context_details_url, anchor: 'tab-grade-publishing'),
|
||||
re_upload_submissions_url: named_context_url(@context, :submissions_upload_context_gradebook_url, "{{ assignment_id }}"),
|
||||
reorder_custom_columns_url: api_v1_custom_gradebook_columns_reorder_url(@context),
|
||||
save_view_ungraded_as_zero_to_server: allow_view_ungraded_as_zero?,
|
||||
sections: sections_json(visible_sections, @current_user, session, [], allow_sis_ids: true),
|
||||
sections_url: api_v1_course_sections_url(@context),
|
||||
setting_update_url: api_v1_course_settings_url(@context),
|
||||
|
@ -1363,4 +1364,8 @@ class GradebooksController < ApplicationController
|
|||
course_settings = @current_user.get_preference(:gradebook_column_size, @context.global_id) || {}
|
||||
shared_settings.merge(course_settings)
|
||||
end
|
||||
|
||||
def allow_view_ungraded_as_zero?
|
||||
Account.site_admin.feature_enabled?(:view_ungraded_as_zero)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -844,15 +844,32 @@ describe GradebooksController do
|
|||
end
|
||||
|
||||
describe "view ungraded as zero" do
|
||||
it "sets allow_view_ungraded_as_zero in the ENV to true if the feature is enabled" do
|
||||
Account.site_admin.enable_feature!(:view_ungraded_as_zero)
|
||||
get :show, params: { course_id: @course.id }
|
||||
expect(gradebook_options.fetch(:allow_view_ungraded_as_zero)).to be true
|
||||
context "when individual gradebook is enabled" do
|
||||
before(:each) { @teacher.preferences[:gradebook_version] = "srgb" }
|
||||
|
||||
it "save_view_ungraded_as_zero_to_server is true when the feature is enabled" do
|
||||
Account.site_admin.enable_feature!(:view_ungraded_as_zero)
|
||||
get :show, params: { course_id: @course.id }
|
||||
expect(gradebook_options[:save_view_ungraded_as_zero_to_server]).to be true
|
||||
end
|
||||
|
||||
it "save_view_ungraded_as_zero_to_server is false when the feature is not enabled" do
|
||||
get :show, params: { course_id: @course.id }
|
||||
expect(gradebook_options[:save_view_ungraded_as_zero_to_server]).to be false
|
||||
end
|
||||
end
|
||||
|
||||
it "sets allow_view_ungraded_as_zero in the ENV to false if the feature is not enabled" do
|
||||
get :show, params: { course_id: @course.id }
|
||||
expect(gradebook_options.fetch(:allow_view_ungraded_as_zero)).to be false
|
||||
context "when default gradebook is enabled" do
|
||||
it "sets allow_view_ungraded_as_zero in the ENV to true if the feature is enabled" do
|
||||
Account.site_admin.enable_feature!(:view_ungraded_as_zero)
|
||||
get :show, params: { course_id: @course.id }
|
||||
expect(gradebook_options.fetch(:allow_view_ungraded_as_zero)).to be true
|
||||
end
|
||||
|
||||
it "sets allow_view_ungraded_as_zero in the ENV to false if the feature is not enabled" do
|
||||
get :show, params: { course_id: @course.id }
|
||||
expect(gradebook_options.fetch(:allow_view_ungraded_as_zero)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue