download-menu.test.jsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { screen, waitFor } from '@testing-library/react'
  2. import { expect } from 'chai'
  3. import fetchMock from 'fetch-mock'
  4. import DownloadMenu from '../../../../../frontend/js/features/editor-left-menu/components/download-menu'
  5. import { renderWithEditorContext } from '../../../helpers/render-with-context'
  6. describe('<DownloadMenu />', function () {
  7. afterEach(function () {
  8. fetchMock.removeRoutes().clearHistory()
  9. })
  10. it('shows download links with correct url', async function () {
  11. fetchMock.post('express:/project/:projectId/compile', {
  12. clsiServerId: 'foo',
  13. compileGroup: 'priority',
  14. status: 'success',
  15. pdfDownloadDomain: 'https://clsi.test-overleaf.com',
  16. outputFiles: [
  17. {
  18. path: 'output.pdf',
  19. build: 'build-123',
  20. url: '/build/build-123/output.pdf',
  21. type: 'pdf',
  22. },
  23. ],
  24. })
  25. renderWithEditorContext(<DownloadMenu />, {
  26. projectId: '123abc',
  27. scope: {
  28. editor: {
  29. sharejs_doc: {
  30. doc_id: 'test-doc',
  31. getSnapshot: () => 'some doc content',
  32. },
  33. },
  34. },
  35. })
  36. const sourceLink = screen.getByRole('link', {
  37. name: 'Source',
  38. })
  39. expect(sourceLink.getAttribute('href')).to.equal(
  40. '/project/123abc/download/zip'
  41. )
  42. await waitFor(() => {
  43. const pdfLink = screen.getByRole('link', {
  44. name: 'PDF',
  45. })
  46. expect(pdfLink.getAttribute('href')).to.equal(
  47. '/download/project/123abc/build/build-123/output/output.pdf?compileGroup=priority&clsiserverid=foo&popupDownload=true'
  48. )
  49. })
  50. })
  51. })