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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
17f98cf5
Commit
17f98cf5
authored
May 22, 2018
by
Clement Ho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove code from bad merge
parent
b4849eb9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
119 deletions
+0
-119
app/assets/javascripts/visibility_select.js
app/assets/javascripts/visibility_select.js
+0
-21
spec/javascripts/visibility_select_spec.js
spec/javascripts/visibility_select_spec.js
+0
-98
No files found.
app/assets/javascripts/visibility_select.js
deleted
100644 → 0
View file @
b4849eb9
export
default
class
VisibilitySelect
{
constructor
(
container
)
{
if
(
!
container
)
throw
new
Error
(
'
VisibilitySelect requires a container element as argument 1
'
);
this
.
container
=
container
;
this
.
helpBlock
=
this
.
container
.
querySelector
(
'
.form-text.text-muted
'
);
this
.
select
=
this
.
container
.
querySelector
(
'
select
'
);
}
init
()
{
if
(
this
.
select
)
{
this
.
updateHelpText
();
this
.
select
.
addEventListener
(
'
change
'
,
this
.
updateHelpText
.
bind
(
this
));
}
else
{
this
.
helpBlock
.
textContent
=
this
.
container
.
querySelector
(
'
.js-locked
'
).
dataset
.
helpBlock
;
}
}
updateHelpText
()
{
this
.
helpBlock
.
textContent
=
this
.
select
.
querySelector
(
'
option:checked
'
).
dataset
.
description
;
}
}
spec/javascripts/visibility_select_spec.js
deleted
100644 → 0
View file @
b4849eb9
import
VisibilitySelect
from
'
~/visibility_select
'
;
(()
=>
{
describe
(
'
VisibilitySelect
'
,
function
()
{
const
lockedElement
=
document
.
createElement
(
'
div
'
);
lockedElement
.
dataset
.
helpBlock
=
'
lockedHelpBlock
'
;
const
checkedElement
=
document
.
createElement
(
'
div
'
);
checkedElement
.
dataset
.
description
=
'
checkedDescription
'
;
const
mockElements
=
{
container
:
document
.
createElement
(
'
div
'
),
select
:
document
.
createElement
(
'
div
'
),
'
.form-text.text-muted
'
:
document
.
createElement
(
'
div
'
),
'
.js-locked
'
:
lockedElement
,
'
option:checked
'
:
checkedElement
,
};
beforeEach
(
function
()
{
spyOn
(
Element
.
prototype
,
'
querySelector
'
).
and
.
callFake
(
selector
=>
mockElements
[
selector
]);
});
describe
(
'
constructor
'
,
function
()
{
beforeEach
(
function
()
{
this
.
visibilitySelect
=
new
VisibilitySelect
(
mockElements
.
container
);
});
it
(
'
sets the container member
'
,
function
()
{
expect
(
this
.
visibilitySelect
.
container
).
toEqual
(
mockElements
.
container
);
});
it
(
'
queries and sets the helpBlock member
'
,
function
()
{
expect
(
Element
.
prototype
.
querySelector
).
toHaveBeenCalledWith
(
'
.form-text.text-muted
'
);
expect
(
this
.
visibilitySelect
.
helpBlock
).
toEqual
(
mockElements
[
'
.form-text.text-muted
'
]);
});
it
(
'
queries and sets the select member
'
,
function
()
{
expect
(
Element
.
prototype
.
querySelector
).
toHaveBeenCalledWith
(
'
select
'
);
expect
(
this
.
visibilitySelect
.
select
).
toEqual
(
mockElements
.
select
);
});
describe
(
'
if there is no container element provided
'
,
function
()
{
it
(
'
throws an error
'
,
function
()
{
expect
(()
=>
new
VisibilitySelect
()).
toThrowError
(
'
VisibilitySelect requires a container element as argument 1
'
);
});
});
});
describe
(
'
init
'
,
function
()
{
describe
(
'
if there is a select
'
,
function
()
{
beforeEach
(
function
()
{
this
.
visibilitySelect
=
new
VisibilitySelect
(
mockElements
.
container
);
});
it
(
'
calls updateHelpText
'
,
function
()
{
spyOn
(
VisibilitySelect
.
prototype
,
'
updateHelpText
'
);
this
.
visibilitySelect
.
init
();
expect
(
this
.
visibilitySelect
.
updateHelpText
).
toHaveBeenCalled
();
});
it
(
'
adds a change event listener
'
,
function
()
{
spyOn
(
this
.
visibilitySelect
.
select
,
'
addEventListener
'
);
this
.
visibilitySelect
.
init
();
expect
(
this
.
visibilitySelect
.
select
.
addEventListener
.
calls
.
argsFor
(
0
)).
toContain
(
'
change
'
);
});
});
describe
(
'
if there is no select
'
,
function
()
{
beforeEach
(
function
()
{
mockElements
.
select
=
undefined
;
this
.
visibilitySelect
=
new
VisibilitySelect
(
mockElements
.
container
);
this
.
visibilitySelect
.
init
();
});
it
(
'
updates the helpBlock text to the locked `data-help-block` messaged
'
,
function
()
{
expect
(
this
.
visibilitySelect
.
helpBlock
.
textContent
)
.
toEqual
(
lockedElement
.
dataset
.
helpBlock
);
});
afterEach
(
function
()
{
mockElements
.
select
=
document
.
createElement
(
'
div
'
);
});
});
});
describe
(
'
updateHelpText
'
,
function
()
{
beforeEach
(
function
()
{
this
.
visibilitySelect
=
new
VisibilitySelect
(
mockElements
.
container
);
this
.
visibilitySelect
.
init
();
});
it
(
'
updates the helpBlock text to the selected options `data-description`
'
,
function
()
{
expect
(
this
.
visibilitySelect
.
helpBlock
.
textContent
)
.
toEqual
(
checkedElement
.
dataset
.
description
);
});
});
});
})();
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