chat.spec.tsx 4.3 KB

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