actions-menu.test.jsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { screen, waitFor } from '@testing-library/react'
  2. import { expect } from 'chai'
  3. import fetchMock from 'fetch-mock'
  4. import ActionsMenu from '../../../../../frontend/js/features/editor-left-menu/components/actions-menu'
  5. import { renderWithEditorContext } from '../../../helpers/render-with-context'
  6. describe('<ActionsMenu />', function () {
  7. beforeEach(function () {
  8. fetchMock.post('express:/project/:projectId/compile', {
  9. status: 'success',
  10. pdfDownloadDomain: 'https://clsi.test-overleaf.com',
  11. outputFiles: [
  12. {
  13. path: 'output.pdf',
  14. build: 'build-123',
  15. url: '/build/build-123/output.pdf',
  16. type: 'pdf',
  17. },
  18. ],
  19. })
  20. })
  21. afterEach(function () {
  22. fetchMock.removeRoutes().clearHistory()
  23. })
  24. it('shows correct menu for non-anonymous users', async function () {
  25. window.metaAttributesCache.set('ol-anonymous', false)
  26. renderWithEditorContext(<ActionsMenu />, {
  27. projectId: '123abc',
  28. scope: {
  29. editor: {
  30. sharejs_doc: {
  31. doc_id: 'test-doc',
  32. getSnapshot: () => 'some doc content',
  33. },
  34. },
  35. },
  36. })
  37. screen.getByText('Actions')
  38. screen.getByRole('button', {
  39. name: 'Copy project',
  40. })
  41. await waitFor(() => {
  42. screen.getByRole('button', {
  43. name: 'Word Count',
  44. })
  45. })
  46. })
  47. it('does not show anything for anonymous users', async function () {
  48. window.metaAttributesCache.set('ol-anonymous', true)
  49. renderWithEditorContext(<ActionsMenu />, {
  50. projectId: '123abc',
  51. scope: {
  52. editor: {
  53. sharejs_doc: {
  54. doc_id: 'test-doc',
  55. getSnapshot: () => 'some doc content',
  56. },
  57. },
  58. },
  59. })
  60. expect(screen.queryByText('Actions')).to.equal(null)
  61. expect(
  62. screen.queryByRole('button', {
  63. name: 'Copy project',
  64. })
  65. ).to.equal(null)
  66. await waitFor(() => {
  67. expect(
  68. screen.queryByRole('button', {
  69. name: 'Word Count',
  70. })
  71. ).to.equal(null)
  72. })
  73. })
  74. })