chat.cy.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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-input').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. // .chat-assistant is created after the first token is received
  38. cy.get('.chat-assistant', { timeout: 10_000 }).should('exist');
  39. // Generation Info is created after the stop token is received
  40. cy.get('div[aria-label="Generation Info"]', { timeout: 120_000 }).should('exist');
  41. });
  42. it('user can share chat', () => {
  43. // Click on the model selector
  44. cy.get('button[aria-label="Select a model"]').click();
  45. // Select the first model
  46. cy.get('button[aria-label="model-item"]').first().click();
  47. // Type a message
  48. cy.get('#chat-input').type('Hi, what can you do? A single sentence only please.', {
  49. force: true
  50. });
  51. // Send the message
  52. cy.get('button[type="submit"]').click();
  53. // User's message should be visible
  54. cy.get('.chat-user').should('exist');
  55. // Wait for the response
  56. // .chat-assistant is created after the first token is received
  57. cy.get('.chat-assistant', { timeout: 10_000 }).should('exist');
  58. // Generation Info is created after the stop token is received
  59. cy.get('div[aria-label="Generation Info"]', { timeout: 120_000 }).should('exist');
  60. // spy on requests
  61. const spy = cy.spy();
  62. cy.intercept('POST', '/api/v1/chats/**/share', spy);
  63. // Open context menu
  64. cy.get('#chat-context-menu-button').click();
  65. // Click share button
  66. cy.get('#chat-share-button').click();
  67. // Check if the share dialog is visible
  68. cy.get('#copy-and-share-chat-button').should('exist');
  69. // Click the copy button
  70. cy.get('#copy-and-share-chat-button').click();
  71. cy.wrap({}, { timeout: 5_000 }).should(() => {
  72. // Check if the share request was made
  73. expect(spy).to.be.callCount(1);
  74. });
  75. });
  76. it('user can generate image', () => {
  77. // Click on the model selector
  78. cy.get('button[aria-label="Select a model"]').click();
  79. // Select the first model
  80. cy.get('button[aria-label="model-item"]').first().click();
  81. // Type a message
  82. cy.get('#chat-input').type('Hi, what can you do? A single sentence only please.', {
  83. force: true
  84. });
  85. // Send the message
  86. cy.get('button[type="submit"]').click();
  87. // User's message should be visible
  88. cy.get('.chat-user').should('exist');
  89. // Wait for the response
  90. // .chat-assistant is created after the first token is received
  91. cy.get('.chat-assistant', { timeout: 10_000 }).should('exist');
  92. // Generation Info is created after the stop token is received
  93. cy.get('div[aria-label="Generation Info"]', { timeout: 120_000 }).should('exist');
  94. // Click on the generate image button
  95. cy.get('[aria-label="Generate Image"]').click();
  96. // Wait for image to be visible
  97. cy.get('img[data-cy="image"]', { timeout: 60_000 }).should('be.visible');
  98. });
  99. });
  100. });