toolbar-header.test.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. })
  29. describe('cobranding logo', function () {
  30. it('is not displayed by default', function () {
  31. renderWithEditorContext(<ToolbarHeader {...defaultProps} />)
  32. expect(screen.queryByRole('link', { name: 'variation' })).to.not.exist
  33. })
  34. it('is displayed when cobranding data is available', function () {
  35. const props = {
  36. ...defaultProps,
  37. cobranding: {
  38. brandVariationHomeUrl: 'http://cobranding',
  39. brandVariationName: 'variation',
  40. logoImgUrl: 'http://cobranding/logo',
  41. },
  42. }
  43. renderWithEditorContext(<ToolbarHeader {...props} />)
  44. screen.getByRole('link', { name: 'variation' })
  45. })
  46. })
  47. describe('track changes toggle button', function () {
  48. it('is displayed by default', function () {
  49. renderWithEditorContext(<ToolbarHeader {...defaultProps} />)
  50. screen.getByText('Review')
  51. })
  52. it('is not displayed when "trackChangesVisible" prop is set to false', function () {
  53. const props = {
  54. ...defaultProps,
  55. trackChangesVisible: false,
  56. }
  57. renderWithEditorContext(<ToolbarHeader {...props} />)
  58. expect(screen.queryByText('Review')).to.not.exist
  59. })
  60. })
  61. describe('History toggle button', function () {
  62. it('is displayed by default', function () {
  63. renderWithEditorContext(<ToolbarHeader {...defaultProps} />)
  64. screen.getByText('History')
  65. })
  66. it('is not displayed when "isRestrictedTokenMember" prop is set to true', function () {
  67. const props = {
  68. ...defaultProps,
  69. isRestrictedTokenMember: true,
  70. }
  71. renderWithEditorContext(<ToolbarHeader {...props} />)
  72. expect(screen.queryByText('History')).to.not.exist
  73. })
  74. })
  75. describe('Chat toggle button', function () {
  76. it('is displayed by default', function () {
  77. renderWithEditorContext(<ToolbarHeader {...defaultProps} />)
  78. screen.getByText('Chat')
  79. })
  80. it('is not displayed when "chatVisible" prop is set to false', function () {
  81. const props = {
  82. ...defaultProps,
  83. chatVisible: false,
  84. }
  85. renderWithEditorContext(<ToolbarHeader {...props} />)
  86. expect(screen.queryByText('Chat')).to.not.exist
  87. })
  88. })
  89. describe('Publish button', function () {
  90. it('is displayed by default', function () {
  91. renderWithEditorContext(<ToolbarHeader {...defaultProps} />)
  92. screen.getByText('Submit')
  93. })
  94. it('is not displayed for users with no publish permissions', function () {
  95. const props = {
  96. ...defaultProps,
  97. hasPublishPermissions: false,
  98. }
  99. renderWithEditorContext(<ToolbarHeader {...props} />)
  100. expect(screen.queryByText('Submit')).to.not.exist
  101. })
  102. })
  103. })