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
Tatuya Kamada
gitlab-ce
Commits
45485947
Commit
45485947
authored
Dec 22, 2016
by
Luke "Jared" Bennett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve disabled state select
Add tests
parent
6ff989cd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
8 deletions
+88
-8
app/views/projects/mattermosts/_team_selection.html.haml
app/views/projects/mattermosts/_team_selection.html.haml
+6
-5
spec/features/projects/services/mattermost_slash_command_spec.rb
...atures/projects/services/mattermost_slash_command_spec.rb
+82
-3
No files found.
app/views/projects/mattermosts/_team_selection.html.haml
View file @
45485947
...
...
@@ -7,20 +7,21 @@
%p
=
@teams
.
one?
?
'The team'
:
'Select the team'
where the slash commands will be used in
-
selected_id
=
@teams
.
keys
.
first
if
@teams
.
one?
-
selected_id
=
@teams
.
one?
?
@teams
.
keys
.
first
:
0
-
options
=
mattermost_teams_options
(
@teams
)
-
options
=
options_for_select
(
options
,
selected_id
)
=
f
.
select
(
:team_id
,
options
,
{},
{
class:
'form-control'
,
selected:
"
#{
selected_id
}
"
})
=
f
.
select
(
:team_id
,
options
,
{},
{
class:
'form-control'
,
disabled:
@teams
.
one?
,
selected:
selected_id
})
=
f
.
hidden_field
(
:team_id
,
value:
selected_id
)
if
@teams
.
one?
.help-block
-
if
@teams
.
one?
This is the only
team where you are an administrator
.
This is the only
available team
.
-
else
The list shows teams where you are administrator
To create a team, ask your Mattermost system administrator.
The list shows all available teams.
To create a team,
=
link_to
"
#{
Gitlab
.
config
.
mattermost
.
host
}
/create_team"
do
use Mattermost's interface
=
icon
(
'external-link'
)
or ask your Mattermost system administrator.
%hr
%h4
Command trigger word
%p
Choose the word that will trigger commands
...
...
spec/features/projects/services/mattermost_slash_command_spec.rb
View file @
45485947
...
...
@@ -33,10 +33,89 @@ feature 'Setup Mattermost slash commands', feature: true do
expect
(
value
).
to
eq
(
token
)
end
describe
'mattermost service is enabled'
do
it
'shows the add to mattermost button'
do
expect
(
page
).
to
have_link
'Add to Mattermost'
it
'shows the add to mattermost button'
do
expect
(
page
).
to
have_link
(
'Add to Mattermost'
)
end
it
'shows an explanation if user is a member of no teams'
do
stub_teams
(
count:
0
)
click_link
'Add to Mattermost'
expect
(
page
).
to
have_content
(
'You aren’t a member of any team on the Mattermost instance'
)
expect
(
page
).
to
have_link
(
'join a team'
,
href:
"
#{
Gitlab
.
config
.
mattermost
.
host
}
/select_team"
)
end
it
'shows an explanation if user is a member of 1 team'
do
stub_teams
(
count:
1
)
click_link
'Add to Mattermost'
expect
(
page
).
to
have_content
(
'The team where the slash commands will be used in'
)
expect
(
page
).
to
have_content
(
'This is the only available team.'
)
end
it
'shows a disabled prefilled select if user is a member of 1 team'
do
teams
=
stub_teams
(
count:
1
)
click_link
'Add to Mattermost'
team_name
=
teams
.
first
[
1
][
'display_name'
]
select_element
=
find
(
'select#mattermost_team_id'
)
selected_option
=
select_element
.
find
(
'option[selected]'
)
expect
(
select_element
[
'disabled'
]).
to
be
(
true
)
expect
(
selected_option
).
to
have_content
(
team_name
.
to_s
)
end
it
'has a hidden input for the prefilled value if user is a member of 1 team'
do
teams
=
stub_teams
(
count:
1
)
click_link
'Add to Mattermost'
expect
(
find
(
'input#mattermost_team_id'
,
visible:
false
).
value
).
to
eq
(
teams
.
first
[
0
].
to_s
)
end
it
'shows an explanation user is a member of multiple teams'
do
stub_teams
(
count:
2
)
click_link
'Add to Mattermost'
expect
(
page
).
to
have_content
(
'Select the team where the slash commands will be used in'
)
expect
(
page
).
to
have_content
(
'The list shows all available teams.'
)
end
it
'shows a select with team options user is a member of multiple teams'
do
stub_teams
(
count:
2
)
click_link
'Add to Mattermost'
select_element
=
find
(
'select#mattermost_team_id'
)
selected_option
=
select_element
.
find
(
'option[selected]'
)
expect
(
select_element
[
'disabled'
]).
to
be
(
false
)
expect
(
selected_option
).
to
have_content
(
'Select team...'
)
# The 'Select team...' placeholder is item `0`.
expect
(
select_element
.
all
(
'option'
).
count
).
to
eq
(
3
)
end
def
stub_teams
(
count:
0
)
teams
=
create_teams
(
count
)
allow_any_instance_of
(
MattermostSlashCommandsService
).
to
receive
(
:list_teams
)
{
teams
}
teams
end
def
create_teams
(
count
=
0
)
teams
=
{}
count
.
times
do
|
i
|
i
+=
1
teams
[
i
]
=
{
id:
i
,
display_name:
i
}
end
teams
end
describe
'mattermost service is not enabled'
do
...
...
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