change-layout-button.spec.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import ChangeLayoutButton from '@/features/ide-react/components/toolbar/change-layout-button'
  2. import type { LayoutContextValue } from '@/shared/context/layout-context'
  3. import { EditorProviders } from '../../../../helpers/editor-providers'
  4. const mount = (layoutContext: Partial<LayoutContextValue>) => {
  5. cy.mount(
  6. <EditorProviders layoutContext={layoutContext}>
  7. <ChangeLayoutButton />
  8. </EditorProviders>
  9. )
  10. }
  11. describe('<ChangeLayoutButton />', function () {
  12. beforeEach(function () {
  13. cy.stub(window, 'open').as('openWindow')
  14. })
  15. describe('selecting a layout', function () {
  16. it('makes Split view active after clicking it', function () {
  17. mount({ pdfLayout: 'flat', view: 'editor', chatIsOpen: false })
  18. cy.findByRole('button', { name: 'Layout options' }).click()
  19. cy.findByRole('menuitem', { name: 'Split view' }).click()
  20. cy.findByRole('button', { name: 'Layout options' }).click()
  21. cy.findByRole('menuitem', { name: 'Split view' }).should(
  22. 'have.attr',
  23. 'aria-current',
  24. 'true'
  25. )
  26. cy.findByRole('menuitem', { name: 'Editor only' }).should(
  27. 'have.attr',
  28. 'aria-current',
  29. 'false'
  30. )
  31. cy.findByRole('menuitem', { name: 'PDF only' }).should(
  32. 'have.attr',
  33. 'aria-current',
  34. 'false'
  35. )
  36. })
  37. it('makes Editor only active after clicking it', function () {
  38. mount({ pdfLayout: 'sideBySide', view: 'editor', chatIsOpen: false })
  39. cy.findByRole('button', { name: 'Layout options' }).click()
  40. cy.findByRole('menuitem', { name: 'Editor only' }).click()
  41. cy.findByRole('button', { name: 'Layout options' }).click()
  42. cy.findByRole('menuitem', { name: 'Editor only' }).should(
  43. 'have.attr',
  44. 'aria-current',
  45. 'true'
  46. )
  47. cy.findByRole('menuitem', { name: 'Split view' }).should(
  48. 'have.attr',
  49. 'aria-current',
  50. 'false'
  51. )
  52. cy.findByRole('menuitem', { name: 'PDF only' }).should(
  53. 'have.attr',
  54. 'aria-current',
  55. 'false'
  56. )
  57. })
  58. it('makes PDF only active after clicking it', function () {
  59. mount({ pdfLayout: 'sideBySide', view: 'editor', chatIsOpen: false })
  60. cy.findByRole('button', { name: 'Layout options' }).click()
  61. cy.findByRole('menuitem', { name: 'PDF only' }).click()
  62. cy.findByRole('button', { name: 'Layout options' }).click()
  63. cy.findByRole('menuitem', { name: 'PDF only' }).should(
  64. 'have.attr',
  65. 'aria-current',
  66. 'true'
  67. )
  68. cy.findByRole('menuitem', { name: 'Editor only' }).should(
  69. 'have.attr',
  70. 'aria-current',
  71. 'false'
  72. )
  73. cy.findByRole('menuitem', { name: 'Split view' }).should(
  74. 'have.attr',
  75. 'aria-current',
  76. 'false'
  77. )
  78. })
  79. it('treats file view the same as editor view', function () {
  80. // the 'file' view cannot be reached by clicking a layout option, so
  81. // verify the active state directly from the initial context
  82. mount({ pdfLayout: 'flat', view: 'file', chatIsOpen: false })
  83. cy.findByRole('button', { name: 'Layout options' }).click()
  84. cy.findByRole('menuitem', { name: 'Editor only' }).should(
  85. 'have.attr',
  86. 'aria-current',
  87. 'true'
  88. )
  89. })
  90. it('marks no item as active in history view', function () {
  91. // the 'history' view is entered via the history toggle (not this menu),
  92. // so verify the active state directly from the initial context
  93. mount({ pdfLayout: 'flat', view: 'history', chatIsOpen: false })
  94. cy.findByRole('button', { name: 'Layout options' }).click()
  95. cy.findByRole('menuitem', { name: 'Split view' }).should(
  96. 'have.attr',
  97. 'aria-current',
  98. 'false'
  99. )
  100. cy.findByRole('menuitem', { name: 'Editor only' }).should(
  101. 'have.attr',
  102. 'aria-current',
  103. 'false'
  104. )
  105. cy.findByRole('menuitem', { name: 'PDF only' }).should(
  106. 'have.attr',
  107. 'aria-current',
  108. 'false'
  109. )
  110. cy.findByRole('menuitem', { name: 'Open PDF in separate tab' }).should(
  111. 'have.attr',
  112. 'aria-current',
  113. 'false'
  114. )
  115. })
  116. })
  117. describe('on detach', function () {
  118. beforeEach(function () {
  119. mount({ pdfLayout: 'flat', view: 'editor', chatIsOpen: false })
  120. cy.findByRole('button', { name: 'Layout options' }).click()
  121. cy.findByRole('menuitem', { name: 'Open PDF in separate tab' }).click()
  122. })
  123. it('opens a detached window', function () {
  124. cy.get('@openWindow').should(
  125. 'have.been.calledWith',
  126. Cypress.sinon.match(/\/detached/),
  127. '_blank'
  128. )
  129. })
  130. it('shows processing state while waiting for the detached tab', function () {
  131. cy.findByRole('button', { name: 'Layout options' }).click()
  132. cy.findByRole('menuitem', { name: 'Open PDF in separate tab' })
  133. .findByTestId('ol-spinner')
  134. .should('exist')
  135. })
  136. })
  137. describe('on layout change while detacher', function () {
  138. beforeEach(function () {
  139. window.metaAttributesCache.set('ol-detachRole', 'detacher')
  140. mount({ pdfLayout: 'flat', view: 'editor', chatIsOpen: false })
  141. cy.findByRole('button', { name: 'Layout options' }).click()
  142. cy.findByRole('menuitem', { name: 'Editor only' }).click()
  143. })
  144. it('marks the newly selected item as active', function () {
  145. cy.findByRole('button', { name: 'Layout options' }).click()
  146. cy.findByRole('menuitem', { name: 'Editor only' }).should(
  147. 'have.attr',
  148. 'aria-current',
  149. 'true'
  150. )
  151. })
  152. })
  153. })