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
fe3a15e9
Commit
fe3a15e9
authored
Dec 22, 2021
by
Savas Vedova
Committed by
Kushal Pandya
Dec 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor form sections
parent
029d4eea
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
204 additions
and
117 deletions
+204
-117
ee/app/assets/javascripts/vulnerabilities/components/new_vulnerability/new_vulnerability.vue
...lities/components/new_vulnerability/new_vulnerability.vue
+6
-75
ee/app/assets/javascripts/vulnerabilities/components/new_vulnerability/section_name.vue
...erabilities/components/new_vulnerability/section_name.vue
+91
-0
ee/app/assets/javascripts/vulnerabilities/new_vulnerability_init.js
...ets/javascripts/vulnerabilities/new_vulnerability_init.js
+5
-7
ee/spec/frontend/vulnerabilities/new_vulnerability/new_vulnerability_spec.js
...lnerabilities/new_vulnerability/new_vulnerability_spec.js
+7
-35
ee/spec/frontend/vulnerabilities/new_vulnerability/section_name_spec.js
...nd/vulnerabilities/new_vulnerability/section_name_spec.js
+61
-0
ee/spec/frontend_integration/vulnerabilities/new_vulnerability_init_integration_spec.js
...ulnerabilities/new_vulnerability_init_integration_spec.js
+34
-0
No files found.
ee/app/assets/javascripts/vulnerabilities/components/new_vulnerability/new_vulnerability.vue
View file @
fe3a15e9
<
script
>
import
{
GlForm
,
GlFormGroup
,
GlFormInput
,
GlFormTextarea
}
from
'
@gitlab/ui
'
;
import
MarkdownField
from
'
~/vue_shared/components/markdown/field.vue
'
;
import
{
s__
,
__
}
from
'
~/locale
'
;
import
{
GlForm
}
from
'
@gitlab/ui
'
;
import
{
s__
}
from
'
~/locale
'
;
import
SectionDetails
from
'
./section_details.vue
'
;
import
SectionName
from
'
./section_name.vue
'
;
export
default
{
name
:
'
NewVulnerabilityForm
'
,
components
:
{
GlForm
,
GlFormGroup
,
GlFormInput
,
GlFormTextarea
,
MarkdownField
,
SectionDetails
,
},
props
:
{
markdownDocsPath
:
{
type
:
String
,
required
:
true
,
},
markdownPreviewPath
:
{
type
:
String
,
required
:
true
,
},
SectionName
,
},
data
()
{
return
{
isSubmitting
:
false
,
form
:
{
vulnerabilityName
:
''
,
vulnerabilityDesc
:
''
,
...
...
@@ -46,26 +32,12 @@ export default {
description
:
s__
(
'
VulnerabilityManagement|Manually add a vulnerability entry into the vulnerability report.
'
,
),
form
:
{
vulnerabilityName
:
{
label
:
__
(
'
Name
'
),
description
:
s__
(
'
VulnerabilityManagement|Vulnerability name or type. Ex: Cross-site scripting
'
,
),
},
vulnerabilityDesc
:
{
label
:
__
(
'
Description
'
),
description
:
s__
(
'
VulnerabilityManagement|Summary, detailed description, steps to reproduce, etc.
'
,
),
},
},
},
};
</
script
>
<
template
>
<div>
<div
data-testid=
"new-vulnerability-form"
>
<header
class=
"gl-my-4 gl-border-b-gray-100 gl-border-b-solid gl-border-b-1"
>
<h2
class=
"gl-mt-0 gl-mb-3"
>
{{
$options
.
i18n
.
title
}}
...
...
@@ -75,48 +47,7 @@ export default {
</p>
</header>
<gl-form
class=
"gl-p-4 gl-w-85p"
@
submit
.
prevent
>
<gl-form-group
:label=
"$options.i18n.form.vulnerabilityName.label"
:description=
"$options.i18n.form.vulnerabilityName.description"
label-for=
"form-vulnerability-name"
class=
"gl-mb-6"
>
<gl-form-input
id=
"form-vulnerability-name"
v-model=
"form.vulnerabilityName"
class=
"gl-mb-2"
type=
"text"
/>
</gl-form-group>
<gl-form-group
:label=
"$options.i18n.form.vulnerabilityDesc.label"
label-for=
"form-vulnerability-desc"
>
<div
class=
"gl-border-solid gl-border-gray-100 gl-border-1 gl-pt-3 gl-pb-5 gl-px-3 gl-rounded-base"
>
<markdown-field
ref=
"markdownField"
:can-attach-file=
"false"
:add-spacing-classes=
"false"
:markdown-preview-path=
"markdownPreviewPath"
:markdown-docs-path=
"markdownDocsPath"
:textarea-value=
"form.vulnerabilityDesc"
:is-submitting=
"isSubmitting"
>
<template
#textarea
>
<gl-form-textarea
id=
"form-vulnerability-desc"
v-model=
"form.vulnerabilityDesc"
rows=
"8"
class=
"gl-shadow-none! gl-px-0! gl-py-4! gl-h-auto!"
:aria-label=
"$options.i18n.form.vulnerabilityDesc.description"
:placeholder=
"$options.i18n.form.vulnerabilityDesc.description"
/>
</
template
>
</markdown-field>
</div>
</gl-form-group>
<section-name
@
change=
"updateFormValues"
/>
<section-details
@
change=
"updateFormValues"
/>
</gl-form>
</div>
...
...
ee/app/assets/javascripts/vulnerabilities/components/new_vulnerability/section_name.vue
0 → 100644
View file @
fe3a15e9
<
script
>
import
{
GlFormGroup
,
GlFormInput
,
GlFormTextarea
}
from
'
@gitlab/ui
'
;
import
{
s__
,
__
}
from
'
~/locale
'
;
import
MarkdownField
from
'
~/vue_shared/components/markdown/field.vue
'
;
export
default
{
components
:
{
GlFormGroup
,
GlFormInput
,
GlFormTextarea
,
MarkdownField
,
},
inject
:
[
'
markdownDocsPath
'
,
'
markdownPreviewPath
'
],
data
()
{
return
{
isSubmitting
:
false
,
vulnerabilityName
:
''
,
vulnerabilityDesc
:
''
,
};
},
methods
:
{
emitChanges
()
{
this
.
$emit
(
'
change
'
,
{
vulnerabilityName
:
this
.
vulnerabilityName
,
vulnerabilityDesc
:
this
.
vulnerabilityDesc
,
});
},
},
i18n
:
{
vulnerabilityName
:
{
label
:
__
(
'
Name
'
),
description
:
s__
(
'
VulnerabilityManagement|Vulnerability name or type. Ex: Cross-site scripting
'
,
),
},
vulnerabilityDesc
:
{
label
:
__
(
'
Description
'
),
description
:
s__
(
'
VulnerabilityManagement|Summary, detailed description, steps to reproduce, etc.
'
,
),
},
},
};
</
script
>
<
template
>
<div>
<gl-form-group
:label=
"$options.i18n.vulnerabilityName.label"
:description=
"$options.i18n.vulnerabilityName.description"
label-for=
"form-vulnerability-name"
class=
"gl-mb-6"
>
<gl-form-input
id=
"form-vulnerability-name"
v-model=
"vulnerabilityName"
type=
"text"
@
change=
"emitChanges"
/>
</gl-form-group>
<gl-form-group
:label=
"$options.i18n.vulnerabilityDesc.label"
label-for=
"form-vulnerability-desc"
>
<div
class=
"gl-border-solid gl-border-gray-100 gl-border-1 gl-pt-3 gl-pb-5 gl-px-3 gl-rounded-base"
>
<markdown-field
ref=
"markdownField"
:can-attach-file=
"false"
:add-spacing-classes=
"false"
:markdown-preview-path=
"markdownPreviewPath"
:markdown-docs-path=
"markdownDocsPath"
:textarea-value=
"vulnerabilityDesc"
:is-submitting=
"isSubmitting"
>
<template
#textarea
>
<gl-form-textarea
id=
"form-vulnerability-desc"
v-model=
"vulnerabilityDesc"
rows=
"8"
class=
"gl-shadow-none! gl-px-0! gl-py-4! gl-h-auto!"
:aria-label=
"$options.i18n.vulnerabilityDesc.description"
:placeholder=
"$options.i18n.vulnerabilityDesc.description"
@
change=
"emitChanges"
/>
</
template
>
</markdown-field>
</div>
</gl-form-group>
</div>
</template>
ee/app/assets/javascripts/vulnerabilities/new_vulnerability_init.js
View file @
fe3a15e9
...
...
@@ -10,12 +10,10 @@ export default (el) => {
return
new
Vue
({
el
,
apolloProvider
,
render
:
(
h
)
=>
h
(
App
,
{
props
:
{
provide
:
{
markdownDocsPath
:
el
.
dataset
.
markdownDocsPath
,
markdownPreviewPath
:
el
.
dataset
.
markdownPreviewPath
,
},
}
),
render
:
(
h
)
=>
h
(
App
),
});
};
ee/spec/frontend/vulnerabilities/new_vulnerability/new_vulnerability_spec.js
View file @
fe3a15e9
import
{
GlForm
}
from
'
@gitlab/ui
'
;
import
MarkdownField
from
'
~/vue_shared/components/markdown/field.vue
'
;
import
{
mountExtended
}
from
'
helpers/vue_test_utils_helper
'
;
import
{
shallowMountExtended
}
from
'
helpers/vue_test_utils_helper
'
;
import
NewVulnerability
from
'
ee/vulnerabilities/components/new_vulnerability/new_vulnerability.vue
'
;
import
SectionName
from
'
ee/vulnerabilities/components/new_vulnerability/section_name.vue
'
;
import
SectionDetails
from
'
ee/vulnerabilities/components/new_vulnerability/section_details.vue
'
;
describe
(
'
New vulnerability component
'
,
()
=>
{
let
wrapper
;
const
markdownDocsPath
=
'
/path/to/markdown/docs
'
;
const
markdownPreviewPath
=
'
/path/to/markdown/preview
'
;
const
findSectionName
=
()
=>
wrapper
.
findComponent
(
SectionName
);
const
findSectionDetails
=
()
=>
wrapper
.
findComponent
(
SectionDetails
);
const
createWrapper
=
()
=>
{
return
mountExtended
(
NewVulnerability
,
{
propsData
:
{
markdownDocsPath
,
markdownPreviewPath
,
},
});
return
shallowMountExtended
(
NewVulnerability
);
};
beforeEach
(()
=>
{
...
...
@@ -41,31 +35,9 @@ describe('New vulnerability component', () => {
expect
(
wrapper
.
findComponent
(
GlForm
).
exists
()).
toBe
(
true
);
});
it
(
'
creates markdown editor with correct props
'
,
()
=>
{
expect
(
wrapper
.
findComponent
(
MarkdownField
).
props
()).
toMatchObject
({
markdownDocsPath
,
markdownPreviewPath
,
textareaValue
:
''
,
canAttachFile
:
false
,
addSpacingClasses
:
false
,
isSubmitting
:
false
,
});
});
it
.
each
`
labelText | description
${
'
Name
'
}
|
${
'
Vulnerability name or type. Ex: Cross-site scripting
'
}
${
'
Description
'
}
|
${
''
}
`
(
'
displays the input with the correct label: $labelText
'
,
({
labelText
,
description
})
=>
{
expect
(
wrapper
.
findByLabelText
(
labelText
).
exists
()).
toBe
(
true
);
if
(
description
)
{
expect
(
wrapper
.
findByText
(
description
).
exists
()).
toBe
(
true
);
}
});
it
.
each
`
section | selector | fields
${
'
Name and Description
'
}
|
${
findSectionName
}
|
${{
vulnerabilityName
:
'
CVE 2050
'
,
vulnerabilityDesc
:
'
Password leak
'
}
}
${
'
Details
'
}
|
${
findSectionDetails
}
|
${{
severity
:
'
low
'
,
detectionMethod
:
2
,
status
:
'
confirmed
'
}
}
`
(
'
mounts the section $section and reacts on the change event
'
,
({
selector
,
fields
})
=>
{
const
section
=
selector
();
...
...
ee/spec/frontend/vulnerabilities/new_vulnerability/section_name_spec.js
0 → 100644
View file @
fe3a15e9
import
{
GlFormInput
,
GlFormTextarea
}
from
'
@gitlab/ui
'
;
import
{
mountExtended
}
from
'
helpers/vue_test_utils_helper
'
;
import
MarkdownField
from
'
~/vue_shared/components/markdown/field.vue
'
;
import
SectionName
from
'
ee/vulnerabilities/components/new_vulnerability/section_name.vue
'
;
describe
(
'
New vulnerability - Section Name
'
,
()
=>
{
const
markdownDocsPath
=
'
/path/to/markdown/docs
'
;
const
markdownPreviewPath
=
'
/path/to/markdown/preview
'
;
let
wrapper
;
const
createWrapper
=
()
=>
{
return
mountExtended
(
SectionName
,
{
provide
:
{
markdownDocsPath
,
markdownPreviewPath
,
},
});
};
beforeEach
(()
=>
{
wrapper
=
createWrapper
();
});
afterEach
(()
=>
{
wrapper
.
destroy
();
});
it
(
'
creates markdown editor with correct props
'
,
()
=>
{
expect
(
wrapper
.
findComponent
(
MarkdownField
).
props
()).
toMatchObject
({
markdownDocsPath
,
markdownPreviewPath
,
textareaValue
:
''
,
canAttachFile
:
false
,
addSpacingClasses
:
false
,
isSubmitting
:
false
,
});
});
it
.
each
`
labelText | description
${
'
Name
'
}
|
${
'
Vulnerability name or type. Ex: Cross-site scripting
'
}
${
'
Description
'
}
|
${
''
}
`
(
'
displays the input with the correct label: $labelText
'
,
({
labelText
,
description
})
=>
{
expect
(
wrapper
.
findByLabelText
(
labelText
).
exists
()).
toBe
(
true
);
if
(
description
)
{
expect
(
wrapper
.
findByText
(
description
).
exists
()).
toBe
(
true
);
}
});
it
.
each
`
field | component | value
${
'
Name
'
}
|
${
GlFormInput
}
|
${{
vulnerabilityName
:
'
CVE 2021
'
,
vulnerabilityDesc
:
''
}
}
${
'
Description
'
}
|
${
GlFormTextarea
}
|
${{
vulnerabilityName
:
''
,
vulnerabilityDesc
:
'
Password leak
'
}
}
`
(
'
emits the changes: $field
'
,
async
({
component
,
value
})
=>
{
wrapper
.
setData
(
value
);
wrapper
.
findComponent
(
component
).
vm
.
$emit
(
'
change
'
,
value
);
expect
(
wrapper
.
emitted
(
'
change
'
)[
0
][
0
]).
toEqual
(
value
);
});
});
ee/spec/frontend_integration/vulnerabilities/new_vulnerability_init_integration_spec.js
0 → 100644
View file @
fe3a15e9
import
{
screen
,
within
}
from
'
@testing-library/dom
'
;
import
initNewVulnerability
from
'
ee/vulnerabilities/new_vulnerability_init
'
;
describe
(
'
New Vulnerability Form
'
,
()
=>
{
let
vm
;
let
container
;
const
createComponent
=
()
=>
{
const
el
=
document
.
createElement
(
'
div
'
);
Object
.
assign
(
el
.
dataset
,
{
markdownDocsPath
:
'
/markdown/docs/path
'
,
markdownPreviewPath
:
'
/markdown/preview/path
'
,
});
container
.
appendChild
(
el
);
return
initNewVulnerability
(
el
);
};
beforeEach
(()
=>
{
setFixtures
(
'
<div class="new-vulnerability-init"></div>
'
);
container
=
document
.
querySelector
(
'
.new-vulnerability-init
'
);
vm
=
createComponent
(
container
);
});
afterEach
(()
=>
{
vm
.
$destroy
();
});
it
(
'
renders the form
'
,
()
=>
{
const
form
=
screen
.
getByTestId
(
'
new-vulnerability-form
'
);
expect
(
within
(
form
).
getByText
(
'
Add vulnerability finding
'
)).
toBeInstanceOf
(
HTMLElement
);
});
});
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