toolbar-header.test.tsx 3.7 KB

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