chat.cy.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. it('user can generate image', () => {
  73. // Click on the model selector
  74. cy.get('button[aria-label="Select a model"]').click();
  75. // Select the first model
  76. cy.get('button[aria-label="model-item"]').first().click();
  77. // Type a message
  78. cy.get('#chat-textarea').type('Hi, what can you do? A single sentence only please.', {
  79. force: true
  80. });
  81. // Send the message
  82. cy.get('button[type="submit"]').click();
  83. // User's message should be visible
  84. cy.get('.chat-user').should('exist');
  85. // Wait for the response
  86. cy.get('.chat-assistant', { timeout: 120_000 }) // .chat-assistant is created after the first token is received
  87. .find('div[aria-label="Generation Info"]', { timeout: 120_000 }) // Generation Info is created after the stop token is received
  88. .should('exist');
  89. // Click on the generate image button
  90. cy.get('[aria-label="Generate Image"]').click();
  91. // Wait for image to be visible
  92. cy.get('img[data-cy="image"]', { timeout: 60_000 }).should('be.visible');
  93. });
  94. });
  95. });