@instructure/canvas-rce 5.14.1 → 5.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (481) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/DEVELOPMENT.md +1 -1
  3. package/README.md +0 -8
  4. package/__tests__/common/indicate.test.js +84 -0
  5. package/__tests__/common/mimeClass.test.js +85 -0
  6. package/__tests__/module/contentInsertionUtils.test.js +52 -0
  7. package/__tests__/module/indicatorRegion.test.js +75 -0
  8. package/__tests__/module/normalizeLocale.test.js +46 -0
  9. package/__tests__/module/normalizeProps.test.js +51 -0
  10. package/__tests__/module/sanitizePlugins.test.js +48 -0
  11. package/__tests__/module/wrapInitCb.test.js +56 -0
  12. package/__tests__/rcs/api.test.js +819 -0
  13. package/{mocha-reporter-config.js → __tests__/sidebar/actions/all_files.test.js} +10 -9
  14. package/__tests__/sidebar/actions/data.test.js +196 -0
  15. package/__tests__/sidebar/actions/utils.js +44 -0
  16. package/{es/rce/plugins/shared/__mocks__/screenfull.js → __tests__/sidebar/reducers/all_files.test.js} +10 -6
  17. package/babel.config.js +3 -1
  18. package/es/bridge/Bridge.js +8 -56
  19. package/es/bridge/index.js +1 -0
  20. package/es/canvasFileBrowser/FileBrowser.js +12 -59
  21. package/es/canvasFileBrowser/en-US.js +3 -6
  22. package/es/common/FlashAlert.js +7 -28
  23. package/es/common/browser.js +4 -2
  24. package/es/common/fileUrl.js +104 -59
  25. package/es/common/incremental-loading/LoadMoreButton.js +1 -0
  26. package/es/common/incremental-loading/LoadingIndicator.js +1 -2
  27. package/es/common/incremental-loading/LoadingStatus.js +1 -2
  28. package/es/common/incremental-loading/index.js +1 -0
  29. package/es/common/incremental-loading/useIncrementalLoading.js +1 -3
  30. package/es/common/indicate.js +15 -8
  31. package/es/common/mimeClass.js +3 -4
  32. package/es/common/natcompare.js +1 -4
  33. package/es/defaultTinymceConfig.js +5 -3
  34. package/es/elementDenylist.js +1 -0
  35. package/es/enhance-user-content/doc_previews.js +17 -28
  36. package/es/enhance-user-content/enhance_user_content.js +28 -60
  37. package/es/enhance-user-content/external_links.js +5 -8
  38. package/es/enhance-user-content/index.js +1 -0
  39. package/es/enhance-user-content/instructure_helper.js +12 -34
  40. package/es/enhance-user-content/jqueryish_funcs.js +8 -11
  41. package/es/enhance-user-content/mathml.js +35 -82
  42. package/es/enhance-user-content/media_comment_thumbnail.js +5 -17
  43. package/es/format-message.js +3 -4
  44. package/es/getThemeVars.js +8 -6
  45. package/es/getTranslations.js +1 -78
  46. package/es/index.js +3 -1
  47. package/es/rce/AlertMessageArea.js +1 -1
  48. package/es/rce/DraggingBlocker.js +4 -2
  49. package/es/rce/KeyboardShortcutModal.js +1 -0
  50. package/es/rce/RCE.js +12 -11
  51. package/es/rce/RCEGlobals.js +12 -10
  52. package/es/rce/RCEVariants.js +27 -10
  53. package/es/rce/RCEWrapper.js +167 -386
  54. package/es/rce/RCEWrapperProps.js +8 -3
  55. package/es/rce/RceHtmlEditor.js +5 -8
  56. package/es/rce/ResizeHandle.js +3 -8
  57. package/es/rce/RestoreAutoSaveModal.js +1 -2
  58. package/es/rce/ShowOnFocusButton/index.js +0 -6
  59. package/es/rce/StatusBar.js +8 -37
  60. package/es/rce/alertHandler.js +1 -4
  61. package/es/rce/contentInsertion.js +35 -57
  62. package/es/rce/contentInsertionUtils.js +6 -8
  63. package/es/rce/contentRendering.js +7 -12
  64. package/es/rce/customEvents.js +1 -0
  65. package/es/rce/editorLanguage.js +22 -10
  66. package/es/rce/indicatorRegion.js +6 -5
  67. package/es/rce/normalizeLocale.js +5 -3
  68. package/es/rce/normalizeProps.js +3 -1
  69. package/es/rce/plugins/instructure-ui-icons/plugin.js +21 -3
  70. package/es/rce/plugins/instructure_color/clickCallback.js +84 -0
  71. package/es/rce/plugins/instructure_color/components/ColorPicker.js +299 -0
  72. package/es/rce/plugins/instructure_color/components/ColorPopup.js +68 -0
  73. package/es/rce/plugins/instructure_color/components/colorUtils.js +60 -0
  74. package/es/rce/plugins/instructure_color/plugin.js +40 -0
  75. package/es/rce/plugins/instructure_condensed_buttons/core/ListUtils.js +10 -3
  76. package/es/rce/plugins/instructure_condensed_buttons/plugin.js +1 -0
  77. package/es/rce/plugins/instructure_condensed_buttons/ui/alignment-button.js +1 -2
  78. package/es/rce/plugins/instructure_condensed_buttons/ui/directionality-button.js +3 -2
  79. package/es/rce/plugins/instructure_condensed_buttons/ui/indent-outdent-button.js +1 -0
  80. package/es/rce/plugins/instructure_condensed_buttons/ui/list-button.js +22 -15
  81. package/es/rce/plugins/instructure_condensed_buttons/ui/subscript-superscript-button.js +1 -2
  82. package/es/rce/plugins/instructure_documents/clickCallback.js +1 -0
  83. package/es/rce/plugins/instructure_documents/components/DocumentsPanel.js +1 -9
  84. package/es/rce/plugins/instructure_documents/components/Link.js +3 -18
  85. package/es/rce/plugins/instructure_documents/plugin.js +7 -14
  86. package/es/rce/plugins/instructure_equation/EquationEditorModal/advancedOnlySyntax.js +4 -2
  87. package/es/rce/plugins/instructure_equation/EquationEditorModal/advancedPreference.js +1 -2
  88. package/es/rce/plugins/instructure_equation/EquationEditorModal/index.js +12 -29
  89. package/es/rce/plugins/instructure_equation/EquationEditorModal/latexTextareaUtil.js +11 -12
  90. package/es/rce/plugins/instructure_equation/EquationEditorModal/parseLatex.js +4 -3
  91. package/es/rce/plugins/instructure_equation/EquationEditorModal/styles.js +4 -2
  92. package/es/rce/plugins/instructure_equation/EquationEditorToolbar/buttons.js +13 -7
  93. package/es/rce/plugins/instructure_equation/EquationEditorToolbar/index.js +4 -7
  94. package/es/rce/plugins/instructure_equation/MathIcon/index.js +1 -1
  95. package/es/rce/plugins/instructure_equation/MathIcon/svgs.js +1 -1
  96. package/es/rce/plugins/instructure_equation/clickCallback.js +2 -5
  97. package/es/rce/plugins/instructure_equation/mathlive/index.js +1 -1
  98. package/es/rce/plugins/instructure_equation/plugin.js +7 -10
  99. package/es/rce/plugins/instructure_fullscreen/plugin.js +3 -6
  100. package/es/rce/plugins/instructure_html_view/clickCallback.js +1 -0
  101. package/es/rce/plugins/instructure_html_view/plugin.js +5 -4
  102. package/es/rce/plugins/instructure_icon_maker/clickCallback.js +2 -4
  103. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ColorSection.js +1 -2
  104. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/CreateIconMakerForm.js +1 -0
  105. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/Footer.js +1 -0
  106. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/Group.js +1 -0
  107. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/Header.js +1 -2
  108. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ImageSection/Course.js +25 -22
  109. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ImageSection/ImageOptions.js +7 -11
  110. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ImageSection/ImageSection.js +27 -23
  111. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ImageSection/ModeSelect.js +5 -4
  112. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ImageSection/MultiColor/index.js +11 -9
  113. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ImageSection/MultiColor/svg.js +1 -0
  114. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ImageSection/SVGList.js +5 -4
  115. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ImageSection/SVGThumbnail.js +1 -3
  116. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ImageSection/SingleColor/index.js +7 -7
  117. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ImageSection/SingleColor/svg.js +1 -0
  118. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ImageSection/Upload.js +27 -20
  119. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ImageSection/index.js +1 -0
  120. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ImageSection/propTypes.js +1 -0
  121. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ImageSection/utils.js +1 -0
  122. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/Preview.js +4 -4
  123. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/ShapeSection.js +1 -2
  124. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/TextSection.js +1 -5
  125. package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/index.js +1 -0
  126. package/es/rce/plugins/instructure_icon_maker/components/IconMakerTray.js +18 -33
  127. package/es/rce/plugins/instructure_icon_maker/components/SavedIconMakerList.js +4 -4
  128. package/es/rce/plugins/instructure_icon_maker/plugin.js +10 -14
  129. package/es/rce/plugins/instructure_icon_maker/reducers/imageSection.js +37 -38
  130. package/es/rce/plugins/instructure_icon_maker/reducers/svgSettings.js +24 -24
  131. package/es/rce/plugins/instructure_icon_maker/registerEditToolbar.js +1 -3
  132. package/es/rce/plugins/instructure_icon_maker/svg/constants.js +4 -3
  133. package/es/rce/plugins/instructure_icon_maker/svg/font.js +3 -1
  134. package/es/rce/plugins/instructure_icon_maker/svg/image.js +69 -83
  135. package/es/rce/plugins/instructure_icon_maker/svg/index.js +11 -15
  136. package/es/rce/plugins/instructure_icon_maker/svg/metadata.js +1 -0
  137. package/es/rce/plugins/instructure_icon_maker/svg/settings.js +32 -39
  138. package/es/rce/plugins/instructure_icon_maker/svg/shape.js +1 -49
  139. package/es/rce/plugins/instructure_icon_maker/svg/text.js +7 -92
  140. package/es/rce/plugins/instructure_icon_maker/svg/utils.js +1 -7
  141. package/es/rce/plugins/instructure_icon_maker/utils/IconMakerClose.js +2 -6
  142. package/es/rce/plugins/instructure_icon_maker/utils/IconMakerFormHasChanges.js +1 -15
  143. package/es/rce/plugins/instructure_icon_maker/utils/addIconMakerAttributes.js +3 -4
  144. package/es/rce/plugins/instructure_icon_maker/utils/iconValidation.js +1 -1
  145. package/es/rce/plugins/instructure_icon_maker/utils/iconsLabels.js +1 -0
  146. package/es/rce/plugins/instructure_icon_maker/utils/useDebouncedValue.js +12 -13
  147. package/es/rce/plugins/instructure_image/ImageEmbedOptions.js +6 -24
  148. package/es/rce/plugins/instructure_image/ImageList/Image.js +1 -6
  149. package/es/rce/plugins/instructure_image/ImageList/index.js +1 -2
  150. package/es/rce/plugins/instructure_image/ImageOptionsTray/TrayController.js +7 -27
  151. package/es/rce/plugins/instructure_image/ImageOptionsTray/index.js +3 -16
  152. package/es/rce/plugins/instructure_image/Images/index.js +1 -3
  153. package/es/rce/plugins/instructure_image/clickCallback.js +1 -0
  154. package/es/rce/plugins/instructure_image/plugin.js +13 -18
  155. package/es/rce/plugins/instructure_links/clickCallback.js +1 -0
  156. package/es/rce/plugins/instructure_links/components/AccordionSection.js +1 -0
  157. package/es/rce/plugins/instructure_links/components/CollectionPanel.js +1 -3
  158. package/es/rce/plugins/instructure_links/components/Link.js +7 -19
  159. package/es/rce/plugins/instructure_links/components/LinkOptionsDialog/LinkOptionsDialogController.js +1 -21
  160. package/es/rce/plugins/instructure_links/components/LinkOptionsDialog/index.js +1 -4
  161. package/es/rce/plugins/instructure_links/components/LinkOptionsTray/LinkOptionsTrayController.js +3 -20
  162. package/es/rce/plugins/instructure_links/components/LinkOptionsTray/index.js +1 -12
  163. package/es/rce/plugins/instructure_links/components/LinkSet.js +4 -20
  164. package/es/rce/plugins/instructure_links/components/LinksPanel.js +1 -2
  165. package/es/rce/plugins/instructure_links/components/NavigationPanel.js +7 -9
  166. package/es/rce/plugins/instructure_links/components/NoResults.js +1 -7
  167. package/es/rce/plugins/instructure_links/plugin.js +17 -40
  168. package/es/rce/plugins/instructure_links/validateURL.js +81 -36
  169. package/es/rce/plugins/instructure_media_embed/clickCallback.js +2 -5
  170. package/es/rce/plugins/instructure_media_embed/components/Embed.js +1 -0
  171. package/es/rce/plugins/instructure_media_embed/plugin.js +7 -3
  172. package/es/rce/plugins/instructure_paste/pasteMenuCommand.js +1 -5
  173. package/es/rce/plugins/instructure_paste/plugin.js +27 -29
  174. package/es/rce/plugins/instructure_rce_external_tools/ExternalToolsEnv.js +14 -53
  175. package/es/rce/plugins/instructure_rce_external_tools/RceToolWrapper.js +21 -49
  176. package/es/rce/plugins/instructure_rce_external_tools/components/ExternalToolDialog/ExternalToolDialog.js +11 -42
  177. package/es/rce/plugins/instructure_rce_external_tools/components/ExternalToolDialog/ExternalToolDialogModal.js +1 -2
  178. package/es/rce/plugins/instructure_rce_external_tools/components/ExternalToolDialog/ExternalToolDialogTray.js +1 -1
  179. package/es/rce/plugins/instructure_rce_external_tools/components/ExternalToolSelectionDialog/ExternalToolSelectionDialog.js +2 -10
  180. package/es/rce/plugins/instructure_rce_external_tools/components/ExternalToolSelectionDialog/ExternalToolSelectionItem.js +1 -2
  181. package/es/rce/plugins/instructure_rce_external_tools/components/util/ExpandoText.js +1 -0
  182. package/es/rce/plugins/instructure_rce_external_tools/components/util/ToolLaunchIframe.js +2 -1
  183. package/es/rce/{__mocks__/_mockStudioPlayer.js → plugins/instructure_rce_external_tools/constants.js} +11 -3
  184. package/es/rce/plugins/instructure_rce_external_tools/dialog-helper.js +19 -4
  185. package/es/rce/plugins/instructure_rce_external_tools/helpers/tags.js +0 -2
  186. package/es/rce/plugins/instructure_rce_external_tools/jquery/jquery.dropdownList.js +130 -136
  187. package/es/rce/plugins/instructure_rce_external_tools/lti11-content-items/RceLti11ContentItem.js +100 -95
  188. package/es/rce/plugins/instructure_rce_external_tools/lti13-content-items/Lti13ContentItemJson.js +1 -0
  189. package/es/rce/plugins/instructure_rce_external_tools/lti13-content-items/RceLti13ContentItem.js +2 -19
  190. package/es/rce/plugins/instructure_rce_external_tools/lti13-content-items/models/BaseLinkContentItem.js +1 -14
  191. package/es/rce/plugins/instructure_rce_external_tools/lti13-content-items/models/HtmlFragmentContentItem.js +1 -6
  192. package/es/rce/plugins/instructure_rce_external_tools/lti13-content-items/models/ImageContentItem.js +1 -9
  193. package/es/rce/plugins/instructure_rce_external_tools/lti13-content-items/models/LinkContentItem.js +1 -1
  194. package/es/rce/plugins/instructure_rce_external_tools/lti13-content-items/models/ResourceLinkContentItem.js +3 -5
  195. package/es/rce/plugins/instructure_rce_external_tools/lti13-content-items/processEditorContentItems.js +18 -10
  196. package/es/rce/plugins/instructure_rce_external_tools/lti13-content-items/rceLti13ContentItemFromJson.js +4 -4
  197. package/es/rce/plugins/instructure_rce_external_tools/plugin.js +7 -16
  198. package/es/rce/plugins/instructure_rce_external_tools/util/addParentFrameContextToUrl.js +1 -1
  199. package/es/rce/plugins/instructure_record/AudioOptionsTray/TrayController.js +1 -25
  200. package/es/rce/plugins/instructure_record/AudioOptionsTray/index.js +1 -4
  201. package/es/rce/plugins/instructure_record/MediaPanel/index.js +1 -9
  202. package/es/rce/plugins/instructure_record/VideoOptionsTray/TrayController.js +8 -51
  203. package/es/rce/plugins/instructure_record/VideoOptionsTray/index.js +4 -17
  204. package/es/rce/plugins/instructure_record/clickCallback.js +7 -15
  205. package/es/rce/plugins/instructure_record/mediaTranslations.js +1 -0
  206. package/es/rce/plugins/instructure_record/plugin.js +11 -18
  207. package/es/rce/plugins/instructure_search_and_replace/clickCallback.js +2 -5
  208. package/es/rce/plugins/instructure_search_and_replace/components/FindReplaceTray.js +20 -35
  209. package/es/rce/plugins/instructure_search_and_replace/components/FindReplaceTrayController.js +3 -18
  210. package/es/rce/plugins/instructure_search_and_replace/getSelectionContext.js +2 -9
  211. package/es/rce/plugins/instructure_search_and_replace/plugin.js +1 -3
  212. package/es/rce/plugins/instructure_studio_media_options/plugin.js +1 -1
  213. package/es/rce/plugins/instructure_wordcount/clickCallback.js +2 -5
  214. package/es/rce/plugins/instructure_wordcount/components/WordCountModal.js +1 -4
  215. package/es/rce/plugins/instructure_wordcount/plugin.js +1 -0
  216. package/es/rce/plugins/instructure_wordcount/utils/countContent.js +1 -8
  217. package/es/rce/plugins/instructure_wordcount/utils/tableContent.js +1 -0
  218. package/es/rce/plugins/shared/CanvasContentTray.js +22 -49
  219. package/es/rce/plugins/shared/CheckerboardStyling.js +1 -1
  220. package/es/rce/plugins/shared/ColorInput.js +5 -14
  221. package/es/rce/plugins/shared/ConditionalTooltip.js +1 -0
  222. package/es/rce/plugins/shared/ContentSelection.js +17 -58
  223. package/es/rce/plugins/shared/DimensionUtils.js +1 -8
  224. package/es/rce/plugins/shared/DimensionsInput/DimensionInput.js +6 -6
  225. package/es/rce/plugins/shared/DimensionsInput/index.js +37 -15
  226. package/es/rce/plugins/shared/DimensionsInput/useDimensionsState.js +5 -29
  227. package/es/rce/plugins/shared/ErrorBoundary.js +2 -5
  228. package/es/rce/plugins/shared/EventUtils.js +1 -3
  229. package/es/rce/plugins/shared/Filter.js +8 -38
  230. package/es/rce/plugins/shared/FixedContentTray.js +3 -3
  231. package/es/rce/plugins/shared/ImageCropper/DirectionRegion.js +1 -8
  232. package/es/rce/plugins/shared/ImageCropper/Modal.js +4 -7
  233. package/es/rce/plugins/shared/ImageCropper/Preview.js +7 -11
  234. package/es/rce/plugins/shared/ImageCropper/constants.js +1 -0
  235. package/es/rce/plugins/shared/ImageCropper/controls/CustomNumberInput.js +2 -5
  236. package/es/rce/plugins/shared/ImageCropper/controls/ResetControls.js +1 -0
  237. package/es/rce/plugins/shared/ImageCropper/controls/RotationControls.js +1 -10
  238. package/es/rce/plugins/shared/ImageCropper/controls/ShapeControls.js +1 -0
  239. package/es/rce/plugins/shared/ImageCropper/controls/ZoomControls.js +1 -11
  240. package/es/rce/plugins/shared/ImageCropper/controls/index.js +1 -0
  241. package/es/rce/plugins/shared/ImageCropper/controls/useDebouncedNumericValue.js +3 -16
  242. package/es/rce/plugins/shared/ImageCropper/controls/utils.js +1 -2
  243. package/es/rce/plugins/shared/ImageCropper/imageCropUtils.js +1 -10
  244. package/es/rce/plugins/shared/ImageCropper/index.js +1 -0
  245. package/es/rce/plugins/shared/ImageCropper/propTypes.js +1 -0
  246. package/es/rce/plugins/shared/ImageCropper/reducers/imageCropper.js +15 -14
  247. package/es/rce/plugins/shared/ImageCropper/shape.js +1 -0
  248. package/es/rce/plugins/shared/ImageCropper/svg/index.js +1 -2
  249. package/es/rce/plugins/shared/ImageCropper/svg/shape.js +1 -17
  250. package/es/rce/plugins/shared/ImageCropper/svg/utils.js +1 -0
  251. package/es/rce/plugins/shared/ImageCropper/useKeyMouseEvents.js +19 -46
  252. package/es/rce/plugins/shared/ImageCropper/useMouseWheel.js +8 -10
  253. package/es/rce/plugins/shared/ImageOptionsForm.js +1 -2
  254. package/es/rce/plugins/shared/LinkDisplay.js +1 -2
  255. package/es/rce/plugins/shared/PreviewIcon.js +1 -6
  256. package/es/rce/plugins/shared/Previewable.js +1 -0
  257. package/es/rce/plugins/shared/RceFileBrowser.js +5 -7
  258. package/es/rce/plugins/shared/StoreContext.js +1 -2
  259. package/es/rce/plugins/shared/StudioLtiSupportUtils.js +10 -6
  260. package/es/rce/plugins/shared/UnknownFileTypePanel.js +1 -0
  261. package/es/rce/plugins/shared/Upload/CanvasContentPanel.js +13 -18
  262. package/es/rce/plugins/shared/Upload/CategoryProcessor.js +1 -1
  263. package/es/rce/plugins/shared/Upload/ComputerPanel.js +8 -26
  264. package/es/rce/plugins/shared/Upload/PanelFilter.js +3 -12
  265. package/es/rce/plugins/shared/Upload/SvgCategoryProcessor.js +4 -3
  266. package/es/rce/plugins/shared/Upload/UploadFile.js +15 -18
  267. package/es/rce/plugins/shared/Upload/UploadFileModal.js +9 -25
  268. package/es/rce/plugins/shared/Upload/UrlPanel.js +1 -0
  269. package/es/rce/plugins/shared/Upload/UsageRightsSelectBox.js +7 -12
  270. package/es/rce/plugins/shared/Upload/doFileUpload.js +4 -6
  271. package/es/rce/plugins/shared/Upload/index.js +1 -0
  272. package/es/rce/plugins/shared/ai_tools/AIResponseModal.js +1 -3
  273. package/es/rce/plugins/shared/ai_tools/AIToolsTray.js +6 -24
  274. package/es/rce/plugins/shared/ai_tools/aiicons.js +1 -0
  275. package/es/rce/plugins/shared/ai_tools/index.js +1 -0
  276. package/es/rce/plugins/shared/buildDownloadUrl.js +0 -2
  277. package/es/rce/plugins/shared/canvasContentUtils.js +6 -9
  278. package/es/rce/plugins/shared/compressionUtils.js +1 -8
  279. package/es/rce/plugins/shared/dateUtils.js +1 -1
  280. package/es/rce/plugins/shared/do-fetch-api-effect/defaultFetchOptions.js +4 -2
  281. package/es/rce/plugins/shared/do-fetch-api-effect/doFetchApi.js +7 -10
  282. package/es/rce/plugins/shared/do-fetch-api-effect/index.js +1 -0
  283. package/es/rce/plugins/shared/do-fetch-api-effect/parse-link-header.js +6 -20
  284. package/es/rce/plugins/shared/do-fetch-api-effect/query-string-encoding.js +5 -3
  285. package/es/rce/plugins/shared/fileShape.js +4 -9
  286. package/es/rce/plugins/shared/fileTypeUtils.js +32 -42
  287. package/es/rce/plugins/shared/fileUtils.js +1 -2
  288. package/es/rce/plugins/shared/linkUtils.js +1 -16
  289. package/es/rce/plugins/shared/round.js +1 -0
  290. package/es/rce/plugins/shared/trayUtils.js +4 -3
  291. package/es/rce/plugins/shared/useDataUrl.js +9 -9
  292. package/es/rce/plugins/shared/useFilterSettings.js +3 -3
  293. package/es/rce/plugins/tinymce-a11y-checker/components/ColorField.js +2 -6
  294. package/es/rce/plugins/tinymce-a11y-checker/components/checker.js +5 -63
  295. package/es/rce/plugins/tinymce-a11y-checker/components/color-picker.js +1 -2
  296. package/es/rce/plugins/tinymce-a11y-checker/components/placeholder-svg.js +1 -0
  297. package/es/rce/plugins/tinymce-a11y-checker/components/pointer.js +1 -0
  298. package/es/rce/plugins/tinymce-a11y-checker/node-checker.js +1 -6
  299. package/es/rce/plugins/tinymce-a11y-checker/plugin.js +4 -7
  300. package/es/rce/plugins/tinymce-a11y-checker/rules/adjacent-links.js +3 -26
  301. package/es/rce/plugins/tinymce-a11y-checker/rules/headings-sequence.js +9 -38
  302. package/es/rce/plugins/tinymce-a11y-checker/rules/headings-start-at-h2.js +1 -5
  303. package/es/rce/plugins/tinymce-a11y-checker/rules/img-alt-filename.js +1 -2
  304. package/es/rce/plugins/tinymce-a11y-checker/rules/img-alt-length.js +1 -1
  305. package/es/rce/plugins/tinymce-a11y-checker/rules/img-alt.js +1 -2
  306. package/es/rce/plugins/tinymce-a11y-checker/rules/index.js +1 -0
  307. package/es/rce/plugins/tinymce-a11y-checker/rules/large-text-contrast.js +1 -4
  308. package/es/rce/plugins/tinymce-a11y-checker/rules/list-structure.js +5 -24
  309. package/es/rce/plugins/tinymce-a11y-checker/rules/paragraphs-for-headings.js +1 -3
  310. package/es/rce/plugins/tinymce-a11y-checker/rules/small-text-contrast.js +1 -6
  311. package/es/rce/plugins/tinymce-a11y-checker/rules/table-caption.js +1 -3
  312. package/es/rce/plugins/tinymce-a11y-checker/rules/table-header-scope.js +1 -2
  313. package/es/rce/plugins/tinymce-a11y-checker/rules/table-header.js +1 -9
  314. package/es/rce/plugins/tinymce-a11y-checker/utils/colors.js +1 -0
  315. package/es/rce/plugins/tinymce-a11y-checker/utils/describe.js +1 -7
  316. package/es/rce/plugins/tinymce-a11y-checker/utils/dom.js +1 -26
  317. package/es/rce/plugins/tinymce-a11y-checker/utils/indicate.js +16 -15
  318. package/es/rce/plugins/tinymce-a11y-checker/utils/rgb-hex.js +7 -10
  319. package/es/rce/plugins/tinymce-a11y-checker/utils/strings.js +1 -4
  320. package/es/rce/root.js +9 -8
  321. package/es/rce/sanitizePlugins.js +1 -3
  322. package/es/rce/style.js +1 -4
  323. package/es/rce/tinyRCE.js +13 -9
  324. package/es/rce/tinymce.oxide.content.min.css.js +1 -0
  325. package/es/rce/tinymce.oxide.skin.min.css.js +1 -0
  326. package/es/rce/transformContent.js +8 -10
  327. package/es/rce/types.js +1 -0
  328. package/es/rce/userOS.js +1 -1
  329. package/es/rce/wrapInitCb.js +50 -43
  330. package/es/rcs/api.js +61 -116
  331. package/es/rcs/buildError.js +5 -17
  332. package/es/rcs/fake.js +4 -13
  333. package/es/sidebar/actions/all_files.js +2 -0
  334. package/es/sidebar/actions/data.js +4 -7
  335. package/es/sidebar/actions/documents.js +9 -6
  336. package/es/sidebar/actions/files.js +3 -6
  337. package/es/sidebar/actions/filter.js +1 -0
  338. package/es/sidebar/actions/flickr.js +1 -1
  339. package/es/sidebar/actions/images.js +12 -11
  340. package/es/sidebar/actions/links.js +1 -0
  341. package/es/sidebar/actions/media.js +12 -10
  342. package/es/sidebar/actions/session.js +1 -3
  343. package/es/sidebar/actions/ui.js +1 -0
  344. package/es/sidebar/actions/upload.js +14 -39
  345. package/es/sidebar/containers/Sidebar.js +1 -2
  346. package/es/sidebar/containers/sidebarHandlers.js +3 -1
  347. package/es/sidebar/dragHtml.js +5 -3
  348. package/es/sidebar/reducers/all_files.js +4 -3
  349. package/es/sidebar/reducers/collection.js +12 -13
  350. package/es/sidebar/reducers/collections.js +5 -5
  351. package/es/sidebar/reducers/documents.js +6 -13
  352. package/es/sidebar/reducers/files.js +3 -3
  353. package/es/sidebar/reducers/filter.js +1 -8
  354. package/es/sidebar/reducers/flickr.js +9 -9
  355. package/es/sidebar/reducers/folder.js +15 -15
  356. package/es/sidebar/reducers/folders.js +3 -3
  357. package/es/sidebar/reducers/images.js +3 -13
  358. package/es/sidebar/reducers/index.js +3 -1
  359. package/es/sidebar/reducers/media.js +6 -13
  360. package/es/sidebar/reducers/newPageLinkExpanded.js +1 -2
  361. package/es/sidebar/reducers/noop.js +1 -0
  362. package/es/sidebar/reducers/rootFolderId.js +1 -2
  363. package/es/sidebar/reducers/session.js +3 -3
  364. package/es/sidebar/reducers/ui.js +3 -16
  365. package/es/sidebar/reducers/upload.js +8 -40
  366. package/es/sidebar/store/configureStore.js +1 -0
  367. package/es/sidebar/store/initialState.js +13 -24
  368. package/es/translations/locales/ab.js +1 -0
  369. package/es/translations/locales/ar.js +67 -9
  370. package/es/translations/locales/ca.js +67 -9
  371. package/es/translations/locales/cs.js +1 -0
  372. package/es/translations/locales/cs_CZ.js +1 -0
  373. package/es/translations/locales/cy.js +67 -9
  374. package/es/translations/locales/da-x-k12.js +67 -9
  375. package/es/translations/locales/da.js +67 -9
  376. package/es/translations/locales/da_DK.js +1 -0
  377. package/es/translations/locales/de.js +67 -9
  378. package/es/translations/locales/el.js +4 -0
  379. package/es/translations/locales/en-AU-x-unimelb.js +67 -9
  380. package/es/translations/locales/en-GB-x-ukhe.js +67 -9
  381. package/es/translations/locales/en.js +72 -8
  382. package/es/translations/locales/en_AU.js +67 -9
  383. package/es/translations/locales/en_CA.js +67 -9
  384. package/es/translations/locales/en_CY.js +67 -9
  385. package/es/translations/locales/en_GB.js +67 -9
  386. package/es/translations/locales/en_NZ.js +1 -0
  387. package/es/translations/locales/en_SE.js +1 -0
  388. package/es/translations/locales/en_US.js +1 -0
  389. package/es/translations/locales/es.js +67 -9
  390. package/es/translations/locales/es_ES.js +67 -9
  391. package/es/translations/locales/es_GT.js +1 -0
  392. package/es/translations/locales/fa_IR.js +7 -0
  393. package/es/translations/locales/fi.js +67 -9
  394. package/es/translations/locales/fr.js +67 -9
  395. package/es/translations/locales/fr_CA.js +68 -10
  396. package/es/translations/locales/ga.js +5 -13
  397. package/es/translations/locales/he.js +7 -0
  398. package/es/translations/locales/hi.js +67 -9
  399. package/es/translations/locales/ht.js +67 -9
  400. package/es/translations/locales/hu.js +7 -6
  401. package/es/translations/locales/hu_HU.js +1 -0
  402. package/es/translations/locales/hy.js +1 -0
  403. package/es/translations/locales/id.js +67 -9
  404. package/es/translations/locales/id_ID.js +1 -0
  405. package/es/translations/locales/is.js +67 -9
  406. package/es/translations/locales/it.js +67 -9
  407. package/es/translations/locales/ja.js +67 -9
  408. package/es/translations/locales/ko.js +1 -0
  409. package/es/translations/locales/ko_KR.js +1 -0
  410. package/es/translations/locales/lt.js +1 -0
  411. package/es/translations/locales/lt_LT.js +1 -0
  412. package/es/translations/locales/mi.js +67 -9
  413. package/es/translations/locales/mn_MN.js +1 -0
  414. package/es/translations/locales/ms.js +67 -9
  415. package/es/translations/locales/nb-x-k12.js +67 -9
  416. package/es/translations/locales/nb.js +67 -9
  417. package/es/translations/locales/nl.js +67 -9
  418. package/es/translations/locales/nl_NL.js +1 -0
  419. package/es/translations/locales/nn.js +7 -6
  420. package/es/translations/locales/pl.js +67 -9
  421. package/es/translations/locales/pt.js +67 -9
  422. package/es/translations/locales/pt_BR.js +67 -9
  423. package/es/translations/locales/ro.js +1 -0
  424. package/es/translations/locales/ru.js +67 -9
  425. package/es/translations/locales/se.js +1 -0
  426. package/es/translations/locales/sl.js +67 -9
  427. package/es/translations/locales/sv-x-k12.js +67 -9
  428. package/es/translations/locales/sv.js +67 -9
  429. package/es/translations/locales/sv_SE.js +1 -0
  430. package/es/translations/locales/tg.js +1 -0
  431. package/es/translations/locales/th.js +67 -9
  432. package/es/translations/locales/th_TH.js +1 -0
  433. package/es/translations/locales/tl_PH.js +1 -0
  434. package/es/translations/locales/tr.js +7 -0
  435. package/es/translations/locales/uk_UA.js +7 -0
  436. package/es/translations/locales/vi.js +67 -9
  437. package/es/translations/locales/vi_VN.js +1 -0
  438. package/es/translations/locales/zh-Hans.js +67 -9
  439. package/es/translations/locales/zh-Hant.js +67 -9
  440. package/es/translations/locales/zh.js +67 -9
  441. package/es/translations/locales/zh_HK.js +67 -9
  442. package/es/translations/locales/zh_TW.Big5.js +1 -0
  443. package/es/translations/locales/zh_TW.js +1 -0
  444. package/es/translations/tinymce/ar_SA.js +1 -0
  445. package/es/translations/tinymce/fi.js +1 -0
  446. package/es/translations/tinymce/ga.js +1 -0
  447. package/es/translations/tinymce/id.js +1 -0
  448. package/es/translations/tinymce/ru.js +1 -0
  449. package/es/translations/tinymce/ru_RU.js +1 -0
  450. package/es/translations/tinymce/sl.js +1 -0
  451. package/es/translations/tinymce/sr.js +1 -0
  452. package/es/translations/tinymce/th.js +1 -0
  453. package/es/translations/tinymce/uk_UA.js +1 -0
  454. package/es/translations/tinymce/vi_VN.js +1 -0
  455. package/es/util/TypedDict.js +4 -2
  456. package/es/util/encrypted-storage.js +3 -13
  457. package/es/util/file-url-util.js +1 -6
  458. package/es/util/fullscreenHelpers.js +4 -1
  459. package/es/util/instui-icon-helper.js +4 -3
  460. package/es/util/loadingPlaceholder.js +38 -39
  461. package/es/util/simpleCache.js +0 -3
  462. package/es/util/string-util.js +1 -1
  463. package/es/util/textarea-editing-util.js +3 -7
  464. package/es/util/tinymce-plugin-util.js +0 -5
  465. package/es/util/url-util.js +16 -25
  466. package/eslint.config.js +239 -0
  467. package/jest.config.js +1 -1
  468. package/package.json +76 -81
  469. package/scripts/build-canvas +2 -1
  470. package/scripts/build.js +4 -4
  471. package/testcafe/RCEWrapper.test.js +0 -1
  472. package/testcafe/StatusBar.test.js +0 -1
  473. package/testcafe/axe.test.js +3 -4
  474. package/testcafe/enhanceUserContent.test.js +0 -1
  475. package/tsconfig.json +20 -15
  476. package/.eslintrc +0 -45
  477. package/.prettierignore +0 -6
  478. package/es/rce/__mocks__/_mockCryptoEs.js +0 -124
  479. package/es/rce/__mocks__/styleMock.js +0 -18
  480. package/es/rce/__mocks__/tinymceReact.js +0 -55
  481. package/es/rce/plugins/tinymce-a11y-checker/rules/__mocks__/index.js +0 -53
@@ -0,0 +1,819 @@
1
+ /*
2
+ * Copyright (C) 2018 - present Instructure, Inc.
3
+ *
4
+ * This file is part of Canvas.
5
+ *
6
+ * Canvas is free software: you can redistribute it and/or modify it under
7
+ * the terms of the GNU Affero General Public License as published by the Free
8
+ * Software Foundation, version 3 of the License.
9
+ *
10
+ * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
11
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
+ * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13
+ * details.
14
+ *
15
+ * You should have received a copy of the GNU Affero General Public License along
16
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ import RceApiSource, {headerFor, originFromHost} from '../../src/rcs/api'
20
+ import fetchMock from 'fetch-mock'
21
+ import * as fileUrl from '../../src/common/fileUrl'
22
+ import {ICON_MAKER_ICONS} from '../../src/rce/plugins/instructure_icon_maker/svg/constants'
23
+
24
+ describe('sources/api', () => {
25
+ const endpoint = 'wikiPages'
26
+ const props = {
27
+ host: 'example.host',
28
+ contextType: 'group',
29
+ contextId: 123,
30
+ sortBy: {sort: 'date_added', dir: 'desc'},
31
+ searchString: '',
32
+ }
33
+ let setProps = {}
34
+ let apiSource
35
+ let alertFuncSpy
36
+
37
+ beforeEach(() => {
38
+ alertFuncSpy = jest.fn()
39
+ apiSource = new RceApiSource({
40
+ jwt: 'theJWT',
41
+ refreshToken: callback => {
42
+ callback('freshJWT')
43
+ },
44
+ alertFunc: alertFuncSpy,
45
+ })
46
+ fetchMock.mock('/api/session', '{}')
47
+ })
48
+
49
+ afterEach(() => {
50
+ fetchMock.restore()
51
+ jest.resetAllMocks()
52
+ })
53
+
54
+ describe('initializeCollection', () => {
55
+ let collection
56
+ beforeEach(() => {
57
+ collection = apiSource.initializeCollection(endpoint, props)
58
+ })
59
+
60
+ it('creates a collection with no links', () => {
61
+ expect(collection.links).toEqual([])
62
+ })
63
+
64
+ it('creates a collection with a bookmark derived from props', () => {
65
+ expect(collection.bookmark).toEqual(
66
+ `${window.location.protocol}//example.host/api/wikiPages?contextType=group&contextId=123&search_term=panda`
67
+ )
68
+ })
69
+
70
+ it('bookmark omits host if not in props', () => {
71
+ const noHostProps = {...props, host: undefined}
72
+ collection = apiSource.initializeCollection(endpoint, noHostProps)
73
+ expect(collection.bookmark).toEqual(
74
+ '/api/wikiPages?contextType=group&contextId=123&search_term=panda'
75
+ )
76
+ })
77
+
78
+ it('creates a collection that is not initially loading', () => {
79
+ expect(collection.isLoading).toEqual(false)
80
+ })
81
+
82
+ it('creates a collection that initially has more', () => {
83
+ expect(collection.hasMore).toEqual(true)
84
+ })
85
+ })
86
+
87
+ describe('initializeImages', () => {
88
+ it('sets hasMore to true', () => {
89
+ expect(apiSource.initializeImages(props)[props.contextType].hasMore).toEqual(true)
90
+ })
91
+
92
+ it('sets searchString to an empty string', () => {
93
+ expect(apiSource.initializeImages(props).searchString).toEqual('')
94
+ })
95
+ })
96
+
97
+ describe('URI construction (baseUri)', () => {
98
+ it('uses a protocol relative url when no window', () => {
99
+ const uri = apiSource.baseUri('files', 'example.instructure.com', {})
100
+ expect(uri).toEqual('//example.instructure.com/api/files')
101
+ })
102
+
103
+ it('uses a path for no-host url construction', () => {
104
+ const uri = apiSource.baseUri('files')
105
+ expect(uri).toEqual('/api/files')
106
+ })
107
+
108
+ it('gets protocol from window if available', () => {
109
+ const fakeWindow = {location: {protocol: 'https:'}}
110
+ const uri = apiSource.baseUri('files', 'example.instructure.com', fakeWindow)
111
+ expect(uri).toEqual('https://example.instructure.com/api/files')
112
+ })
113
+
114
+ it('never applies protocol to path', () => {
115
+ const fakeWindow = {location: {protocol: 'https:'}}
116
+ const uri = apiSource.baseUri('files', null, fakeWindow)
117
+ expect(uri).toEqual('/api/files')
118
+ })
119
+
120
+ it("will replace protocol if there's a mismatch from http to https", () => {
121
+ const fakeWindow = {location: {protocol: 'https:'}}
122
+ const uri = apiSource.normalizeUriProtocol('http://something.com', fakeWindow)
123
+ expect(uri).toEqual('https://something.com')
124
+ })
125
+ })
126
+
127
+ describe('more URI construction (uriFor)', () => {
128
+ beforeEach(() => {
129
+ setProps = {
130
+ host: undefined,
131
+ contextType: 'course',
132
+ contextId: '17',
133
+ sortBy: {sort: 'alphabetical', dir: 'asc'},
134
+ searchString: 'hello world',
135
+ }
136
+ })
137
+
138
+ it('gets documents', () => {
139
+ const uri = apiSource.uriFor('documents', setProps)
140
+ expect(uri).toEqual(
141
+ '/api/documents?contextType=course&contextId=17&exclude_content_types=image,video,audio&sort=name&order=asc&search_term=hello%20world'
142
+ )
143
+ })
144
+
145
+ it('gets images', () => {
146
+ const uri = apiSource.uriFor('images', setProps)
147
+ expect(uri).toEqual(
148
+ '/api/documents?contextType=course&contextId=17&content_types=image&sort=name&order=asc&search_term=hello%20world'
149
+ )
150
+ })
151
+
152
+ // this endpoint isn't actually used yet, but could be if media_objects all had associated Attachments
153
+ it('gets media', () => {
154
+ const uri = apiSource.uriFor('media', setProps)
155
+ expect(uri).toEqual(
156
+ '/api/documents?contextType=course&contextId=17&content_types=video,audio&sort=name&order=asc&search_term=hello%20world'
157
+ )
158
+ })
159
+
160
+ it('gets media_objects', () => {
161
+ const uri = apiSource.uriFor('media_objects', setProps)
162
+ expect(uri).toEqual(
163
+ '/api/media_objects?contextType=course&contextId=17&sort=title&order=asc&search_term=hello%20world'
164
+ )
165
+ })
166
+ })
167
+
168
+ describe('fetchPage', () => {
169
+ const uri = 'theURI'
170
+ const fakePageBody =
171
+ '{"bookmark":"newBookmark","links":[' +
172
+ '{"href":"link1","title":"Link 1"},' +
173
+ '{"href":"link2","title":"Link 2"}]}'
174
+
175
+ it('includes jwt in Authorization header', async () => {
176
+ fetchMock.mock(uri, '{}')
177
+ await apiSource.fetchPage(uri)
178
+ expect(fetchMock.lastOptions(uri).headers.Authorization).toEqual('Bearer theJWT')
179
+ })
180
+
181
+ it('converts 400+ statuses to errors', async () => {
182
+ fetchMock.mock(uri, 403)
183
+ await expect(apiSource.fetchPage(uri)).rejects.toThrow('Forbidden')
184
+ })
185
+
186
+ it('parses server response before handing it back', async () => {
187
+ fetchMock.mock(uri, fakePageBody)
188
+ const page = await apiSource.fetchPage(uri)
189
+ expect(page).toEqual({
190
+ bookmark: 'newBookmark',
191
+ links: [
192
+ {href: 'link1', title: 'Link 1'},
193
+ {href: 'link2', title: 'Link 2'},
194
+ ],
195
+ })
196
+ })
197
+
198
+ it('retries once on 401 with a renewed token', async () => {
199
+ fetchMock.mock((fetchUrl, opts) => {
200
+ return uri === fetchUrl && opts.headers.Authorization === 'Bearer theJWT'
201
+ }, 401)
202
+
203
+ fetchMock.mock((fetchUrl, opts) => {
204
+ return uri === fetchUrl && opts.headers.Authorization === 'Bearer freshJWT'
205
+ }, fakePageBody)
206
+
207
+ const page = await apiSource.fetchPage(uri, 'theJWT')
208
+ expect(page.bookmark).toEqual('newBookmark')
209
+ expect(apiSource.jwt).toEqual('freshJWT')
210
+ })
211
+ })
212
+
213
+ describe('fetchFiles', () => {
214
+ let bookmark, files, wrapUrl
215
+
216
+ beforeEach(() => {
217
+ bookmark = 'some-bookmark'
218
+ files = [{url: '/url1'}, {url: '/url2'}]
219
+ wrapUrl = '/path?preview=1'
220
+ const body = {bookmark, files}
221
+ jest.spyOn(apiSource, 'fetchPage').mockReturnValue(Promise.resolve(body))
222
+ jest.spyOn(fileUrl, 'downloadToWrap').mockReturnValue(wrapUrl)
223
+ })
224
+
225
+ it('proxies the call to fetchPage', async () => {
226
+ const uri = 'files-uri'
227
+ const body = await apiSource.fetchFiles(uri)
228
+ expect(apiSource.fetchPage).toHaveBeenCalledWith(uri)
229
+ expect(body.bookmark).toEqual(bookmark)
230
+ })
231
+
232
+ it('converts file urls from download to preview', async () => {
233
+ const body = await apiSource.fetchFiles('foo')
234
+ files.forEach((file, i) => {
235
+ expect(fileUrl.downloadToWrap).toHaveBeenCalledWith(file.url)
236
+ expect(body.files[i].href).toEqual(wrapUrl)
237
+ })
238
+ })
239
+ })
240
+
241
+ describe('fetchSubFolders()', () => {
242
+ let bookmark
243
+
244
+ beforeEach(() => {
245
+ setProps = {host: 'canvas.rce', folderId: 2}
246
+ bookmark = undefined
247
+ jest.spyOn(apiSource, 'apiFetch').mockReturnValue(Promise.resolve({}))
248
+ })
249
+
250
+ it('makes a request to the folders api with the given host and ID', () => {
251
+ apiSource.fetchSubFolders(setProps, bookmark)
252
+ expect(apiSource.apiFetch).toHaveBeenCalledWith(
253
+ `${window.location.protocol}//canvas.rce/api/folders/2`,
254
+ {
255
+ Authorization: 'Bearer theJWT',
256
+ }
257
+ )
258
+ })
259
+
260
+ describe('fetchFilesForFolder()', () => {
261
+ beforeEach(() => {
262
+ setProps = {host: 'canvas.rce', filesUrl: 'https://canvas.rce/api/files/2'}
263
+ bookmark = undefined
264
+ })
265
+
266
+ it('makes a request to the files api with given host and folder ID', () => {
267
+ apiSource.fetchFilesForFolder(setProps, bookmark)
268
+ expect(apiSource.apiFetch).toHaveBeenCalledWith('https://canvas.rce/api/files/2', {
269
+ Authorization: 'Bearer theJWT',
270
+ })
271
+ })
272
+
273
+ describe('with perPage set', () => {
274
+ beforeEach(() => {
275
+ setProps.perPage = 50
276
+ })
277
+
278
+ it('includes the "per_page" query param', () => {
279
+ apiSource.fetchFilesForFolder(setProps, bookmark)
280
+ expect(apiSource.apiFetch).toHaveBeenCalledWith(
281
+ 'https://canvas.rce/api/files/2?per_page=50',
282
+ {
283
+ Authorization: 'Bearer theJWT',
284
+ }
285
+ )
286
+ })
287
+ })
288
+ })
289
+
290
+ describe('with a provided bookmark', () => {
291
+ beforeEach(() => (bookmark = 'https://canvas.rce/api/folders/2?page=2'))
292
+
293
+ it('makes a request to the bookmark', () => {
294
+ apiSource.fetchSubFolders(props, bookmark)
295
+ expect(apiSource.apiFetch).toHaveBeenCalledWith(bookmark, {
296
+ Authorization: 'Bearer theJWT',
297
+ })
298
+ })
299
+ })
300
+ })
301
+
302
+ describe('fetchBookmarkedData', () => {
303
+ let fetchFunction, properties, onSuccess, onError
304
+
305
+ beforeEach(() => {
306
+ fetchFunction = jest
307
+ .fn()
308
+ .mockReturnValueOnce(Promise.resolve({bookmark: 'https://canvas.rce/api/thing/1?page=2'}))
309
+ .mockReturnValueOnce(Promise.resolve({data: 'foo'}))
310
+ properties = {foo: 'bar'}
311
+ onSuccess = jest.fn()
312
+ onError = jest.fn()
313
+ })
314
+
315
+ afterEach(() => {
316
+ jest.resetAllMocks()
317
+ })
318
+
319
+ const subject = () =>
320
+ apiSource.fetchBookmarkedData(fetchFunction, properties, onSuccess, onError)
321
+
322
+ it('calls the "fetchFunction", passing "properties"', async () => {
323
+ await subject()
324
+ expect(fetchFunction).toHaveBeenCalledWith(properties, undefined)
325
+ expect(fetchFunction).toHaveBeenCalledWith(
326
+ properties,
327
+ 'https://canvas.rce/api/thing/1?page=2'
328
+ )
329
+ expect(fetchFunction).toHaveBeenCalledTimes(2)
330
+ })
331
+
332
+ it('calls "onSuccess" for each page', async () => {
333
+ await subject()
334
+ expect(onSuccess).toHaveBeenCalledTimes(2)
335
+ })
336
+
337
+ describe('when "fetchFunction" throws an exception', () => {
338
+ beforeEach(() => {
339
+ jest.resetAllMocks()
340
+ fetchFunction.mockRejectedValue('error')
341
+ })
342
+
343
+ it('calls "onError"', () => {
344
+ return subject().then(() => {
345
+ expect(onError).toHaveBeenCalledTimes(1)
346
+ })
347
+ })
348
+ })
349
+ })
350
+
351
+ describe('fetchIconMakerFolder', () => {
352
+ let folders
353
+
354
+ beforeEach(() => {
355
+ folders = [{id: 24}]
356
+ const body = {folders}
357
+ jest.spyOn(apiSource, 'fetchPage').mockReturnValue(Promise.resolve(body))
358
+ })
359
+
360
+ it('calls fetchPage with the proper params', () => {
361
+ return apiSource
362
+ .fetchIconMakerFolder({
363
+ contextType: 'course',
364
+ contextId: '22',
365
+ })
366
+ .then(() => {
367
+ expect(apiSource.fetchPage).toHaveBeenCalledWith(
368
+ '/api/folders/icon_maker?contextType=course&contextId=22'
369
+ )
370
+ })
371
+ })
372
+ })
373
+
374
+ describe('fetchMediaFolder', () => {
375
+ let files
376
+ beforeEach(() => {
377
+ files = [{id: 24}]
378
+ const body = {files}
379
+ jest.spyOn(apiSource, 'fetchPage').mockReturnValue(Promise.resolve(body))
380
+ })
381
+
382
+ it('calls fetchPage with the proper params', () => {
383
+ return apiSource
384
+ .fetchMediaFolder({
385
+ contextType: 'course',
386
+ contextId: '22',
387
+ })
388
+ .then(() => {
389
+ expect(apiSource.fetchPage).toHaveBeenCalledWith(
390
+ '/api/folders/media?contextType=course&contextId=22'
391
+ )
392
+ })
393
+ })
394
+ })
395
+
396
+ describe('preflightUpload', () => {
397
+ const uri = '/api/upload'
398
+ const fileProps = {}
399
+ const apiProps = {}
400
+
401
+ afterEach(() => {
402
+ fetchMock.restore()
403
+ })
404
+
405
+ it('includes "onDuplicate"', () => {
406
+ fetchMock.mock(uri, '{}')
407
+
408
+ return apiSource.preflightUpload(fileProps, {onDuplicate: 'overwrite'}, apiProps).then(() => {
409
+ const body = JSON.parse(fetchMock.lastOptions(uri).body)
410
+ expect(body.onDuplicate).toEqual('overwrite')
411
+ })
412
+ })
413
+
414
+ it('includes "category"', () => {
415
+ fetchMock.mock(uri, '{}')
416
+
417
+ return apiSource
418
+ .preflightUpload(fileProps, {category: ICON_MAKER_ICONS}, apiProps)
419
+ .then(() => {
420
+ const body = JSON.parse(fetchMock.lastOptions(uri).body)
421
+ expect(body.category).toEqual(ICON_MAKER_ICONS)
422
+ })
423
+ })
424
+
425
+ it('includes jwt in Authorization header', () => {
426
+ fetchMock.mock(uri, '{}')
427
+
428
+ return apiSource.preflightUpload(fileProps, apiProps).then(() => {
429
+ expect(fetchMock.lastOptions(uri).headers.Authorization).toEqual('Bearer theJWT')
430
+ })
431
+ })
432
+
433
+ it('retries once with fresh token on 401', () => {
434
+ fetchMock.mock((fetchUrl, opts) => {
435
+ return uri === fetchUrl && opts.headers.Authorization === 'Bearer theJWT'
436
+ }, 401)
437
+
438
+ fetchMock.mock((fetchUrl, opts) => {
439
+ return uri === fetchUrl && opts.headers.Authorization === 'Bearer freshJWT'
440
+ }, '{"upload": "done"}')
441
+
442
+ return apiSource.preflightUpload(fileProps, apiProps).then(response => {
443
+ expect(response.upload).toEqual('done')
444
+ })
445
+ })
446
+
447
+ it('notifies a provided callback when a new token is fetched', () => {
448
+ fetchMock.mock((fetchUrl, opts) => {
449
+ return uri === fetchUrl && opts.headers.Authorization === 'Bearer theJWT'
450
+ }, 401)
451
+
452
+ fetchMock.mock((fetchUrl, opts) => {
453
+ return uri === fetchUrl && opts.headers.Authorization === 'Bearer freshJWT'
454
+ }, '{"upload": "done"}')
455
+
456
+ return apiSource.preflightUpload(fileProps, apiProps).then(() => {
457
+ expect(apiSource.jwt).toEqual('freshJWT')
458
+ })
459
+ })
460
+
461
+ it('calls alertFunc when an error occurs', () => {
462
+ fetchMock.mock(uri, 500)
463
+ return apiSource
464
+ .preflightUpload(fileProps, apiProps)
465
+ .then(() => {
466
+ expect(alertFuncSpy).toHaveBeenCalledWith({
467
+ text: 'Something went wrong uploading, check your connection and try again.',
468
+ variant: 'error',
469
+ })
470
+ })
471
+ .catch(() => {
472
+ // This will re-throw so we just catch it here.
473
+ })
474
+ })
475
+
476
+ it('throws an exception when an error occurs', () => {
477
+ fetchMock.mock(uri, 500)
478
+ return apiSource.preflightUpload(fileProps, apiProps).catch(e => {
479
+ expect(e).not.toBeNull()
480
+ })
481
+ })
482
+
483
+ describe('when the file storage quota is exceeded', () => {
484
+ beforeEach(() => {
485
+ const error = new Error('file size exceeds quota')
486
+ error.response = {json: async () => ({message: 'file size exceeds quota'})}
487
+
488
+ fetchMock.mock(uri, {throws: error}, {overwriteRoutes: true})
489
+ })
490
+
491
+ it('gives a "quota" error if quota is full', async () => {
492
+ try {
493
+ await apiSource.preflightUpload(fileProps, apiProps)
494
+ expect(alertFuncSpy).toHaveBeenCalledWith({
495
+ text: 'File storage quota exceeded',
496
+ variant: 'error',
497
+ })
498
+ } catch (e) {
499
+ return e
500
+ } // This will re-throw so we just catch it here/
501
+ })
502
+ })
503
+ })
504
+
505
+ describe('uploadFRD', () => {
506
+ let fileDomObject, uploadUrl, preflightProps, file, wrapUrl
507
+
508
+ beforeEach(() => {
509
+ fileDomObject = new window.Blob()
510
+ uploadUrl = 'upload-url'
511
+ preflightProps = {
512
+ upload_params: {},
513
+ upload_url: uploadUrl,
514
+ }
515
+ file = {url: 'file-url'}
516
+ fetchMock.mock(uploadUrl, file)
517
+ })
518
+
519
+ afterEach(() => {
520
+ fetchMock.restore()
521
+ })
522
+
523
+ it('calls alertFunc if there is a problem', () => {
524
+ fetchMock.once(uploadUrl, 500, {overwriteRoutes: true})
525
+ return apiSource
526
+ .uploadFRD(fileDomObject, preflightProps)
527
+ .then(() => {
528
+ expect(alertFuncSpy).toHaveBeenCalledWith({
529
+ text: 'Something went wrong uploading, check your connection and try again.',
530
+ variant: 'error',
531
+ })
532
+ })
533
+ .catch(() => {})
534
+ })
535
+
536
+ describe('files', () => {
537
+ beforeEach(() => {
538
+ wrapUrl = '/groups/123/path?wrap=1'
539
+ jest.spyOn(fileUrl, 'downloadToWrap').mockReturnValue(wrapUrl)
540
+ jest.spyOn(fileUrl, 'fixupFileUrl').mockReturnValue(wrapUrl)
541
+ jest.spyOn(apiSource, 'getFile').mockReturnValue(Promise.resolve(file))
542
+ })
543
+
544
+ afterEach(() => {
545
+ jest.restoreAllMocks()
546
+ })
547
+
548
+ it('includes credentials in non-S3 upload', () => {
549
+ preflightProps.upload_params.success_url = undefined
550
+ return apiSource.uploadFRD(fileDomObject, preflightProps).then(() => {
551
+ expect(fetchMock.lastOptions(uploadUrl).credentials).toEqual('include')
552
+ })
553
+ })
554
+
555
+ it('does not include credentials in S3 upload', () => {
556
+ preflightProps.upload_params['x-amz-signature'] = 'success-url'
557
+ preflightProps.upload_params.success_url = 'success-url'
558
+ const s3File = {url: 's3-file-url'}
559
+ fetchMock.mock(preflightProps.upload_params.success_url, s3File)
560
+ return apiSource.uploadFRD(fileDomObject, preflightProps).then(() => {
561
+ expect(fetchMock.lastOptions(uploadUrl).credentials).toBeUndefined()
562
+ })
563
+ })
564
+
565
+ it('does not include credentials in a local cross-origin upload', () => {
566
+ preflightProps.upload_params.success_url = undefined
567
+ const crossOriginUploadUrl = 'cross-origin.site/files_api'
568
+ preflightProps.upload_url = crossOriginUploadUrl
569
+ fetchMock.mock(crossOriginUploadUrl, file)
570
+ return apiSource.uploadFRD(fileDomObject, preflightProps).then(() => {
571
+ expect(fetchMock.lastOptions(crossOriginUploadUrl).credentials).toBeUndefined()
572
+ })
573
+ })
574
+
575
+ it('handles s3 post-flight', async () => {
576
+ preflightProps.upload_params.success_url = 'success-url'
577
+ const s3File = {url: 's3-file-url'}
578
+ fetchMock.mock(preflightProps.upload_params.success_url, s3File)
579
+ const result = await apiSource.uploadFRD(fileDomObject, preflightProps)
580
+ expect(result).toEqual(s3File)
581
+ })
582
+
583
+ it('handles inst-fs post-flight', () => {
584
+ preflightProps.upload_url = 'instfs-upload-url'
585
+ const fileId = '123'
586
+ const response = {
587
+ location: `http://canvas/api/v1/files/${fileId}?foo=bar`,
588
+ uuid: 'xyzzy',
589
+ }
590
+ fetchMock.mock(preflightProps.upload_url, response)
591
+ return apiSource.uploadFRD(fileDomObject, preflightProps).then(resp => {
592
+ expect(apiSource.getFile).toHaveBeenCalledWith(fileId)
593
+ expect(resp.uuid).toEqual('xyzzy')
594
+ expect(resp.url).toEqual('file-url')
595
+ })
596
+ })
597
+
598
+ it('handles inst-fs post-flight with global file id', () => {
599
+ preflightProps.upload_url = 'instfs-upload-url'
600
+ const fileId = '1023~789'
601
+ const response = {
602
+ location: `http://canvas/api/v1/files/${fileId}?foo=bar`,
603
+ uuid: 'xyzzy',
604
+ }
605
+ fetchMock.mock(preflightProps.upload_url, response)
606
+ return apiSource.uploadFRD(fileDomObject, preflightProps).then(resp => {
607
+ expect(apiSource.getFile).toHaveBeenCalledWith(fileId)
608
+ expect(resp.uuid).toEqual('xyzzy')
609
+ expect(resp.url).toEqual('file-url')
610
+ })
611
+ })
612
+ })
613
+ })
614
+
615
+ describe('api mapping', () => {
616
+ const body = {
617
+ bookmark: 'mo.images',
618
+ files: [{href: '/some/where', uuid: 'xyzzy'}],
619
+ }
620
+ props.images = {
621
+ group: {
622
+ isLoading: false,
623
+ hasMore: true,
624
+ bookmark: null,
625
+ files: [],
626
+ },
627
+ }
628
+ props.searchString = 'panda'
629
+
630
+ it('can fetch folders', async () => {
631
+ fetchMock.mock(/\/folders\?/, {body})
632
+ const page = await apiSource.fetchRootFolder(props)
633
+ expect(page).toEqual(body)
634
+ })
635
+
636
+ it('requests images from API', async () => {
637
+ fetchMock.mock(/\/documents\?.*content_types=image/, {body})
638
+ const page = await apiSource.fetchImages(props)
639
+ expect(page).toEqual({
640
+ bookmark: 'mo.images',
641
+ files: [{href: '/some/where?wrap=1', uuid: 'xyzzy'}],
642
+ searchString: 'panda',
643
+ })
644
+ })
645
+
646
+ it('requests subsequent page of images from API', async () => {
647
+ props.images.group.bookmark = 'mo.images'
648
+ fetchMock.mock(/\/documents\?.*content_types=image/, 'should not get here')
649
+ fetchMock.mock(/mo.images/, {body})
650
+ const page = await apiSource.fetchImages(props)
651
+ expect(page).toEqual({
652
+ bookmark: 'mo.images',
653
+ files: [{href: '/some/where?wrap=1', uuid: 'xyzzy'}],
654
+ searchString: 'panda',
655
+ })
656
+ })
657
+ })
658
+
659
+ describe('getSession', () => {
660
+ const uri = '/api/session' // already mocked
661
+
662
+ it('includes jwt in Authorization header', () => {
663
+ return apiSource.getSession().then(() => {
664
+ expect(fetchMock.lastOptions(uri).headers.Authorization).toEqual('Bearer theJWT')
665
+ })
666
+ })
667
+ })
668
+
669
+ describe('setUsageRights', () => {
670
+ const uri = '/api/usage_rights'
671
+ const fileId = 47
672
+ const usageRights = {usageRight: 'foo'}
673
+
674
+ beforeEach(() => {
675
+ fetchMock.mock(uri, '{}')
676
+ })
677
+
678
+ it('includes jwt in Authorization header', () => {
679
+ return apiSource.setUsageRights(fileId, usageRights).then(() => {
680
+ expect(fetchMock.lastOptions(uri).headers.Authorization).toEqual('Bearer theJWT')
681
+ })
682
+ })
683
+
684
+ it('posts file id and usage rights to the api', () => {
685
+ return apiSource.setUsageRights(fileId, usageRights).then(() => {
686
+ const postBody = JSON.parse(fetchMock.lastOptions(uri).body)
687
+ expect(postBody).toEqual({
688
+ fileId,
689
+ usageRight: usageRights.usageRight,
690
+ })
691
+ })
692
+ })
693
+ })
694
+
695
+ describe('getFile', () => {
696
+ const id = 47
697
+ const uri = `/api/file/${id}`
698
+ let url = '/file/url'
699
+ setProps = {}
700
+
701
+ it('includes jwt in Authorization header', () => {
702
+ fetchMock.mock(uri, {url})
703
+
704
+ return apiSource.getFile(id, setProps).then(() => {
705
+ expect(fetchMock.lastOptions(uri).headers.Authorization).toEqual('Bearer theJWT')
706
+ })
707
+ })
708
+
709
+ it('retries once with fresh token on 401', () => {
710
+ fetchMock.mock((fetchUrl, opts) => {
711
+ return uri === fetchUrl && opts.headers.Authorization === 'Bearer theJWT'
712
+ }, 401)
713
+
714
+ fetchMock.mock(
715
+ (fetchUrl, opts) => {
716
+ return uri === fetchUrl && opts.headers.Authorization === 'Bearer freshJWT'
717
+ },
718
+ {upload: 'done', url}
719
+ )
720
+
721
+ return apiSource.getFile(id, setProps).then(response => {
722
+ expect(response.upload).toEqual('done')
723
+ })
724
+ })
725
+
726
+ it('notifies a provided callback when a new token is fetched', () => {
727
+ fetchMock.mock((fetchUrl, opts) => {
728
+ return uri === fetchUrl && opts.headers.Authorization === 'Bearer theJWT'
729
+ }, 401)
730
+
731
+ fetchMock.mock(
732
+ (fetchUrl, opts) => {
733
+ return uri === fetchUrl && opts.headers.Authorization === 'Bearer freshJWT'
734
+ },
735
+ {upload: 'done', url}
736
+ )
737
+
738
+ return apiSource.getFile(id, setProps).then(() => {
739
+ expect(apiSource.jwt).toEqual('freshJWT')
740
+ })
741
+ })
742
+
743
+ it('transforms file url with downloadToWrap', () => {
744
+ url = '/file/url?download_frd=1'
745
+ const wrapUrl = '/file/url?wrap=1'
746
+ fetchMock.mock('*', {url})
747
+ jest.spyOn(fileUrl, 'downloadToWrap').mockReturnValue(wrapUrl)
748
+ return apiSource.getFile(id).then(file => {
749
+ expect(fileUrl.downloadToWrap).toHaveBeenCalledWith(url)
750
+ expect(file.href).toEqual(wrapUrl)
751
+ fetchMock.restore()
752
+ })
753
+ })
754
+
755
+ it('defaults display_name to name', () => {
756
+ url = '/file/url?download_frd=1'
757
+ const name = 'filename'
758
+ fetchMock.mock('*', {url, name})
759
+ jest.spyOn(fileUrl, 'downloadToWrap')
760
+ return apiSource.getFile(id).then(file => {
761
+ expect(file.display_name).toEqual(name)
762
+ fetchMock.restore()
763
+ })
764
+ })
765
+ })
766
+
767
+ describe('media object apis', () => {
768
+ describe('updateMediaObject', () => {
769
+ it('PUTs to the media_object endpoint', async () => {
770
+ const uri = `/api/media_objects/m-id?user_entered_title=${encodeURIComponent('new title')}`
771
+ fetchMock.put(uri, '{"media_id": "m-id", "title": "new title"}')
772
+ const response = await apiSource.updateMediaObject(
773
+ {},
774
+ {media_object_id: 'm-id', title: 'new title'}
775
+ )
776
+ expect(fetchMock.lastOptions(uri).headers.Authorization).toEqual('Bearer theJWT')
777
+ expect(response).toEqual({media_id: 'm-id', title: 'new title'})
778
+ })
779
+ })
780
+ })
781
+
782
+ describe('headerFor', () => {
783
+ it('returns an authorization header', () => {
784
+ expect(headerFor('the_jwt')).toEqual({
785
+ Authorization: 'Bearer the_jwt',
786
+ })
787
+ })
788
+ })
789
+
790
+ describe('originFromHost', () => {
791
+ // this logic was factored out from baseUri, so the logic is tested
792
+ // there too.
793
+ it('uses the incoming http protocol if present', () => {
794
+ expect(originFromHost('http://host:port')).toEqual('http://host:port')
795
+ })
796
+
797
+ it('uses the incoming https protocol if present', () => {
798
+ expect(originFromHost('https://host:port')).toEqual('https://host:port')
799
+ })
800
+
801
+ it('uses the provided protocol if present', () => {
802
+ const win = {
803
+ location: {
804
+ protocol: 'https:',
805
+ },
806
+ }
807
+ expect(originFromHost('http://host:port', win)).toEqual('http://host:port')
808
+ })
809
+
810
+ it('uses the window protocol if not present', () => {
811
+ const win = {
812
+ location: {
813
+ protocol: 'https:',
814
+ },
815
+ }
816
+ expect(originFromHost('host:port', win)).toEqual('https://host:port')
817
+ })
818
+ })
819
+ })