# # Copyright (C) 2016 - 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 . define ['submit_assignment_helper','jquery'], ({submitContentItem, recordEulaAgreement}, $) -> formHtml = """
""" url = 'https://lti-tool-provider-example.herokuapp.com/messages/blti' fileUrl = 'https://lti-tool-provider-example.herokuapp.com/test_file.txt' contentItem = null originalEnv = null QUnit.module "SubmitAssignmentHelper", setup: -> $('#fixtures').append(formHtml) contentItem = 'ext_canvas_visibility': 'users': [ '86157096483e6b3a50bfedc6bac902c0b20a824f' ] 'updateUrl': 'https://lti-tool-provider-example.herokuapp.com/messages/content-item' 'windowTarget': '' 'text': 'Arch Linux' 'title': 'It\'s amazing' 'url': url 'thumbnail': 'height': 128 'width': 128 '@id': 'http://www.runeaudio.com/assets/img/banner-archlinux.png' 'custom': 'What\'s black and white and red all over?': 'A sunburnt panda' 'placementAdvice': 'displayHeight': 600 'displayWidth': 800 'presentationDocumentTarget': 'iframe' 'mediaType': 'application/vnd.ims.lti.v1.ltilink' '@type': 'LtiLinkItem' '@id': 'https://lti-tool-provider-example.herokuapp.com/messages/blti' 'canvasURL': '/courses/2/external_tools/retrieve?display=borderless&url=https%3A%2F%2Flti-tool-provider-example.herokuapp.com%2Fmessages%2Fblti' originalEnv = ENV ENV.SUBMIT_ASSIGNMENT = ALLOWED_EXTENSIONS: [ 'txt' ] teardown: -> $("#fixtures").html("") ENV = originalEnv test "correctly populates form values for LtiLinkItem", -> submitContentItem(contentItem) equal $("#external_tool_url").val(), url equal $("#external_tool_submission_type").val(), 'basic_lti_launch' test "correctly populates form values for FileItem", -> fileItem = contentItem fileItem['@type'] = 'FileItem' fileItem['@id'] = fileUrl fileItem.url = fileUrl submitContentItem(fileItem) equal $("#external_tool_url").val(), fileUrl equal $("#external_tool_submission_type").val(), "online_url_to_file" test "rejects unsupported file types", -> unsupportedItem = contentItem unsupportedItem['@type'] = 'FileItem' unsupportedItem.url = 'https://lti-tool-provider-example.herokuapp.com/test_file.jpg' result = submitContentItem(unsupportedItem) equal result, false test "accepts supported file types", -> supportedItem = contentItem supportedItem['@type'] = 'FileItem' supportedItem.url = fileUrl result = submitContentItem(supportedItem) equal result, true test "correctly populates form values for FileItem", -> unsupportedItem = contentItem unsupportedItem['@type'] = 'UnsupportedType' result = submitContentItem(unsupportedItem) equal result, false test "returns false if not given an item", -> result = submitContentItem(undefined) equal result, false test "Sets the input value to the current time if checked is true for all eula inputs", -> now = new Date(); clock = sinon.useFakeTimers(now.getTime()); inputHtml = """ """ $('#fixtures').append(inputHtml) recordEulaAgreement('.checkbox-test', true) inputs = document.querySelectorAll('.checkbox-test') for val in inputs equal val.value, now.getTime() clock.restore(); test "Clears the value if the input is not checked", -> now = new Date(); clock = sinon.useFakeTimers(now.getTime()); inputHtml = """ """ $('#fixtures').append(inputHtml) recordEulaAgreement('.checkbox-test', false) inputs = document.querySelectorAll('.checkbox-test') for val in inputs equal val.value, '' clock.restore();