@quidgest/chatbot 0.5.0 → 0.5.3-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/dist/components/ChatBot/ChatBot.vue.d.ts +2 -0
- package/dist/components/ChatBot/types.d.ts +2 -1
- package/dist/components/ChatBotInput/ChatBotInput.vue.d.ts +2 -2
- package/dist/components/ChatBotInput/__tests__/ChatBotInput.spec.d.ts +1 -0
- package/dist/components/ChatBotMessage/ChatBotMessage.vue.d.ts +3 -1
- package/dist/components/ChatBotMessage/__tests__/ChatBotMessageButtons.spec.d.ts +1 -0
- package/dist/components/ChatToolBar/__tests__/ChatToolBar.spec.d.ts +1 -0
- package/dist/components/FieldPreview/FieldPreview.vue.d.ts +2 -0
- package/dist/components/FieldPreview/__tests__/FieldPreview.spec.d.ts +1 -0
- package/dist/components/MarkdownRender/__tests__/MarkdownRender.spec.d.ts +1 -0
- package/dist/components/PulseDots/__tests__/PulseDots.spec.d.ts +1 -0
- package/dist/composables/__tests__/useChatMessages.spec.d.ts +1 -0
- package/dist/composables/__tests__/useSSE.spec.d.ts +1 -0
- package/dist/composables/useChatApi.d.ts +1 -1
- package/dist/composables/useChatMessages.d.ts +2 -1
- package/dist/composables/useSSE.d.ts +1 -2
- package/dist/composables/useTexts.d.ts +5 -0
- package/dist/index.js +25 -25
- package/dist/index.mjs +2317 -1810
- package/dist/style.css +1 -1
- package/dist/test/setup.d.ts +1 -0
- package/dist/utils/__tests__/parseFieldValue.spec.d.ts +1 -0
- package/package.json +28 -7
- package/src/assets/styles/styles.scss +212 -220
- package/src/components/ChatBot/ChatBot.vue +346 -370
- package/src/components/ChatBot/types.ts +34 -33
- package/src/components/ChatBotInput/ChatBotInput.vue +181 -190
- package/src/components/ChatBotInput/__tests__/ChatBotInput.spec.ts +292 -0
- package/src/components/ChatBotInput/__tests__/__snapshots__/ChatBotInput.spec.ts.snap +25 -0
- package/src/components/ChatBotInput/types.ts +24 -24
- package/src/components/ChatBotMessage/ChatBotMessage.vue +133 -134
- package/src/components/ChatBotMessage/ChatBotMessageButtons.vue +179 -164
- package/src/components/ChatBotMessage/__tests__/ChatBotMessageButtons.spec.ts +199 -0
- package/src/components/ChatBotMessage/__tests__/__snapshots__/ChatBotMessageButtons.spec.ts.snap +25 -0
- package/src/components/ChatBotMessage/types.ts +52 -52
- package/src/components/ChatToolBar/ChatToolBar.vue +69 -64
- package/src/components/ChatToolBar/__tests__/ChatToolBar.spec.ts +138 -0
- package/src/components/ChatToolBar/__tests__/__snapshots__/ChatToolBar.spec.ts.snap +11 -0
- package/src/components/ChatToolBar/types.ts +12 -12
- package/src/components/FieldPreview/FieldPreview.vue +83 -63
- package/src/components/FieldPreview/__tests__/FieldPreview.spec.ts +72 -0
- package/src/components/FieldPreview/__tests__/__snapshots__/FieldPreview.spec.ts.snap +19 -0
- package/src/components/FieldPreview/field-preview.scss +28 -24
- package/src/components/FieldPreview/types.ts +5 -5
- package/src/components/MarkdownRender/MarkdownRender.vue +16 -15
- package/src/components/MarkdownRender/__tests__/MarkdownRender.spec.ts +68 -0
- package/src/components/MarkdownRender/__tests__/__snapshots__/MarkdownRender.spec.ts.snap +8 -0
- package/src/components/MarkdownRender/markdown-render.scss +19 -20
- package/src/components/MarkdownRender/types.ts +3 -3
- package/src/components/PulseDots/PulseDots.vue +17 -17
- package/src/components/PulseDots/__tests__/PulseDots.spec.ts +35 -0
- package/src/components/PulseDots/__tests__/__snapshots__/PulseDots.spec.ts.snap +7 -0
- package/src/components/PulseDots/__tests__/__snapshots__/pulse-dots.spec.ts.snap +7 -0
- package/src/components/PulseDots/pulse-dots.scss +24 -23
- package/src/composables/__tests__/useChatMessages.spec.ts +64 -0
- package/src/composables/__tests__/useSSE.spec.ts +132 -0
- package/src/composables/useChatApi.ts +132 -134
- package/src/composables/useChatMessages.ts +50 -48
- package/src/composables/useSSE.ts +75 -73
- package/src/composables/useTexts.ts +33 -30
- package/src/test/setup.ts +41 -0
- package/src/utils/__tests__/parseFieldValue.spec.ts +27 -0
- package/src/utils/parseFieldValue.ts +12 -0
- package/src/utils/helper.ts +0 -12
- /package/dist/utils/{helper.d.ts → parseFieldValue.d.ts} +0 -0
|
@@ -1,169 +1,184 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
2
|
+
<q-dialog
|
|
3
|
+
v-model="showDialog"
|
|
4
|
+
inline
|
|
5
|
+
:buttons="commentButtons">
|
|
6
|
+
<template #body>
|
|
7
|
+
<div class="q-chatbot__dialog-title">
|
|
8
|
+
{{ texts.commentDialogTitle }}
|
|
9
|
+
</div>
|
|
10
|
+
<q-text-field
|
|
11
|
+
v-model="feedbackComment"
|
|
12
|
+
class="q-chatbot__dialog-comment-input"
|
|
13
|
+
:max-length="150"
|
|
14
|
+
size="large"
|
|
15
|
+
:placeholder="texts.commentPlaceholder" />
|
|
16
|
+
</template>
|
|
17
|
+
</q-dialog>
|
|
18
|
+
|
|
19
|
+
<div
|
|
20
|
+
v-if="showButtons"
|
|
21
|
+
class="q-chatbot__feedback-buttons">
|
|
22
|
+
<q-button-group>
|
|
23
|
+
<q-button
|
|
24
|
+
:title="texts.goodResponse"
|
|
25
|
+
class="q-chatbot__good-response-button"
|
|
26
|
+
borderless
|
|
27
|
+
:disabled="props.loading"
|
|
28
|
+
@click="handleGoodResponseClick">
|
|
29
|
+
<q-icon icon="thumb-up" />
|
|
30
|
+
</q-button>
|
|
31
|
+
<q-button
|
|
32
|
+
:title="texts.badResponse"
|
|
33
|
+
class="q-chatbot__bad-response-button"
|
|
34
|
+
borderless
|
|
35
|
+
:disabled="props.loading"
|
|
36
|
+
@click="handleBadResponseClick">
|
|
37
|
+
<q-icon icon="thumb-down" />
|
|
38
|
+
</q-button>
|
|
39
|
+
<q-button
|
|
40
|
+
:title="texts.copyResponse"
|
|
41
|
+
class="q-chatbot__copy-button"
|
|
42
|
+
borderless
|
|
43
|
+
:disabled="props.loading"
|
|
44
|
+
@click="copyResponse">
|
|
45
|
+
<q-icon icon="copy-content" />
|
|
46
|
+
</q-button>
|
|
47
|
+
<q-button
|
|
48
|
+
v-if="showApplyAll"
|
|
49
|
+
:title="texts.applyAll"
|
|
50
|
+
class="q-chatbot__apply-all-button"
|
|
51
|
+
borderless
|
|
52
|
+
:disabled="blockApplyAllButton"
|
|
53
|
+
:readonly="blockApplyAllButton"
|
|
54
|
+
@click="onApplyAll">
|
|
55
|
+
<q-icon icon="apply-all" />
|
|
56
|
+
</q-button>
|
|
57
|
+
</q-button-group>
|
|
58
|
+
</div>
|
|
59
|
+
<div class="q-chatbot__sender">
|
|
60
|
+
{{ messageDate }}
|
|
61
|
+
</div>
|
|
56
62
|
</template>
|
|
57
63
|
|
|
58
64
|
<script setup lang="ts">
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
65
|
+
import { computed, ref } from 'vue'
|
|
66
|
+
import { QDialog, QButtonGroup, QButton, QTextField, QIcon } from '@quidgest/ui/components'
|
|
67
|
+
import type { ChatBotMessageButtonsProps } from './'
|
|
68
|
+
|
|
69
|
+
// Composables
|
|
70
|
+
import { useTexts } from '@/composables/useTexts'
|
|
71
|
+
import { useChatMessages } from '@/composables/useChatMessages'
|
|
72
|
+
|
|
73
|
+
const props = defineProps<ChatBotMessageButtonsProps>()
|
|
74
|
+
const emit = defineEmits<{
|
|
75
|
+
(e: 'submit-feedback', feedback: number, comment: string): void
|
|
76
|
+
(e: 'copy-response'): void
|
|
77
|
+
(e: 'apply-all'): void
|
|
78
|
+
}>()
|
|
79
|
+
const texts = useTexts()
|
|
80
|
+
const { getLastMessage } = useChatMessages()
|
|
81
|
+
|
|
82
|
+
const showDialog = ref(false)
|
|
83
|
+
const feedbackComment = ref('')
|
|
84
|
+
const currentFeedback = ref<number | null>(null)
|
|
85
|
+
const blockApplyAll = ref(false)
|
|
86
|
+
const blockApplyAllButton = computed(() => {
|
|
87
|
+
return props.loading || blockApplyAll.value
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const date = props.date || new Date()
|
|
91
|
+
|
|
92
|
+
const lastMessage = getLastMessage()
|
|
93
|
+
|
|
94
|
+
const showApplyAll = computed(() => {
|
|
95
|
+
if (!lastMessage) return false
|
|
96
|
+
|
|
97
|
+
return lastMessage.fields && lastMessage.fields.length > 1
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
const commentButtons = [
|
|
101
|
+
{
|
|
102
|
+
id: 'confirm-btn',
|
|
103
|
+
action: submitFeedback,
|
|
104
|
+
props: {
|
|
105
|
+
label: texts.submitButton,
|
|
106
|
+
class: 'q-chatbot__dialog-confirm-button'
|
|
107
|
+
},
|
|
108
|
+
icon: {
|
|
109
|
+
icon: 'submit'
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
id: 'cancel-btn',
|
|
114
|
+
props: {
|
|
115
|
+
label: texts.cancelButton,
|
|
116
|
+
class: 'q-chatbot__dialog-cancel-button'
|
|
117
|
+
},
|
|
118
|
+
icon: {
|
|
119
|
+
icon: 'cancel'
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
|
|
124
|
+
const getLocaleDate = computed(() => {
|
|
125
|
+
if (!props.dateFormat) return date.toLocaleString()
|
|
126
|
+
|
|
127
|
+
return formatDate(date, 'HH:mm')
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
const messageDate = computed(() => {
|
|
131
|
+
return `${getLocaleDate.value}`
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
function formatDate(date: Date, format: string) {
|
|
135
|
+
const day = date.getDate().toString().padStart(2, '0')
|
|
136
|
+
const month = (date.getMonth() + 1).toString().padStart(2, '0')
|
|
137
|
+
const year = date.getFullYear().toString().padStart(2, '0')
|
|
138
|
+
const hours = date.getHours().toString().padStart(2, '0')
|
|
139
|
+
const minutes = date.getMinutes().toString().padStart(2, '0')
|
|
140
|
+
const seconds = date.getSeconds().toString().padStart(2, '0')
|
|
141
|
+
|
|
142
|
+
return format
|
|
143
|
+
.replace('dd', day)
|
|
144
|
+
.replace('MM', month)
|
|
145
|
+
.replace('yyyy', year)
|
|
146
|
+
.replace('HH', hours)
|
|
147
|
+
.replace('mm', minutes)
|
|
148
|
+
.replace('ss', seconds)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function openFeedbackDialog(feedback: number) {
|
|
152
|
+
showDialog.value = true
|
|
153
|
+
feedbackComment.value = ''
|
|
154
|
+
currentFeedback.value = feedback
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function handleBadResponseClick() {
|
|
158
|
+
openFeedbackDialog(0)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function handleGoodResponseClick() {
|
|
162
|
+
openFeedbackDialog(1)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function onApplyAll() {
|
|
166
|
+
if (blockApplyAll.value) return
|
|
167
|
+
blockApplyAll.value = true
|
|
168
|
+
|
|
169
|
+
emit('apply-all')
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function submitFeedback() {
|
|
173
|
+
if (!currentFeedback.value) return
|
|
174
|
+
|
|
175
|
+
emit('submit-feedback', currentFeedback.value, feedbackComment.value)
|
|
176
|
+
showDialog.value = false
|
|
177
|
+
feedbackComment.value = ''
|
|
178
|
+
currentFeedback.value = null
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function copyResponse() {
|
|
182
|
+
emit('copy-response')
|
|
183
|
+
}
|
|
169
184
|
</script>
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// Components
|
|
2
|
+
import { ChatBotMessageButtons } from '..'
|
|
3
|
+
|
|
4
|
+
// Utils
|
|
5
|
+
import { describe, expect, it, beforeEach, vi, afterEach } from 'vitest'
|
|
6
|
+
import { mount } from '@vue/test-utils'
|
|
7
|
+
import { useChatMessages } from '@/composables/useChatMessages'
|
|
8
|
+
|
|
9
|
+
// Types
|
|
10
|
+
import type { ChatBotMessageButtonsProps } from '..'
|
|
11
|
+
|
|
12
|
+
describe('ChatBotMessageButtons', () => {
|
|
13
|
+
const fixedDate = new Date('2025-01-01T11:47:00')
|
|
14
|
+
const { addChatMessage, clearMessages } = useChatMessages()
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
clearMessages()
|
|
18
|
+
|
|
19
|
+
vi.useFakeTimers()
|
|
20
|
+
vi.setSystemTime(fixedDate)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
vi.useRealTimers()
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const props: ChatBotMessageButtonsProps = {
|
|
28
|
+
loading: false,
|
|
29
|
+
showButtons: true,
|
|
30
|
+
dateFormat: 'MM/DD/YYYY',
|
|
31
|
+
date: fixedDate
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
it('renders correctly with default props', () => {
|
|
35
|
+
const wrapper = mount(ChatBotMessageButtons, { props })
|
|
36
|
+
|
|
37
|
+
expect(wrapper.html()).toMatchSnapshot()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('does not render buttons when showButtons is false', () => {
|
|
41
|
+
const wrapper = mount(ChatBotMessageButtons, {
|
|
42
|
+
props: { ...props, showButtons: false }
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const buttons = wrapper.find('.q-chatbot__feedback-buttons')
|
|
46
|
+
expect(buttons.exists()).toBe(false)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('sets loading state correctly to all buttons', () => {
|
|
50
|
+
const wrapper = mount(ChatBotMessageButtons, {
|
|
51
|
+
props: { ...props, loading: true }
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const buttons = wrapper.findAll('q.-chatbot__feedback-buttons button')
|
|
55
|
+
|
|
56
|
+
buttons.forEach((button) => {
|
|
57
|
+
expect(button.attributes('disabled')).toBeDefined()
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('sets the hour date on the bottom of the component', () => {
|
|
62
|
+
const testDate = new Date('2024-01-01T12:00:00Z')
|
|
63
|
+
const wrapper = mount(ChatBotMessageButtons, {
|
|
64
|
+
props: {
|
|
65
|
+
...props,
|
|
66
|
+
date: testDate
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const dateElement = wrapper.find('.q-chatbot__sender')
|
|
71
|
+
expect(dateElement.text()).toBe('12:00')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('emits the copy event when copy button is clicked', async () => {
|
|
75
|
+
const wrapper = mount(ChatBotMessageButtons, { props })
|
|
76
|
+
const copyButton = wrapper.find('.q-chatbot__copy-button')
|
|
77
|
+
|
|
78
|
+
await copyButton.trigger('click')
|
|
79
|
+
|
|
80
|
+
expect(wrapper.emitted()['copy-response']).toBeTruthy()
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('emits the apply-all event when apply all button is clicked', async () => {
|
|
84
|
+
// Add one message with fields to enable the button
|
|
85
|
+
const message = addChatMessage('Test message 1', 'bot')
|
|
86
|
+
|
|
87
|
+
message.fields = [
|
|
88
|
+
{ name: 'field1', text: 'value1', type: 'text', id: '1' },
|
|
89
|
+
{ name: 'field2', text: 'value2', type: 'text', id: '2' }
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
const wrapper = mount(ChatBotMessageButtons, {
|
|
93
|
+
props: { ...props, showButtons: true }
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
const applyAllButton = wrapper.find('.q-chatbot__apply-all-button')
|
|
97
|
+
await applyAllButton.trigger('click')
|
|
98
|
+
|
|
99
|
+
expect(wrapper.emitted()['apply-all']).toBeTruthy()
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('does not emit apply-all if the button has already been clicked', async () => {
|
|
103
|
+
// Add one message with fields to enable the button
|
|
104
|
+
const message = addChatMessage('Test message 1', 'bot')
|
|
105
|
+
|
|
106
|
+
message.fields = [
|
|
107
|
+
{ name: 'field1', text: 'value1', type: 'text', id: '1' },
|
|
108
|
+
{ name: 'field2', text: 'value2', type: 'text', id: '2' }
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
const wrapper = mount(ChatBotMessageButtons, {
|
|
112
|
+
props: { ...props, showButtons: true }
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
const applyAllButton = wrapper.find('.q-chatbot__apply-all-button')
|
|
116
|
+
await applyAllButton.trigger('click')
|
|
117
|
+
await applyAllButton.trigger('click') // Click again
|
|
118
|
+
|
|
119
|
+
expect(wrapper.emitted()['apply-all']).toBeTruthy()
|
|
120
|
+
expect(wrapper.emitted()['apply-all'].length).toBe(1) // Should only be emitted once
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('does not render apply all button if there is no message, and the message does not have fields', () => {
|
|
124
|
+
const wrapper = mount(ChatBotMessageButtons, {
|
|
125
|
+
props: { ...props, showButtons: true }
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
const applyAllButton = wrapper.find('.q-chatbot__apply-all-button')
|
|
129
|
+
expect(applyAllButton.exists()).toBe(false)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('opens the dialog when clicking the thumbs up button', async () => {
|
|
133
|
+
const wrapper = mount(ChatBotMessageButtons, {
|
|
134
|
+
props: { ...props, showButtons: true }
|
|
135
|
+
})
|
|
136
|
+
const goodResponseButton = wrapper.find('.q-chatbot__good-response-button')
|
|
137
|
+
await goodResponseButton.trigger('click')
|
|
138
|
+
|
|
139
|
+
const dialog = wrapper.findComponent({ name: 'QDialog' })
|
|
140
|
+
expect(dialog.exists()).toBe(true)
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('opens the dialog when clicking the thumbs down button', async () => {
|
|
144
|
+
const wrapper = mount(ChatBotMessageButtons, {
|
|
145
|
+
props: { ...props, showButtons: true }
|
|
146
|
+
})
|
|
147
|
+
const badResponseButton = wrapper.find('.q-chatbot__bad-response-button')
|
|
148
|
+
await badResponseButton.trigger('click')
|
|
149
|
+
|
|
150
|
+
const dialog = wrapper.findComponent({ name: 'QDialog' })
|
|
151
|
+
expect(dialog.exists()).toBe(true)
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('emits submit-feedback event with comment when submitting feedback', async () => {
|
|
155
|
+
const wrapper = mount(ChatBotMessageButtons, {
|
|
156
|
+
props: { ...props, showButtons: true }
|
|
157
|
+
})
|
|
158
|
+
const goodResponseButton = wrapper.find('.q-chatbot__good-response-button')
|
|
159
|
+
await goodResponseButton.trigger('click')
|
|
160
|
+
|
|
161
|
+
const dialog = wrapper.findComponent({ name: 'QDialog' })
|
|
162
|
+
expect(dialog.exists()).toBe(true)
|
|
163
|
+
|
|
164
|
+
const commentInput = dialog.find('input')
|
|
165
|
+
expect(commentInput.exists()).toBe(true)
|
|
166
|
+
await commentInput.setValue('Great response!')
|
|
167
|
+
|
|
168
|
+
const overlay = wrapper.find('.q-overlay__content')
|
|
169
|
+
const submitButton = overlay.find('.q-chatbot__dialog-confirm-button')
|
|
170
|
+
|
|
171
|
+
expect(submitButton.exists()).toBe(true)
|
|
172
|
+
await submitButton.trigger('click')
|
|
173
|
+
expect(wrapper.emitted()['submit-feedback']).toBeTruthy()
|
|
174
|
+
expect(wrapper.emitted()['submit-feedback'][0]).toEqual([1, 'Great response!'])
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
it('uses a default date if no date prop is provided', () => {
|
|
178
|
+
const wrapper = mount(ChatBotMessageButtons, {
|
|
179
|
+
props: { ...props, date: undefined }
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
const dateElement = wrapper.find('.q-chatbot__sender')
|
|
183
|
+
|
|
184
|
+
// The default date is the current date, so we just check if it renders something
|
|
185
|
+
expect(dateElement.text().length).toBeGreaterThan(0)
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
it('uses the current data format if no dateFormat prop is provided', () => {
|
|
189
|
+
const wrapper = mount(ChatBotMessageButtons, {
|
|
190
|
+
props: { ...props, dateFormat: '' }
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
const dateElement = wrapper.find('.q-chatbot__sender')
|
|
194
|
+
const expectedFormat = fixedDate.toLocaleString()
|
|
195
|
+
|
|
196
|
+
// The date should be in the current locale format
|
|
197
|
+
expect(dateElement.text()).toBe(expectedFormat)
|
|
198
|
+
})
|
|
199
|
+
})
|
package/src/components/ChatBotMessage/__tests__/__snapshots__/ChatBotMessageButtons.spec.ts.snap
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`ChatBotMessageButtons > renders correctly with default props 1`] = `
|
|
4
|
+
"<!--teleport start-->
|
|
5
|
+
<transition-stub name="fade" appear="true" persisted="false" css="true">
|
|
6
|
+
<!--v-if-->
|
|
7
|
+
</transition-stub>
|
|
8
|
+
<transition-stub name="fade" appear="true" persisted="false" css="true">
|
|
9
|
+
<!--v-if-->
|
|
10
|
+
</transition-stub>
|
|
11
|
+
<!--teleport end-->
|
|
12
|
+
<!--v-if-->
|
|
13
|
+
<div class="q-chatbot__feedback-buttons">
|
|
14
|
+
<div class="q-button-group" role="group"><button type="button" class="q-button q-button--outlined q-button--primary q-button--borderless q-chatbot__good-response-button" title="Good response">
|
|
15
|
+
<!--v-if--><span class="q-button__content"><span data-test="thumb-up"></span> </span>
|
|
16
|
+
</button><button type="button" class="q-button q-button--outlined q-button--primary q-button--borderless q-chatbot__bad-response-button" title="Bad response">
|
|
17
|
+
<!--v-if--><span class="q-button__content"><span data-test="thumb-down"></span> </span>
|
|
18
|
+
</button><button type="button" class="q-button q-button--outlined q-button--primary q-button--borderless q-chatbot__copy-button" title="Copy response">
|
|
19
|
+
<!--v-if--><span class="q-button__content"><span data-test="copy-content"></span> </span>
|
|
20
|
+
</button>
|
|
21
|
+
<!--v-if-->
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
<div class="q-chatbot__sender">11:47</div>"
|
|
25
|
+
`;
|