BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
ea04d1ab
Commit
ea04d1ab
authored
Jan 18, 2018
by
Eric Eastwood
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix duplicate item in protected branch/tag dropdown
Fix
https://gitlab.com/gitlab-org/gitlab-ce/issues/42157
Fix
https://gitlab.com/gitlab-org/gitlab-ce/issues/41989
parent
5392568e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
135 additions
and
1 deletion
+135
-1
create_item_dropdown.js
app/assets/javascripts/create_item_dropdown.js
+11
-1
42157-41989-fix-duplicate-in-create-item-dropdown.yml
...sed/42157-41989-fix-duplicate-in-create-item-dropdown.yml
+5
-0
create_item_dropdown_spec.js
spec/javascripts/create_item_dropdown_spec.js
+106
-0
create_item_dropdown.html.haml
spec/javascripts/fixtures/create_item_dropdown.html.haml
+13
-0
No files found.
app/assets/javascripts/create_item_dropdown.js
View file @
ea04d1ab
...
...
@@ -65,7 +65,17 @@ export default class CreateItemDropdown {
getData
(
term
,
callback
)
{
this
.
getDataOption
(
term
,
(
data
=
[])
=>
{
callback
(
data
.
concat
(
this
.
selectedItem
||
[]));
// Ensure the selected item isn't already in the data to avoid duplicates
const
alreadyHasSelectedItem
=
this
.
selectedItem
&&
data
.
some
(
item
=>
item
.
id
===
this
.
selectedItem
.
id
,
);
let
uniqueData
=
data
;
if
(
!
alreadyHasSelectedItem
)
{
uniqueData
=
data
.
concat
(
this
.
selectedItem
||
[]);
}
callback
(
uniqueData
);
});
}
...
...
changelogs/unreleased/42157-41989-fix-duplicate-in-create-item-dropdown.yml
0 → 100644
View file @
ea04d1ab
---
title
:
Fix duplicate item in protected branch/tag dropdown
merge_request
:
author
:
type
:
fixed
spec/javascripts/create_item_dropdown_spec.js
0 → 100644
View file @
ea04d1ab
import
CreateItemDropdown
from
'~/create_item_dropdown'
;
const
DROPDOWN_ITEM_DATA
=
[{
title
:
'one'
,
id
:
'one'
,
text
:
'one'
,
},
{
title
:
'two'
,
id
:
'two'
,
text
:
'two'
,
},
{
title
:
'three'
,
id
:
'three'
,
text
:
'three'
,
}];
describe
(
'CreateItemDropdown'
,
()
=>
{
preloadFixtures
(
'static/create_item_dropdown.html.raw'
);
let
$wrapperEl
;
beforeEach
(()
=>
{
loadFixtures
(
'static/create_item_dropdown.html.raw'
);
$wrapperEl
=
$
(
'.js-create-item-dropdown-fixture-root'
);
// eslint-disable-next-line no-new
new
CreateItemDropdown
({
$dropdown
:
$wrapperEl
.
find
(
'.js-dropdown-menu-toggle'
),
defaultToggleLabel
:
'All variables'
,
fieldName
:
'variable[environment]'
,
getData
:
(
term
,
callback
)
=>
{
callback
(
DROPDOWN_ITEM_DATA
);
},
});
});
afterEach
(()
=>
{
$wrapperEl
.
remove
();
});
it
(
'should have a dropdown item for each piece of data'
,
()
=>
{
// Get the data in the dropdown
$
(
'.js-dropdown-menu-toggle'
).
click
();
const
$itemEls
=
$wrapperEl
.
find
(
'.js-dropdown-content a'
);
expect
(
$itemEls
.
length
).
toEqual
(
DROPDOWN_ITEM_DATA
.
length
);
});
describe
(
'created items'
,
()
=>
{
const
NEW_ITEM_TEXT
=
'foobarbaz'
;
function
createItemAndClearInput
(
text
)
{
// Filter for the new item
$wrapperEl
.
find
(
'.dropdown-input-field'
)
.
val
(
text
)
.
trigger
(
'input'
);
// Create the new item
const
$createButton
=
$wrapperEl
.
find
(
'.js-dropdown-create-new-item'
);
$createButton
.
click
();
// Clear out the filter
$wrapperEl
.
find
(
'.dropdown-input-field'
)
.
val
(
''
)
.
trigger
(
'input'
);
}
beforeEach
(()
=>
{
// Open the dropdown
$
(
'.js-dropdown-menu-toggle'
).
click
();
// Filter for the new item
$wrapperEl
.
find
(
'.dropdown-input-field'
)
.
val
(
NEW_ITEM_TEXT
)
.
trigger
(
'input'
);
});
it
(
'create new item button should include the filter text'
,
()
=>
{
expect
(
$wrapperEl
.
find
(
'.js-dropdown-create-new-item code'
).
text
()).
toEqual
(
NEW_ITEM_TEXT
);
});
it
(
'should update the dropdown with the newly created item'
,
()
=>
{
// Create the new item
const
$createButton
=
$wrapperEl
.
find
(
'.js-dropdown-create-new-item'
);
$createButton
.
click
();
expect
(
$wrapperEl
.
find
(
'.dropdown-toggle-text'
).
text
()).
toEqual
(
NEW_ITEM_TEXT
);
expect
(
$wrapperEl
.
find
(
'input[name="variable[environment]"]'
).
val
()).
toEqual
(
NEW_ITEM_TEXT
);
});
it
(
'should include newly created item in dropdown list'
,
()
=>
{
createItemAndClearInput
(
NEW_ITEM_TEXT
);
const
$itemEls
=
$wrapperEl
.
find
(
'.js-dropdown-content a'
);
expect
(
$itemEls
.
length
).
toEqual
(
1
+
DROPDOWN_ITEM_DATA
.
length
);
expect
(
$
(
$itemEls
.
get
(
DROPDOWN_ITEM_DATA
.
length
)).
text
()).
toEqual
(
NEW_ITEM_TEXT
);
});
it
(
'should not duplicate an item when trying to create an existing item'
,
()
=>
{
createItemAndClearInput
(
DROPDOWN_ITEM_DATA
[
0
].
text
);
const
$itemEls
=
$wrapperEl
.
find
(
'.js-dropdown-content a'
);
expect
(
$itemEls
.
length
).
toEqual
(
DROPDOWN_ITEM_DATA
.
length
);
});
});
});
spec/javascripts/fixtures/create_item_dropdown.html.haml
0 → 100644
View file @
ea04d1ab
.js-create-item-dropdown-fixture-root
%input
{
name:
'variable[environment]'
,
type:
'hidden'
}
=
dropdown_tag
(
'some label'
,
options:
{
toggle_class:
'js-dropdown-menu-toggle'
,
content_class:
'js-dropdown-content'
,
filter:
true
,
dropdown_class:
"dropdown-menu-selectable"
,
footer_content:
true
})
do
%ul
.dropdown-footer-list
%li
%button
{
class:
"dropdown-create-new-item-button js-dropdown-create-new-item"
}
Create wildcard
%code
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