index.test.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { afterAll, beforeAll, describe, expect, it } from 'vitest'
  2. import resizeObserverPolyfill from 'resize-observer-polyfill'
  3. import Core from '@uppy/core'
  4. import Dashboard from '@uppy/dashboard'
  5. import RemoteSources from './index.ts'
  6. describe('RemoteSources', () => {
  7. beforeAll(() => {
  8. globalThis.ResizeObserver =
  9. // @ts-expect-error .default is fine
  10. resizeObserverPolyfill.default || resizeObserverPolyfill
  11. })
  12. afterAll(() => {
  13. // @ts-expect-error delete does not have to be conditional
  14. delete globalThis.ResizeObserver
  15. })
  16. it('should install RemoteSources with default options', () => {
  17. expect(() => {
  18. const core = new Core()
  19. core.use(Dashboard)
  20. core.use(RemoteSources, { companionUrl: 'https://example.com' })
  21. }).not.toThrow()
  22. })
  23. it('should throw when a companionUrl is not specified', () => {
  24. expect(() => {
  25. const core = new Core()
  26. core.use(Dashboard)
  27. // @ts-expect-error companionUrl is missing
  28. core.use(RemoteSources, { sources: ['Webcam'] })
  29. }).toThrow(
  30. new Error(
  31. 'Please specify companionUrl for RemoteSources to work, see https://uppy.io/docs/remote-sources#companionUrl',
  32. ),
  33. )
  34. })
  35. it('should throw when trying to use a plugin which is not included in RemoteSources', () => {
  36. expect(() => {
  37. const core = new Core()
  38. core.use(Dashboard)
  39. core.use(RemoteSources, {
  40. companionUrl: 'https://example.com',
  41. // @ts-expect-error test invalid
  42. sources: ['Webcam'],
  43. })
  44. }).toThrow(
  45. 'Invalid plugin: "Webcam" is not one of: Box, Dropbox, Facebook, GoogleDrive, Instagram, OneDrive, Unsplash, Url, or Zoom.',
  46. )
  47. })
  48. })