Открыть боковую панель
Захаров Дмитрий Сергеевич
Gitlab
Коммиты
27b86a50
Коммит
27b86a50
создал
Апр 14, 2023
по автору
Nicolas Dular
Просмотр файлов
Only subscribe when the mutation has been sent
владелец
7cc0fe81
Изменения
2
Скрыть пробелы
Построчно
Рядом
ee/app/assets/javascripts/vue_shared/components/markdown/ai_actions_dropdown.vue
Просмотр файла @
27b86a50
...
...
@@ -32,6 +32,7 @@ export default {
loading
:
false
,
errorAlert
:
null
,
aiCompletionResponse
:
{},
skipSubscription
:
true
,
};
},
computed
:
{
...
...
@@ -60,7 +61,13 @@ export default {
error
(
error
)
{
this
.
handleError
(
error
);
},
skip
()
{
return
this
.
skipSubscription
;
},
result
({
data
})
{
if
(
!
data
.
aiCompletionResponse
)
{
return
;
}
this
.
loading
=
false
;
if
(
this
.
timeout
)
{
...
...
@@ -69,6 +76,7 @@ export default {
if
(
data
.
error
)
{
this
.
handleError
(
new
Error
(
data
.
error
));
this
.
skipSubscription
=
true
;
return
;
}
...
...
@@ -77,6 +85,8 @@ export default {
const
generatedByText
=
`
${
data
.
aiCompletionResponse
.
responseBody
}
\n***\n_
${
__
(
'
This comment was generated using OpenAI
'
,
)}
_`
;
this
.
skipSubscription
=
true
;
if
(
textArea
)
{
updateText
({
textArea
,
...
...
@@ -110,11 +120,11 @@ export default {
this
.
$apollo
.
mutate
({
mutation
:
aiActionMutation
,
variables
:
{
input
}
})
.
then
(({
data
:
{
aiAction
}
})
=>
{
if
(
aiAction
.
errors
.
length
>
0
)
{
if
(
aiAction
.
errors
&&
aiAction
.
errors
.
length
>
0
)
{
this
.
handleError
(
new
Error
(
aiAction
.
errors
));
return
;
}
this
.
$apollo
.
s
ubscription
s
.
aiCompletionResponse
.
start
()
;
this
.
skipS
ubscription
=
false
;
})
.
catch
(
this
.
handleError
);
},
...
...
@@ -135,6 +145,7 @@ export default {
...
alertOptions
,
});
this
.
loading
=
false
;
this
.
skipSubscription
=
true
;
clearTimeout
(
this
.
timeout
);
},
},
...
...
ee/spec/frontend/vue_shared/components/markdown/ai_actions_dropdown_spec.js
Просмотр файла @
27b86a50
import
Vue
,
{
nextTick
}
from
'
vue
'
;
import
VueApollo
from
'
vue-apollo
'
;
import
{
GlCollapsibleListbox
,
GlListboxItem
,
GlLoadingIcon
}
from
'
@gitlab/ui
'
;
import
{
createMockSubscription
}
from
'
mock-apollo-client
'
;
import
createMockApollo
from
'
helpers/mock_apollo_helper
'
;
import
{
setHTMLFixture
,
resetHTMLFixture
}
from
'
helpers/fixtures
'
;
...
...
@@ -40,13 +39,12 @@ describe('AI actions dropdown component', () => {
const
createWrapper
=
(
props
)
=>
{
window
.
gon
=
{
current_user_id
:
userId
};
aiResponseSubscriptionHandler
=
createMockSubscription
();
aiActionMutationHandler
=
jest
.
fn
();
const
mockApollo
=
createMockApollo
([[
aiActionMutation
,
aiActionMutationHandler
]]
);
mockApollo
.
defaultClient
.
setRequestHandler
(
aiResponseSubscription
,
()
=>
aiResponseSubscrip
tionHandler
,
);
aiResponseSubscriptionHandler
=
jest
.
fn
(
);
const
mockApollo
=
createMockApollo
([
[
aiResponseSubscription
,
aiResponseSubscriptionHandler
],
[
aiActionMutation
,
aiActionMuta
tionHandler
]
,
]
);
wrapper
=
mountExtended
(
AiActionsDropdown
,
{
attachTo
:
'
#root
'
,
...
...
@@ -65,6 +63,8 @@ describe('AI actions dropdown component', () => {
afterEach
(()
=>
{
resetHTMLFixture
();
aiActionMutationHandler
.
mockRestore
();
aiResponseSubscriptionHandler
.
mockRestore
();
});
describe
(
'
summarize comments action
'
,
()
=>
{
...
...
@@ -95,17 +95,22 @@ describe('AI actions dropdown component', () => {
describe
(
'
success
'
,
()
=>
{
beforeEach
(
async
()
=>
{
aiActionMutationHandler
.
mockResolvedValue
({});
await
selectSummariseComments
();
aiResponseSubscriptionHandler
.
next
({
aiResponseSubscriptionHandler
.
mockResolvedValue
({
data
:
{
aiCompletionResponse
:
{
responseBody
:
'
yay
'
,
},
},
});
aiActionMutationHandler
.
mockResolvedValue
({
data
:
{
aiAction
:
{
errors
:
''
,
},
},
});
await
selectSummariseComments
();
});
it
(
'
stops loading
'
,
()
=>
{
...
...
@@ -183,7 +188,10 @@ describe('AI actions dropdown component', () => {
it
(
'
shows an error and logs to Sentry when the AI subscription fails
'
,
async
()
=>
{
const
mockError
=
new
Error
(
'
ding
'
);
aiResponseSubscriptionHandler
.
error
(
mockError
);
aiResponseSubscriptionHandler
.
mockRejectedValue
(
mockError
);
await
selectSummariseComments
();
await
waitForPromises
();
expect
(
createAlert
).
toHaveBeenCalledWith
(
expect
.
objectContaining
({
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать