chat.spec.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { consentTutorialKey } from '@modules/workbench/frontend/js/components/chat'
  2. import Workbench from '@modules/workbench/frontend/js/components/workbench'
  3. import { EditorProviders } from '../../helpers/editor-providers'
  4. import { EditorView } from '@codemirror/view'
  5. import type { FC, PropsWithChildren } from 'react'
  6. import { EditorViewContext } from '@/features/ide-react/context/editor-view-context'
  7. import { TutorialProvider } from '@/shared/context/tutorial-context'
  8. describe('Workbench', { scrollBehavior: false }, function () {
  9. beforeEach(function () {
  10. cy.window().then(win => {
  11. win.metaAttributesCache.set('ol-showAiErrorAssistant', true)
  12. win.metaAttributesCache.set('ol-splitTestVariants', {
  13. 'ai-workbench-release': 'enabled',
  14. })
  15. win.metaAttributesCache.set('ol-inactiveTutorials', [consentTutorialKey])
  16. })
  17. })
  18. const EditorViewProvider: FC<React.PropsWithChildren> = ({ children }) => (
  19. <EditorViewContext.Provider
  20. value={{
  21. view: new EditorView(),
  22. setView: cy.stub(),
  23. }}
  24. >
  25. {children}
  26. </EditorViewContext.Provider>
  27. )
  28. const Providers: FC<PropsWithChildren<{ aiAssistEnabled?: boolean }>> = ({
  29. children,
  30. aiAssistEnabled = true,
  31. }) => {
  32. return (
  33. <EditorProviders
  34. features={{ aiErrorAssistant: aiAssistEnabled }}
  35. providers={{ EditorViewProvider, TutorialProvider }}
  36. >
  37. <div style={{ backgroundColor: '#1b222c' }}>{children}</div>
  38. </EditorProviders>
  39. )
  40. }
  41. describe('when AI assist is enabled and consent is given', function () {
  42. it('should show the chat interface', function () {
  43. cy.mount(
  44. <Providers aiAssistEnabled>
  45. <Workbench />
  46. </Providers>
  47. )
  48. cy.get('textarea').should('exist').and('be.visible')
  49. cy.get('.conversation-footer').should('not.have.attr', 'inert')
  50. cy.contains('Supporting your research').should('not.exist')
  51. cy.contains('Get early access').should('not.exist')
  52. cy.contains('AI can make mistakes').should('exist')
  53. })
  54. })
  55. describe('when AI assist is enabled but consent not yet given', function () {
  56. beforeEach(function () {
  57. cy.window().then(win => {
  58. win.metaAttributesCache.set('ol-inactiveTutorials', [])
  59. })
  60. cy.mount(
  61. <Providers aiAssistEnabled>
  62. <Workbench />
  63. </Providers>
  64. )
  65. })
  66. it('should show consent screen', function () {
  67. cy.get('.workbench-consent-prompt').should('exist')
  68. cy.contains('Supporting your research').should('be.visible')
  69. cy.findByRole('button', { name: /accept and continue/i }).should('exist')
  70. cy.contains('Get early access').should('not.exist')
  71. cy.get('.conversation-footer').should('have.attr', 'inert', 'true')
  72. })
  73. it('should hide consent and show chat after accepting', function () {
  74. cy.intercept('POST', '/user/tutorials/*', { statusCode: 204 }).as(
  75. 'completeTutorial'
  76. )
  77. cy.intercept('POST', '/tutorial/workbench-consent-release/complete', {
  78. statusCode: 205,
  79. }).as('completeConsentTutorial')
  80. cy.get('.workbench-consent-prompt').should('be.visible')
  81. cy.findByRole('button', { name: /accept and continue/i }).click()
  82. cy.wait('@completeConsentTutorial')
  83. cy.get('.workbench-consent-prompt').should('not.exist')
  84. })
  85. })
  86. describe('when AI assist is not enabled', function () {
  87. beforeEach(function () {
  88. cy.window().then(win => {
  89. win.metaAttributesCache.set('ol-showAiErrorAssistant', false)
  90. })
  91. cy.mount(
  92. <Providers aiAssistEnabled={false}>
  93. <Workbench />
  94. </Providers>
  95. )
  96. })
  97. it('should show upgrade notification', function () {
  98. cy.get('.workbench-upgrade-notification').should('exist')
  99. cy.contains('Get early access').should('be.visible')
  100. cy.findByRole('button', { name: /get ai assist/i }).should('exist')
  101. cy.get('.workbench-consent-prompt').should('not.exist')
  102. cy.get('.conversation-footer').should('have.attr', 'inert', 'true')
  103. })
  104. it('should dispatch paywall event when clicking upgrade button', function () {
  105. const paywallSpy = cy.spy().as('paywallSpy')
  106. cy.window().then(win => {
  107. win.addEventListener('aiAssist:showPaywall', paywallSpy)
  108. })
  109. cy.findByRole('button', { name: /get ai assist/i }).click()
  110. // Should dispatch the paywall event
  111. cy.get('@paywallSpy').should('have.been.calledOnce')
  112. })
  113. })
  114. })