chat.spec.tsx 4.3 KB

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