actions-menu.test.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. mockCompileOnLoad: true,
  29. scope: {
  30. editor: {
  31. sharejs_doc: {
  32. doc_id: 'test-doc',
  33. getSnapshot: () => 'some doc content',
  34. },
  35. },
  36. },
  37. })
  38. screen.getByText('Actions')
  39. screen.getByRole('button', {
  40. name: 'Copy project',
  41. })
  42. await waitFor(() => {
  43. screen.getByRole('button', {
  44. name: 'Word Count',
  45. })
  46. })
  47. })
  48. it('does not show anything for anonymous users', async function () {
  49. window.metaAttributesCache.set('ol-anonymous', true)
  50. renderWithEditorContext(<ActionsMenu />, {
  51. projectId: '123abc',
  52. mockCompileOnLoad: true,
  53. scope: {
  54. editor: {
  55. sharejs_doc: {
  56. doc_id: 'test-doc',
  57. getSnapshot: () => 'some doc content',
  58. },
  59. },
  60. },
  61. })
  62. expect(screen.queryByText('Actions')).to.equal(null)
  63. expect(
  64. screen.queryByRole('button', {
  65. name: 'Copy project',
  66. })
  67. ).to.equal(null)
  68. await waitFor(() => {
  69. expect(
  70. screen.queryByRole('button', {
  71. name: 'Word Count',
  72. })
  73. ).to.equal(null)
  74. })
  75. })
  76. })