Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
18711a65
Commit
18711a65
authored
Dec 24, 2021
by
anna_vovchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented suggestions after the FE review
parent
6b5b5e8f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
19 deletions
+87
-19
app/assets/javascripts/clusters_list/components/agent_actions.vue
...ts/javascripts/clusters_list/components/agent_actions.vue
+8
-4
spec/frontend/clusters_list/components/agent_actions_spec.js
spec/frontend/clusters_list/components/agent_actions_spec.js
+79
-15
No files found.
app/assets/javascripts/clusters_list/components/agent_actions.vue
View file @
18711a65
...
...
@@ -61,6 +61,7 @@ export default {
loading
:
false
,
error
:
null
,
deleteConfirmText
:
null
,
agentName
:
this
.
agent
.
name
,
};
},
computed
:
{
...
...
@@ -98,15 +99,17 @@ export default {
},
methods
:
{
async
deleteAgent
()
{
if
(
this
.
disableModalSubmit
||
this
.
loading
)
{
return
;
}
this
.
loading
=
true
;
this
.
error
=
null
;
const
successMessage
=
sprintf
(
this
.
$options
.
i18n
.
successMessage
,
{
name
:
this
.
agent
.
name
});
try
{
const
{
errors
}
=
await
this
.
deleteAgentMutation
();
if
(
errors
?.
length
>
0
)
{
if
(
errors
.
length
)
{
throw
new
Error
(
errors
[
0
]);
}
}
catch
(
error
)
{
...
...
@@ -117,6 +120,7 @@ export default {
}
}
finally
{
this
.
loading
=
false
;
const
successMessage
=
sprintf
(
this
.
$options
.
i18n
.
successMessage
,
{
name
:
this
.
agentName
});
if
(
!
this
.
error
)
{
this
.
$toast
.
show
(
successMessage
);
...
...
@@ -196,7 +200,7 @@ export default {
</
template
>
</gl-sprintf>
</template>
<gl-form-input
v-model=
"deleteConfirmText"
@
key
up
.enter=
"deleteAgent"
/>
<gl-form-input
v-model=
"deleteConfirmText"
@
key
down
.enter=
"deleteAgent"
/>
</gl-form-group>
</gl-modal>
</div>
...
...
spec/frontend/clusters_list/components/agent_actions_spec.js
View file @
18711a65
import
{
GlDropdownItem
,
GlModal
,
GlFormInput
}
from
'
@gitlab/ui
'
;
import
{
GlDropdown
,
GlDropdown
Item
,
GlModal
,
GlFormInput
}
from
'
@gitlab/ui
'
;
import
Vue
from
'
vue
'
;
import
VueApollo
from
'
vue-apollo
'
;
import
{
shallowMountExtended
}
from
'
helpers/vue_test_utils_helper
'
;
import
{
ENTER_KEY
}
from
'
~/lib/utils/keys
'
;
import
getAgentsQuery
from
'
~/clusters_list/graphql/queries/get_agents.query.graphql
'
;
import
deleteAgentMutation
from
'
~/clusters_list/graphql/mutations/delete_agent.mutation.graphql
'
;
import
createMockApollo
from
'
helpers/mock_apollo_helper
'
;
...
...
@@ -27,6 +28,7 @@ describe('AgentActions', () => {
let
deleteResponse
;
const
findModal
=
()
=>
wrapper
.
findComponent
(
GlModal
);
const
findDropdown
=
()
=>
wrapper
.
findComponent
(
GlDropdown
);
const
findDeleteBtn
=
()
=>
wrapper
.
findComponent
(
GlDropdownItem
);
const
findInput
=
()
=>
wrapper
.
findComponent
(
GlFormInput
);
const
findPrimaryAction
=
()
=>
findModal
().
props
(
'
actionPrimary
'
);
...
...
@@ -77,6 +79,12 @@ describe('AgentActions', () => {
return
wrapper
.
vm
.
$nextTick
();
};
const
submitAgentToDelete
=
async
()
=>
{
findDeleteBtn
().
vm
.
$emit
(
'
click
'
);
findInput
().
vm
.
$emit
(
'
input
'
,
agent
.
name
);
await
findModal
().
vm
.
$emit
(
'
primary
'
);
};
beforeEach
(()
=>
{
return
createWrapper
({});
});
...
...
@@ -103,27 +111,57 @@ describe('AgentActions', () => {
});
});
describe
(
'
when the input with agent name is missing
'
,
()
=>
{
describe
.
each
`
condition | agentName | isDisabled | mutationCalled
${
'
the input with agent name is missing
'
}
|
${
''
}
|
${
true
}
|
${
false
}
${
'
the input with agent name is incorrect
'
}
|
${
'
wrong-name
'
}
|
${
true
}
|
${
false
}
${
'
the input with agent name is correct
'
}
|
${
agent
.
name
}
|
${
false
}
|
${
true
}
`
(
'
when $condition
'
,
({
agentName
,
isDisabled
,
mutationCalled
})
=>
{
beforeEach
(()
=>
{
findDeleteBtn
().
vm
.
$emit
(
'
click
'
);
findInput
().
vm
.
$emit
(
'
input
'
,
agentName
);
});
it
(
'
disables the modal primary button
'
,
()
=>
{
expect
(
findPrimaryActionAttributes
(
'
disabled
'
)).
toBe
(
true
);
it
(
`
${
isDisabled
?
'
disables
'
:
'
enables
'
}
the modal primary button`
,
()
=>
{
expect
(
findPrimaryActionAttributes
(
'
disabled
'
)).
toBe
(
isDisabled
);
});
});
describe
(
'
when submitting the delete modal and the input with agent name is correct
'
,
()
=>
{
beforeEach
(()
=>
{
findDeleteBtn
().
vm
.
$emit
(
'
click
'
);
findInput
().
vm
.
$emit
(
'
input
'
,
agent
.
name
);
findModal
().
vm
.
$emit
(
'
primary
'
);
describe
(
'
when user clicks the modal primary button
'
,
()
=>
{
beforeEach
(
async
()
=>
{
await
findModal
().
vm
.
$emit
(
'
primary
'
);
});
if
(
mutationCalled
)
{
it
(
'
calls the delete mutation
'
,
()
=>
{
expect
(
deleteResponse
).
toHaveBeenCalledWith
({
input
:
{
id
:
agent
.
id
}
});
});
}
else
{
it
(
"
doesn't call the delete mutation
"
,
()
=>
{
expect
(
deleteResponse
).
not
.
toHaveBeenCalled
();
});
}
});
return
wrapper
.
vm
.
$nextTick
();
describe
(
'
when user presses the enter button
'
,
()
=>
{
beforeEach
(
async
()
=>
{
await
findInput
().
vm
.
$emit
(
'
keydown
'
,
new
KeyboardEvent
({
key
:
ENTER_KEY
}));
});
if
(
mutationCalled
)
{
it
(
'
calls the delete mutation
'
,
()
=>
{
expect
(
deleteResponse
).
toHaveBeenCalledWith
({
input
:
{
id
:
agent
.
id
}
});
});
}
else
{
it
(
"
doesn't call the delete mutation
"
,
()
=>
{
expect
(
deleteResponse
).
not
.
toHaveBeenCalled
();
});
}
});
});
it
(
'
calls the delete mutation
'
,
()
=>
{
expect
(
deleteResponse
).
toHaveBeenCalledWith
({
input
:
{
id
:
agent
.
id
}
});
describe
(
'
when agent was deleted successfully
'
,
()
=>
{
beforeEach
(
async
()
=>
{
await
submitAgentToDelete
();
});
it
(
'
calls the toast action
'
,
()
=>
{
...
...
@@ -136,12 +174,38 @@ describe('AgentActions', () => {
beforeEach
(
async
()
=>
{
await
createWrapper
({
mutationResponse
:
mockErrorDeleteResponse
});
findDeleteBtn
().
vm
.
$emit
(
'
click
'
);
findModal
().
vm
.
$emit
(
'
primary
'
);
submitAgentToDelete
();
});
it
(
'
displays the error message
'
,
()
=>
{
expect
(
toast
).
toHaveBeenCalledWith
(
'
could not delete agent
'
);
});
});
describe
(
'
when the delete modal was closed
'
,
()
=>
{
beforeEach
(
async
()
=>
{
const
loadingResponse
=
new
Promise
(()
=>
{});
await
createWrapper
({
mutationResponse
:
loadingResponse
});
submitAgentToDelete
();
});
it
(
'
reenables the actions dropdown
'
,
async
()
=>
{
expect
(
findPrimaryActionAttributes
(
'
loading
'
)).
toBe
(
true
);
expect
(
findDropdown
().
attributes
(
'
disabled
'
)).
toBe
(
'
true
'
);
await
findModal
().
vm
.
$emit
(
'
hide
'
);
expect
(
findPrimaryActionAttributes
(
'
loading
'
)).
toBe
(
false
);
expect
(
findDropdown
().
attributes
(
'
disabled
'
)).
toBeUndefined
();
});
it
(
'
clears the agent name input
'
,
async
()
=>
{
expect
(
findInput
().
attributes
(
'
value
'
)).
toBe
(
agent
.
name
);
await
findModal
().
vm
.
$emit
(
'
hide
'
);
expect
(
findInput
().
attributes
(
'
value
'
)).
toBeUndefined
();
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment