toolbar-header.test.jsx 3.5 KB

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