toolbar-header.test.jsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { expect } from 'chai'
  2. import { screen } from '@testing-library/react'
  3. import ToolbarHeader from '../../../../../frontend/js/features/editor-navigation-toolbar/components/toolbar-header'
  4. import { renderWithEditorContext } from '../../../helpers/render-with-context'
  5. describe('<ToolbarHeader />', function () {
  6. const defaultProps = {
  7. onShowLeftMenuClick: () => {},
  8. toggleChatOpen: () => {},
  9. toggleReviewPanelOpen: () => {},
  10. toggleHistoryOpen: () => {},
  11. unreadMessageCount: 0,
  12. onlineUsers: [],
  13. goToUser: () => {},
  14. projectName: 'test project',
  15. renameProject: () => {},
  16. openShareModal: () => {},
  17. hasPublishPermissions: true,
  18. chatVisible: true,
  19. trackChangesVisible: true,
  20. handleChangeLayout: () => {},
  21. pdfLayout: 'sideBySide',
  22. view: 'editor',
  23. reattach: () => {},
  24. detach: () => {},
  25. }
  26. beforeEach(function () {
  27. window.metaAttributesCache.set('ol-chatEnabled', true)
  28. window.metaAttributesCache.set('ol-preventCompileOnLoad', true)
  29. })
  30. describe('cobranding logo', function () {
  31. it('is not displayed by default', function () {
  32. renderWithEditorContext(<ToolbarHeader {...defaultProps} />)
  33. expect(screen.queryByRole('link', { name: 'variation' })).to.not.exist
  34. })
  35. it('is displayed when cobranding data is available', function () {
  36. const props = {
  37. ...defaultProps,
  38. cobranding: {
  39. brandVariationHomeUrl: 'http://cobranding',
  40. brandVariationName: 'variation',
  41. logoImgUrl: 'http://cobranding/logo',
  42. },
  43. }
  44. renderWithEditorContext(<ToolbarHeader {...props} />)
  45. screen.getByRole('link', { name: 'variation' })
  46. })
  47. })
  48. describe('track changes toggle button', function () {
  49. it('is displayed by default', function () {
  50. renderWithEditorContext(<ToolbarHeader {...defaultProps} />)
  51. screen.getByText('Review')
  52. })
  53. it('is not displayed when "trackChangesVisible" prop is set to false', function () {
  54. const props = {
  55. ...defaultProps,
  56. trackChangesVisible: false,
  57. }
  58. renderWithEditorContext(<ToolbarHeader {...props} />)
  59. expect(screen.queryByText('Review')).to.not.exist
  60. })
  61. })
  62. describe('History toggle button', function () {
  63. it('is displayed by default', function () {
  64. renderWithEditorContext(<ToolbarHeader {...defaultProps} />)
  65. screen.getByText('History')
  66. })
  67. it('is not displayed when "isRestrictedTokenMember" prop is set to true', function () {
  68. const props = {
  69. ...defaultProps,
  70. isRestrictedTokenMember: true,
  71. }
  72. renderWithEditorContext(<ToolbarHeader {...props} />)
  73. expect(screen.queryByText('History')).to.not.exist
  74. })
  75. })
  76. describe('Chat toggle button', function () {
  77. it('is displayed by default', function () {
  78. renderWithEditorContext(<ToolbarHeader {...defaultProps} />)
  79. screen.getByText('Chat')
  80. })
  81. it('is not displayed when "chatVisible" prop is set to false', function () {
  82. const props = {
  83. ...defaultProps,
  84. chatVisible: false,
  85. }
  86. renderWithEditorContext(<ToolbarHeader {...props} />)
  87. expect(screen.queryByText('Chat')).to.not.exist
  88. })
  89. })
  90. describe('Publish button', function () {
  91. it('is displayed by default', function () {
  92. renderWithEditorContext(<ToolbarHeader {...defaultProps} />)
  93. screen.getByText('Submit')
  94. })
  95. it('is not displayed for users with no publish permissions', function () {
  96. const props = {
  97. ...defaultProps,
  98. hasPublishPermissions: false,
  99. }
  100. renderWithEditorContext(<ToolbarHeader {...props} />)
  101. expect(screen.queryByText('Submit')).to.not.exist
  102. })
  103. })
  104. })