-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-ozon-chat.js
More file actions
226 lines (187 loc) · 7.23 KB
/
test-ozon-chat.js
File metadata and controls
226 lines (187 loc) · 7.23 KB
1
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
56
57
58
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/* eslint-disable no-undef */
// Тестовый скрипт для создания чатов на странице Ozon
// Запускать в консоли DevTools
console.log('🛒 Тестирование чатов на странице Ozon...');
// Получаем текущий URL
const currentUrl = window.location.href;
console.log('📍 Текущий URL:', currentUrl);
// Функция для создания чата для ozon-analyzer
async function createOzonChat() {
try {
console.log('📝 Создание чата для ozon-analyzer...');
// Создаем чат
const chat = await chrome.runtime.sendMessage({
type: 'CREATE_PLUGIN_CHAT',
pluginId: 'ozon-analyzer',
pageKey: currentUrl,
});
console.log('✅ Чат создан:', chat);
// Сохраняем тестовое сообщение пользователя
const userMessage = {
role: 'user',
content: 'Проанализируй этот товар и расскажи о его характеристиках',
timestamp: Date.now(),
};
await chrome.runtime.sendMessage({
type: 'SAVE_PLUGIN_CHAT_MESSAGE',
pluginId: 'ozon-analyzer',
pageKey: currentUrl,
message: userMessage,
});
console.log('✅ Сообщение пользователя сохранено:', userMessage);
// Сохраняем ответ плагина
const pluginMessage = {
role: 'plugin',
content:
'Анализирую товар "Костюм спортивный North Dot"... Найдена информация о цене, характеристиках и отзывах.',
timestamp: Date.now(),
};
await chrome.runtime.sendMessage({
type: 'SAVE_PLUGIN_CHAT_MESSAGE',
pluginId: 'ozon-analyzer',
pageKey: currentUrl,
message: pluginMessage,
});
console.log('✅ Ответ плагина сохранен:', pluginMessage);
// Сохраняем черновик
await chrome.runtime.sendMessage({
type: 'SAVE_PLUGIN_CHAT_DRAFT',
pluginId: 'ozon-analyzer',
pageKey: currentUrl,
draftText: 'Хотите узнать больше о доставке или отзывах?',
});
console.log('✅ Черновик сохранен');
return true;
} catch (error) {
console.error('❌ Ошибка создания чата:', error);
return false;
}
}
// Функция для создания чата для test-chat-plugin
async function createTestPluginChat() {
try {
console.log('📝 Создание чата для test-chat-plugin...');
// Создаем чат
const chat = await chrome.runtime.sendMessage({
type: 'CREATE_PLUGIN_CHAT',
pluginId: 'test-chat-plugin',
pageKey: currentUrl,
});
console.log('✅ Чат создан:', chat);
// Сохраняем тестовое сообщение
const message = {
role: 'user',
content: 'Это тестовое сообщение с Ozon',
timestamp: Date.now(),
};
await chrome.runtime.sendMessage({
type: 'SAVE_PLUGIN_CHAT_MESSAGE',
pluginId: 'test-chat-plugin',
pageKey: currentUrl,
message: message,
});
console.log('✅ Тестовое сообщение сохранено:', message);
return true;
} catch (error) {
console.error('❌ Ошибка создания тестового чата:', error);
return false;
}
}
// Функция для отправки тестовых логов
async function sendTestLogs() {
try {
console.log('📝 Отправка тестовых логов...');
const logs = [
{
pluginId: 'ozon-analyzer',
level: 'info',
stepId: 'page-load',
message: 'Страница товара загружена',
logData: { url: currentUrl, title: document.title },
},
{
pluginId: 'ozon-analyzer',
level: 'success',
stepId: 'product-found',
message: 'Товар найден: Костюм спортивный North Dot',
logData: { productId: '1438414833' },
},
{
pluginId: 'test-chat-plugin',
level: 'debug',
stepId: 'test-debug',
message: 'Тестовый отладочный лог',
logData: { test: true, timestamp: Date.now() },
},
];
for (const log of logs) {
await chrome.runtime.sendMessage({
type: 'LOG_EVENT',
pluginId: log.pluginId,
pageKey: currentUrl,
level: log.level,
stepId: log.stepId,
message: log.message,
logData: log.logData,
});
console.log(`✅ Лог отправлен: ${log.pluginId} - ${log.message}`);
}
} catch (error) {
console.error('❌ Ошибка отправки логов:', error);
}
}
// Функция для получения всех данных
async function getAllData() {
try {
console.log('📋 Получение всех данных...');
// Получаем чаты
const chats = await chrome.runtime.sendMessage({
type: 'LIST_PLUGIN_CHATS',
pluginId: null,
});
console.log('✅ Чаты найдены:', chats);
// Получаем черновики
const drafts = await chrome.runtime.sendMessage({
type: 'LIST_PLUGIN_CHAT_DRAFTS',
pluginId: null,
});
console.log('✅ Черновики найдены:', drafts);
// Получаем логи
const logs = await chrome.runtime.sendMessage({
type: 'LIST_ALL_PLUGIN_LOGS',
});
console.log('✅ Логи найдены:', logs);
return { chats, drafts, logs };
} catch (error) {
console.error('❌ Ошибка получения данных:', error);
return { chats: [], drafts: [], logs: {} };
}
}
// Запуск всех тестов
async function runOzonTests() {
console.log('🚀 Запуск тестов для Ozon...');
await createOzonChat();
await createTestPluginChat();
await sendTestLogs();
await getAllData();
console.log('✅ Все тесты завершены!');
console.log('💡 Теперь откройте DevTools и перейдите на вкладки:');
console.log(' - "Чаты плагинов" - для просмотра чатов и черновиков');
console.log(' - "Логи" - для просмотра логов плагинов');
}
// Экспортируем функции для использования в консоли
window.ozonTestSystem = {
createOzonChat,
createTestPluginChat,
sendTestLogs,
getAllData,
runOzonTests,
};
console.log('🎯 Функции тестирования Ozon доступны:');
console.log('- ozonTestSystem.createOzonChat() - создать чат для ozon-analyzer');
console.log('- ozonTestSystem.createTestPluginChat() - создать чат для test-chat-plugin');
console.log('- ozonTestSystem.sendTestLogs() - отправить тестовые логи');
console.log('- ozonTestSystem.getAllData() - получить все данные');
console.log('- ozonTestSystem.runOzonTests() - запустить все тесты');
// Автоматически запускаем тесты
runOzonTests();