actions-menu.test.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { screen, waitFor } from '@testing-library/dom'
  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.reset()
  23. window.metaAttributesCache = new Map()
  24. })
  25. it('shows correct menu for non-anonymous users', async function () {
  26. window.metaAttributesCache.set('ol-anonymous', false)
  27. renderWithEditorContext(<ActionsMenu />, {
  28. projectId: '123abc',
  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. scope: {
  53. editor: {
  54. sharejs_doc: {
  55. doc_id: 'test-doc',
  56. getSnapshot: () => 'some doc content',
  57. },
  58. },
  59. },
  60. })
  61. expect(screen.queryByText('Actions')).to.equal(null)
  62. expect(
  63. screen.queryByRole('button', {
  64. name: 'Copy Project',
  65. })
  66. ).to.equal(null)
  67. await waitFor(() => {
  68. expect(
  69. screen.queryByRole('button', {
  70. name: 'Word Count',
  71. })
  72. ).to.equal(null)
  73. })
  74. })
  75. })