chat.cy.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // eslint-disable-next-line @typescript-eslint/triple-slash-reference
  2. /// <reference path="../support/index.d.ts" />
  3. // These tests run through the chat flow.
  4. describe('Settings', () => {
  5. // Wait for 2 seconds after all tests to fix an issue with Cypress's video recording missing the last few frames
  6. after(() => {
  7. // eslint-disable-next-line cypress/no-unnecessary-waiting
  8. cy.wait(2000);
  9. });
  10. beforeEach(() => {
  11. // Login as the admin user
  12. cy.loginAdmin();
  13. // Visit the home page
  14. cy.visit('/');
  15. });
  16. context('Ollama', () => {
  17. it('user can select a model', () => {
  18. // Click on the model selector
  19. cy.get('button[aria-label="Select a model"]').click();
  20. // Select the first model
  21. cy.get('button[aria-label="model-item"]').first().click();
  22. });
  23. it('user can perform text chat', () => {
  24. // Click on the model selector
  25. cy.get('button[aria-label="Select a model"]').click();
  26. // Select the first model
  27. cy.get('button[aria-label="model-item"]').first().click();
  28. // Type a message
  29. cy.get('#chat-textarea').type('Hi, what can you do? A single sentence only please.', {
  30. force: true
  31. });
  32. // Send the message
  33. cy.get('button[type="submit"]').click();
  34. // User's message should be visible
  35. cy.get('.chat-user').should('exist');
  36. // Wait for the response
  37. cy.get('.chat-assistant', { timeout: 120_000 }) // .chat-assistant is created after the first token is received
  38. .find('div[aria-label="Generation Info"]', { timeout: 120_000 }) // Generation Info is created after the stop token is received
  39. .should('exist');
  40. });
  41. it('user can share chat', () => {
  42. // Click on the model selector
  43. cy.get('button[aria-label="Select a model"]').click();
  44. // Select the first model
  45. cy.get('button[aria-label="model-item"]').first().click();
  46. // Type a message
  47. cy.get('#chat-textarea').type('Hi, what can you do? A single sentence only please.', {
  48. force: true
  49. });
  50. // Send the message
  51. cy.get('button[type="submit"]').click();
  52. // User's message should be visible
  53. cy.get('.chat-user').should('exist');
  54. // Wait for the response
  55. cy.get('.chat-assistant', { timeout: 120_000 }) // .chat-assistant is created after the first token is received
  56. .find('div[aria-label="Generation Info"]', { timeout: 120_000 }) // Generation Info is created after the stop token is received
  57. .should('exist');
  58. // spy on requests
  59. const spy = cy.spy();
  60. cy.intercept('GET', '/api/v1/chats/*', spy);
  61. // Open context menu
  62. cy.get('#chat-context-menu-button').click();
  63. // Click share button
  64. cy.get('#chat-share-button').click();
  65. // Check if the share dialog is visible
  66. cy.get('#copy-and-share-chat-button').should('exist');
  67. cy.wrap({}, { timeout: 5000 }).should(() => {
  68. // Check if the request was made twice (once for to replace chat object and once more due to change event)
  69. expect(spy).to.be.callCount(2);
  70. });
  71. });
  72. });
  73. });