|
| 1 | +import { |
| 2 | + CODE_REVIEW_CONTAINER_CYPRESS, |
| 3 | + COMMENT_CONTAINER_CYPRESS, |
| 4 | + COMMENT_EDITOR_SAVE_BUTTON_CYPRESS, |
| 5 | + COMMENT_EDITOR_TEXTAREA_CYPRESS, |
| 6 | + COMMENT_RESPONSE_BOX_CY, |
| 7 | + buildChatbotPromptContainerDataCy, |
| 8 | + buildCommentContainerDataCy, |
| 9 | + buildCommentResponseBoxDataCy, |
| 10 | + buildDataCy, |
| 11 | +} from '../../../src/config/selectors'; |
| 12 | +import { CHATBOT_THREAD_MOCK_COMMENTS } from '../../fixtures/appData'; |
| 13 | +import { |
| 14 | + CODE_REVIEW_MODE_SETTING, |
| 15 | + MOCK_CHATBOT_PROMPT_SETTINGS_INPUT, |
| 16 | + MOCK_CODE_SETTINGS, |
| 17 | +} from '../../fixtures/appSettings'; |
| 18 | + |
| 19 | +describe('OpenAI api chatbot', () => { |
| 20 | + describe('no previous interactions', () => { |
| 21 | + beforeEach(() => { |
| 22 | + cy.setUpApi({ |
| 23 | + database: { |
| 24 | + appSettings: [ |
| 25 | + // set the view to "code-review" mode |
| 26 | + CODE_REVIEW_MODE_SETTING, |
| 27 | + // set some code |
| 28 | + MOCK_CODE_SETTINGS, |
| 29 | + // chatbot prompt setting |
| 30 | + MOCK_CHATBOT_PROMPT_SETTINGS_INPUT, |
| 31 | + ], |
| 32 | + }, |
| 33 | + }); |
| 34 | + cy.visit('/'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('show a ghost comment', () => { |
| 38 | + cy.get(buildDataCy(CODE_REVIEW_CONTAINER_CYPRESS)).should('be.visible'); |
| 39 | + |
| 40 | + // check that the bot comment is shown |
| 41 | + cy.get( |
| 42 | + buildDataCy( |
| 43 | + buildChatbotPromptContainerDataCy( |
| 44 | + MOCK_CHATBOT_PROMPT_SETTINGS_INPUT.id, |
| 45 | + ), |
| 46 | + ), |
| 47 | + ).should('be.visible'); |
| 48 | + |
| 49 | + // click on the response box |
| 50 | + cy.get( |
| 51 | + buildDataCy( |
| 52 | + buildCommentResponseBoxDataCy(MOCK_CHATBOT_PROMPT_SETTINGS_INPUT.id), |
| 53 | + ), |
| 54 | + ).click(); |
| 55 | + |
| 56 | + cy.get(buildDataCy(COMMENT_EDITOR_TEXTAREA_CYPRESS)).type( |
| 57 | + 'hello chatbot how are you ?', |
| 58 | + ); |
| 59 | + |
| 60 | + cy.get(buildDataCy(COMMENT_EDITOR_SAVE_BUTTON_CYPRESS)).click(); |
| 61 | + |
| 62 | + // wait for chatbot response to come |
| 63 | + cy.get(`[data-cy^=${COMMENT_CONTAINER_CYPRESS}]`).should( |
| 64 | + 'have.length', |
| 65 | + 3, |
| 66 | + ); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + describe('with previous interaction', () => { |
| 71 | + beforeEach(() => { |
| 72 | + cy.setUpApi({ |
| 73 | + database: { |
| 74 | + appSettings: [ |
| 75 | + // set the view to "code-review" mode |
| 76 | + CODE_REVIEW_MODE_SETTING, |
| 77 | + // set some code |
| 78 | + MOCK_CODE_SETTINGS, |
| 79 | + // chatbot prompt setting |
| 80 | + MOCK_CHATBOT_PROMPT_SETTINGS_INPUT, |
| 81 | + ], |
| 82 | + appData: [ |
| 83 | + // chatbot thread |
| 84 | + ...CHATBOT_THREAD_MOCK_COMMENTS, |
| 85 | + ], |
| 86 | + }, |
| 87 | + }); |
| 88 | + cy.visit('/'); |
| 89 | + }); |
| 90 | + |
| 91 | + it('show chatbot thread', () => { |
| 92 | + cy.get(buildDataCy(CODE_REVIEW_CONTAINER_CYPRESS)).should('be.visible'); |
| 93 | + |
| 94 | + // check that the first comment is displayed |
| 95 | + cy.get( |
| 96 | + buildDataCy( |
| 97 | + buildCommentContainerDataCy(CHATBOT_THREAD_MOCK_COMMENTS[0].id), |
| 98 | + ), |
| 99 | + ).should('be.visible'); |
| 100 | + cy.get(buildDataCy(COMMENT_RESPONSE_BOX_CY)).click(); |
| 101 | + cy.get(buildDataCy(COMMENT_EDITOR_TEXTAREA_CYPRESS)).type('test'); |
| 102 | + cy.get(buildDataCy(COMMENT_EDITOR_SAVE_BUTTON_CYPRESS)).click(); |
| 103 | + }); |
| 104 | + }); |
| 105 | +}); |
0 commit comments