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
c5e725e6
Commit
c5e725e6
authored
Oct 20, 2021
by
Doug Stull
Committed by
James Fargher
Oct 20, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use shared runners constants from the backend for the frontend
parent
f5b128eb
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
67 deletions
+81
-67
app/assets/javascripts/group_settings/components/shared_runners_form.vue
...scripts/group_settings/components/shared_runners_form.vue
+14
-27
app/assets/javascripts/group_settings/constants.js
app/assets/javascripts/group_settings/constants.js
+0
-5
app/assets/javascripts/group_settings/mount_shared_runners.js
...assets/javascripts/group_settings/mount_shared_runners.js
+17
-1
app/helpers/ci/runners_helper.rb
app/helpers/ci/runners_helper.rb
+4
-1
spec/frontend/group_settings/components/shared_runners_form_spec.js
...end/group_settings/components/shared_runners_form_spec.js
+24
-23
spec/helpers/ci/runners_helper_spec.rb
spec/helpers/ci/runners_helper_spec.rb
+22
-10
No files found.
app/assets/javascripts/group_settings/components/shared_runners_form.vue
View file @
c5e725e6
...
...
@@ -3,13 +3,7 @@ import { GlToggle, GlLoadingIcon, GlTooltip, GlAlert } from '@gitlab/ui';
import
{
debounce
}
from
'
lodash
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
{
__
}
from
'
~/locale
'
;
import
{
DEBOUNCE_TOGGLE_DELAY
,
ERROR_MESSAGE
,
ENABLED
,
DISABLED
,
ALLOW_OVERRIDE
,
}
from
'
../constants
'
;
import
{
DEBOUNCE_TOGGLE_DELAY
,
ERROR_MESSAGE
}
from
'
../constants
'
;
export
default
{
components
:
{
...
...
@@ -18,21 +12,14 @@ export default {
GlTooltip
,
GlAlert
,
},
props
:
{
updatePath
:
{
type
:
String
,
required
:
true
,
},
sharedRunnersAvailability
:
{
type
:
String
,
required
:
true
,
},
parentSharedRunnersAvailability
:
{
type
:
String
,
required
:
false
,
default
:
''
,
},
},
inject
:
[
'
updatePath
'
,
'
sharedRunnersAvailability
'
,
'
parentSharedRunnersAvailability
'
,
'
runnerEnabled
'
,
'
runnerDisabled
'
,
'
runnerAllowOverride
'
,
],
data
()
{
return
{
isLoading
:
false
,
...
...
@@ -43,21 +30,21 @@ export default {
},
computed
:
{
toggleDisabled
()
{
return
this
.
parentSharedRunnersAvailability
===
DISABLED
||
this
.
isLoading
;
return
this
.
parentSharedRunnersAvailability
===
this
.
runnerDisabled
||
this
.
isLoading
;
},
enabledOrDisabledSetting
()
{
return
this
.
enabled
?
ENABLED
:
DISABLED
;
return
this
.
enabled
?
this
.
runnerEnabled
:
this
.
runnerDisabled
;
},
disabledWithOverrideSetting
()
{
return
this
.
allowOverride
?
ALLOW_OVERRIDE
:
DISABLED
;
return
this
.
allowOverride
?
this
.
runnerAllowOverride
:
this
.
runnerDisabled
;
},
},
created
()
{
if
(
this
.
sharedRunnersAvailability
!==
ENABLED
)
{
if
(
this
.
sharedRunnersAvailability
!==
this
.
runnerEnabled
)
{
this
.
enabled
=
false
;
}
if
(
this
.
sharedRunnersAvailability
===
ALLOW_OVERRIDE
)
{
if
(
this
.
sharedRunnersAvailability
===
this
.
runnerAllowOverride
)
{
this
.
allowOverride
=
true
;
}
},
...
...
app/assets/javascripts/group_settings/constants.js
View file @
c5e725e6
...
...
@@ -4,8 +4,3 @@ import { __ } from '~/locale';
export
const
DEBOUNCE_TOGGLE_DELAY
=
1000
;
export
const
ERROR_MESSAGE
=
__
(
'
Refresh the page and try again.
'
);
// runner setting options
export
const
ENABLED
=
'
enabled
'
;
export
const
DISABLED
=
'
disabled_and_unoverridable
'
;
export
const
ALLOW_OVERRIDE
=
'
disabled_with_override
'
;
app/assets/javascripts/group_settings/mount_shared_runners.js
View file @
c5e725e6
...
...
@@ -4,11 +4,27 @@ import UpdateSharedRunnersForm from './components/shared_runners_form.vue';
export
default
(
containerId
=
'
update-shared-runners-form
'
)
=>
{
const
containerEl
=
document
.
getElementById
(
containerId
);
const
{
updatePath
,
sharedRunnersAvailability
,
parentSharedRunnersAvailability
,
runnerEnabled
,
runnerDisabled
,
runnerAllowOverride
,
}
=
containerEl
.
dataset
;
return
new
Vue
({
el
:
containerEl
,
render
(
createElement
)
{
return
createElement
(
UpdateSharedRunnersForm
,
{
props
:
containerEl
.
dataset
,
provide
:
{
updatePath
,
sharedRunnersAvailability
,
parentSharedRunnersAvailability
,
runnerEnabled
,
runnerDisabled
,
runnerAllowOverride
,
},
});
},
});
...
...
app/helpers/ci/runners_helper.rb
View file @
c5e725e6
...
...
@@ -61,7 +61,10 @@ module Ci
{
update_path:
api_v4_groups_path
(
id:
group
.
id
),
shared_runners_availability:
group
.
shared_runners_setting
,
parent_shared_runners_availability:
group
.
parent
&
.
shared_runners_setting
parent_shared_runners_availability:
group
.
parent
&
.
shared_runners_setting
,
runner_enabled:
Namespace
::
SR_ENABLED
,
runner_disabled:
Namespace
::
SR_DISABLED_AND_UNOVERRIDABLE
,
runner_allow_override:
Namespace
::
SR_DISABLED_WITH_OVERRIDE
}
end
...
...
spec/frontend/group_settings/components/shared_runners_form_spec.js
View file @
c5e725e6
...
...
@@ -3,13 +3,16 @@ import { shallowMount } from '@vue/test-utils';
import
MockAxiosAdapter
from
'
axios-mock-adapter
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
SharedRunnersForm
from
'
~/group_settings/components/shared_runners_form.vue
'
;
import
{
ENABLED
,
DISABLED
,
ALLOW_OVERRIDE
}
from
'
~/group_settings/constants
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
const
TEST_UPDATE_PATH
=
'
/test/update
'
;
const
DISABLED_PAYLOAD
=
{
shared_runners_setting
:
DISABLED
};
const
ENABLED_PAYLOAD
=
{
shared_runners_setting
:
ENABLED
};
const
OVERRIDE_PAYLOAD
=
{
shared_runners_setting
:
ALLOW_OVERRIDE
};
const
provide
=
{
updatePath
:
'
/test/update
'
,
sharedRunnersAvailability
:
'
enabled
'
,
parentSharedRunnersAvailability
:
null
,
runnerDisabled
:
'
disabled
'
,
runnerEnabled
:
'
enabled
'
,
runnerAllowOverride
:
'
allow_override
'
,
};
jest
.
mock
(
'
~/flash
'
);
...
...
@@ -17,13 +20,11 @@ describe('group_settings/components/shared_runners_form', () => {
let
wrapper
;
let
mock
;
const
createComponent
=
(
pro
p
s
=
{})
=>
{
const
createComponent
=
(
pro
vide
s
=
{})
=>
{
wrapper
=
shallowMount
(
SharedRunnersForm
,
{
propsData
:
{
updatePath
:
TEST_UPDATE_PATH
,
sharedRunnersAvailability
:
ENABLED
,
parentSharedRunnersAvailability
:
null
,
...
props
,
provide
:
{
...
provide
,
...
provides
,
},
});
};
...
...
@@ -33,13 +34,13 @@ describe('group_settings/components/shared_runners_form', () => {
const
findEnabledToggle
=
()
=>
wrapper
.
find
(
'
[data-testid="enable-runners-toggle"]
'
);
const
findOverrideToggle
=
()
=>
wrapper
.
find
(
'
[data-testid="override-runners-toggle"]
'
);
const
changeToggle
=
(
toggle
)
=>
toggle
.
vm
.
$emit
(
'
change
'
,
!
toggle
.
props
(
'
value
'
));
const
get
RequestPayload
=
()
=>
JSON
.
parse
(
mock
.
history
.
put
[
0
].
data
)
;
const
get
SharedRunnersSetting
=
()
=>
JSON
.
parse
(
mock
.
history
.
put
[
0
].
data
).
shared_runners_setting
;
const
isLoadingIconVisible
=
()
=>
findLoadingIcon
().
exists
();
beforeEach
(()
=>
{
mock
=
new
MockAxiosAdapter
(
axios
);
mock
.
onPut
(
TEST_UPDATE_PATH
).
reply
(
200
);
mock
.
onPut
(
provide
.
updatePath
).
reply
(
200
);
});
afterEach
(()
=>
{
...
...
@@ -95,7 +96,7 @@ describe('group_settings/components/shared_runners_form', () => {
await
waitForPromises
();
expect
(
get
RequestPayload
()).
toEqual
(
ENABLED_PAYLOAD
);
expect
(
get
SharedRunnersSetting
()).
toEqual
(
provide
.
runnerEnabled
);
expect
(
findOverrideToggle
().
exists
()).
toBe
(
false
);
});
...
...
@@ -104,14 +105,14 @@ describe('group_settings/components/shared_runners_form', () => {
await
waitForPromises
();
expect
(
get
RequestPayload
()).
toEqual
(
DISABLED_PAYLOAD
);
expect
(
get
SharedRunnersSetting
()).
toEqual
(
provide
.
runnerDisabled
);
expect
(
findOverrideToggle
().
exists
()).
toBe
(
true
);
});
});
describe
(
'
override toggle
'
,
()
=>
{
beforeEach
(()
=>
{
createComponent
({
sharedRunnersAvailability
:
ALLOW_OVERRIDE
});
createComponent
({
sharedRunnersAvailability
:
provide
.
runnerAllowOverride
});
});
it
(
'
enabling the override toggle sends correct payload
'
,
async
()
=>
{
...
...
@@ -119,7 +120,7 @@ describe('group_settings/components/shared_runners_form', () => {
await
waitForPromises
();
expect
(
get
RequestPayload
()).
toEqual
(
OVERRIDE_PAYLOAD
);
expect
(
get
SharedRunnersSetting
()).
toEqual
(
provide
.
runnerAllowOverride
);
});
it
(
'
disabling the override toggle sends correct payload
'
,
async
()
=>
{
...
...
@@ -127,21 +128,21 @@ describe('group_settings/components/shared_runners_form', () => {
await
waitForPromises
();
expect
(
get
RequestPayload
()).
toEqual
(
DISABLED_PAYLOAD
);
expect
(
get
SharedRunnersSetting
()).
toEqual
(
provide
.
runnerDisabled
);
});
});
describe
(
'
toggle disabled state
'
,
()
=>
{
it
(
`toggles are not disabled with setting
${
DISABLED
}
`
,
()
=>
{
createComponent
({
sharedRunnersAvailability
:
DISABLED
});
it
(
`toggles are not disabled with setting
${
provide
.
runnerDisabled
}
`
,
()
=>
{
createComponent
({
sharedRunnersAvailability
:
provide
.
runnerDisabled
});
expect
(
findEnabledToggle
().
props
(
'
disabled
'
)).
toBe
(
false
);
expect
(
findOverrideToggle
().
props
(
'
disabled
'
)).
toBe
(
false
);
});
it
(
'
toggles are disabled
'
,
()
=>
{
createComponent
({
sharedRunnersAvailability
:
DISABLED
,
parentSharedRunnersAvailability
:
DISABLED
,
sharedRunnersAvailability
:
provide
.
runnerDisabled
,
parentSharedRunnersAvailability
:
provide
.
runnerDisabled
,
});
expect
(
findEnabledToggle
().
props
(
'
disabled
'
)).
toBe
(
true
);
expect
(
findOverrideToggle
().
props
(
'
disabled
'
)).
toBe
(
true
);
...
...
@@ -154,7 +155,7 @@ describe('group_settings/components/shared_runners_form', () => {
${{
error
:
'
Undefined error
'
}
} |
${
'
Undefined error Refresh the page and try again.
'
}
`
(
`with error $errorObj`
,
({
errorObj
,
message
})
=>
{
beforeEach
(
async
()
=>
{
mock
.
onPut
(
TEST_UPDATE_PATH
).
reply
(
500
,
errorObj
);
mock
.
onPut
(
provide
.
updatePath
).
reply
(
500
,
errorObj
);
createComponent
();
changeToggle
(
findEnabledToggle
());
...
...
spec/helpers/ci/runners_helper_spec.rb
View file @
c5e725e6
...
...
@@ -68,23 +68,35 @@ RSpec.describe Ci::RunnersHelper do
end
describe
'#group_shared_runners_settings_data'
do
let
(
:group
)
{
create
(
:group
,
parent:
parent
,
shared_runners_enabled:
false
)
}
let
(
:parent
)
{
create
(
:group
)
}
let_it_be
(
:parent
)
{
create
(
:group
)
}
let_it_be
(
:group
)
{
create
(
:group
,
parent:
parent
,
shared_runners_enabled:
false
)
}
let
(
:runner_constants
)
do
{
runner_enabled:
Namespace
::
SR_ENABLED
,
runner_disabled:
Namespace
::
SR_DISABLED_AND_UNOVERRIDABLE
,
runner_allow_override:
Namespace
::
SR_DISABLED_WITH_OVERRIDE
}
end
it
'returns group data for top level group'
do
data
=
group_shared_runners_settings_data
(
parent
)
result
=
{
update_path:
"/api/v4/groups/
#{
parent
.
id
}
"
,
shared_runners_availability:
Namespace
::
SR_ENABLED
,
parent_shared_runners_availability:
nil
}.
merge
(
runner_constants
)
expect
(
data
[
:update_path
]).
to
eq
(
"/api/v4/groups/
#{
parent
.
id
}
"
)
expect
(
data
[
:shared_runners_availability
]).
to
eq
(
'enabled'
)
expect
(
data
[
:parent_shared_runners_availability
]).
to
eq
(
nil
)
expect
(
group_shared_runners_settings_data
(
parent
)).
to
eq
result
end
it
'returns group data for child group'
do
data
=
group_shared_runners_settings_data
(
group
)
result
=
{
update_path:
"/api/v4/groups/
#{
group
.
id
}
"
,
shared_runners_availability:
Namespace
::
SR_DISABLED_AND_UNOVERRIDABLE
,
parent_shared_runners_availability:
Namespace
::
SR_ENABLED
}.
merge
(
runner_constants
)
expect
(
data
[
:update_path
]).
to
eq
(
"/api/v4/groups/
#{
group
.
id
}
"
)
expect
(
data
[
:shared_runners_availability
]).
to
eq
(
Namespace
::
SR_DISABLED_AND_UNOVERRIDABLE
)
expect
(
data
[
:parent_shared_runners_availability
]).
to
eq
(
'enabled'
)
expect
(
group_shared_runners_settings_data
(
group
)).
to
eq
result
end
end
...
...
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