mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
152 lines
5.3 KiB
TypeScript
152 lines
5.3 KiB
TypeScript
import { render } from '@testing-library/vue';
|
||
import AskAssistantChat from '../AskAssistantChat.vue';
|
||
|
||
describe('AskAssistantChat', () => {
|
||
it('renders default placeholder chat correctly', () => {
|
||
const { container } = render(AskAssistantChat, {
|
||
props: {
|
||
user: { firstName: 'Kobi', lastName: 'Dog' },
|
||
},
|
||
});
|
||
expect(container).toMatchSnapshot();
|
||
});
|
||
it('renders chat with messages correctly', () => {
|
||
const { container } = render(AskAssistantChat, {
|
||
props: {
|
||
user: { firstName: 'Kobi', lastName: 'Dog' },
|
||
messages: [
|
||
{
|
||
id: '1',
|
||
type: 'text',
|
||
role: 'assistant',
|
||
content:
|
||
'Hi Max! Here is my top solution to fix the error in your **Transform data** node👇',
|
||
read: false,
|
||
},
|
||
{
|
||
id: '1',
|
||
type: 'code-diff',
|
||
role: 'assistant',
|
||
description: 'Short solution description here that can spill over to two lines',
|
||
codeDiff:
|
||
'@@ -1,7 +1,6 @@\n-The Way that can be told of is not the eternal Way;\n-The name that can be named is not the eternal name.\nThe Nameless is the origin of Heaven and Earth;\n-The Named is the mother of all things.\n+The named is the mother of all things.\n+\nTherefore let there always be non-being,\nso we may see their subtlety,\nAnd let there always be being,\n@@ -9,3 +8,6 @@\n The two are the same,\n But after they are produced,\n they have different names.\n+They both may be called deep and profound.\n+Deeper and more profound,\n+The door of all subtleties!',
|
||
suggestionId: 'test',
|
||
quickReplies: [
|
||
{
|
||
type: 'new-suggestion',
|
||
text: 'Give me another solution',
|
||
},
|
||
{
|
||
type: 'resolved',
|
||
text: 'All good',
|
||
},
|
||
],
|
||
read: false,
|
||
},
|
||
{
|
||
id: '2',
|
||
type: 'text',
|
||
role: 'user',
|
||
content: 'Give it to me **ignore this markdown**',
|
||
read: false,
|
||
},
|
||
{
|
||
id: '2',
|
||
type: 'block',
|
||
role: 'assistant',
|
||
title: 'Credential doesn’t have correct permissions to send a message',
|
||
content:
|
||
'Solution steps:\n1. Lorem ipsum dolor sit amet, consectetur **adipiscing** elit. Proin id nulla placerat, tristique ex at, euismod dui.\n2. Copy this into somewhere\n3. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin id nulla placerat, tristique ex at, euismod dui.\n4. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin id nulla placerat, tristique ex at, euismod dui. \n Testing more code \n - Unordered item 1 \n - Unordered item 2',
|
||
read: false,
|
||
},
|
||
{
|
||
id: '2',
|
||
type: 'code-diff',
|
||
role: 'assistant',
|
||
description: 'Short solution with min height',
|
||
codeDiff:
|
||
'@@ -1,7 +1,6 @@\n-The Way that can be told of is not the eternal Way;\n-The name that can be named is not the eternal name.\n+The door of all subtleties!',
|
||
quickReplies: [
|
||
{
|
||
type: 'new-suggestion',
|
||
text: 'Give me another solution',
|
||
},
|
||
{
|
||
type: 'resolved',
|
||
text: 'All good',
|
||
},
|
||
],
|
||
suggestionId: 'test',
|
||
read: false,
|
||
},
|
||
],
|
||
},
|
||
});
|
||
expect(container).toMatchSnapshot();
|
||
});
|
||
it('renders streaming chat correctly', () => {
|
||
const { container } = render(AskAssistantChat, {
|
||
props: {
|
||
user: { firstName: 'Kobi', lastName: 'Dog' },
|
||
messages: [
|
||
{
|
||
id: '1',
|
||
type: 'text',
|
||
role: 'assistant',
|
||
content:
|
||
'Hi Max! Here is my top solution to fix the error in your **Transform data** node👇',
|
||
read: false,
|
||
},
|
||
],
|
||
isStreaming: true,
|
||
},
|
||
});
|
||
expect(container).toMatchSnapshot();
|
||
});
|
||
it('renders end of session chat correctly', () => {
|
||
const { container } = render(AskAssistantChat, {
|
||
props: {
|
||
user: { firstName: 'Kobi', lastName: 'Dog' },
|
||
messages: [
|
||
{
|
||
id: '1',
|
||
type: 'text',
|
||
role: 'assistant',
|
||
content:
|
||
'Hi Max! Here is my top solution to fix the error in your **Transform data** node👇',
|
||
read: false,
|
||
},
|
||
{
|
||
id: '123',
|
||
role: 'assistant',
|
||
type: 'event',
|
||
eventName: 'end-session',
|
||
read: false,
|
||
},
|
||
],
|
||
},
|
||
});
|
||
expect(container).toMatchSnapshot();
|
||
});
|
||
it('renders message with code snippet', () => {
|
||
const { container } = render(AskAssistantChat, {
|
||
props: {
|
||
user: { firstName: 'Kobi', lastName: 'Dog' },
|
||
messages: [
|
||
{
|
||
id: '1',
|
||
type: 'text',
|
||
role: 'assistant',
|
||
content:
|
||
'Hi Max! Here is my top solution to fix the error in your **Transform data** node👇',
|
||
codeSnippet:
|
||
"node.on('input', function(msg) {\n if (msg.seed) { dummyjson.seed = msg.seed; }\n try {\n var value = dummyjson.parse(node.template, {mockdata: msg});\n if (node.syntax === 'json') {\n try { value = JSON.parse(value); }\n catch(e) { node.error(RED._('datagen.errors.json-error')); }\n }\n if (node.fieldType === 'msg') {\n RED.util.setMessageProperty(msg,node.field,value);\n }\n else if (node.fieldType === 'flow') {\n node.context().flow.set(node.field,value);\n }\n else if (node.fieldType === 'global') {\n node.context().global.set(node.field,value);\n }\n node.send(msg);\n }\n catch(e) {",
|
||
read: false,
|
||
},
|
||
],
|
||
},
|
||
});
|
||
expect(container).toMatchSnapshot();
|
||
});
|
||
});
|