Skip to content
Snippets Groups Projects
Commit 34279614 authored by Miguel Rincon's avatar Miguel Rincon Committed by Enrique Alcántara
Browse files

Migrate usage CiRunner.active to CiRunner.paused

The "paused" field is preferred to "active" in the CiRunner GraphQL API
since 14.8, this change updates our queries to use it.
parent b7027a74
No related branches found
No related tags found
1 merge request!120878Migrate usage CiRunner.active to CiRunner.paused
Showing
with 45 additions and 55 deletions
......@@ -20,7 +20,7 @@ export default {
},
computed: {
paused() {
return !this.runner.active;
return this.runner.paused;
},
},
};
......
......@@ -25,9 +25,6 @@ export default {
},
},
computed: {
paused() {
return !this.runner.active;
},
heading() {
const id = getIdFromGraphQLId(this.runner.id);
return sprintf(I18N_DETAILS_TITLE, { runner_id: id });
......
<script>
import { GlButton, GlTooltipDirective } from '@gitlab/ui';
import runnerToggleActiveMutation from '~/ci/runner/graphql/shared/runner_toggle_active.mutation.graphql';
import runnerTogglePausedMutation from '~/ci/runner/graphql/shared/runner_toggle_paused.mutation.graphql';
import { createAlert } from '~/alert';
import { captureException } from '~/ci/runner/sentry_utils';
import { I18N_PAUSE, I18N_PAUSE_TOOLTIP, I18N_RESUME, I18N_RESUME_TOOLTIP } from '../constants';
......@@ -31,14 +31,14 @@ export default {
};
},
computed: {
isActive() {
return this.runner.active;
isPaused() {
return this.runner.paused;
},
icon() {
return this.isActive ? 'pause' : 'play';
return this.isPaused ? 'play' : 'pause';
},
label() {
return this.isActive ? I18N_PAUSE : I18N_RESUME;
return this.isPaused ? I18N_RESUME : I18N_PAUSE;
},
buttonContent() {
if (this.compact) {
......@@ -56,7 +56,7 @@ export default {
// Prevent a "sticky" tooltip: If this button is disabled,
// mouseout listeners don't run leaving the tooltip stuck
if (!this.updating) {
return this.isActive ? I18N_PAUSE_TOOLTIP : I18N_RESUME_TOOLTIP;
return this.isPaused ? I18N_RESUME_TOOLTIP : I18N_PAUSE_TOOLTIP;
}
return '';
},
......@@ -67,7 +67,7 @@ export default {
try {
const input = {
id: this.runner.id,
active: !this.isActive,
paused: !this.isPaused,
};
const {
......@@ -75,7 +75,7 @@ export default {
runnerUpdate: { errors },
},
} = await this.$apollo.mutate({
mutation: runnerToggleActiveMutation,
mutation: runnerTogglePausedMutation,
variables: {
input,
},
......
......@@ -134,12 +134,7 @@ export default {
</template>
<template v-else>
<div class="gl-mb-5">
<gl-form-checkbox
v-model="model.active"
data-testid="runner-field-paused"
:value="false"
:unchecked-value="true"
>
<gl-form-checkbox v-model="model.paused" data-testid="runner-field-paused">
{{ __('Paused') }}
<template #help>
{{ s__('Runners|Stop the runner from accepting new jobs.') }}
......
......@@ -2,7 +2,7 @@ fragment RunnerFieldsShared on CiRunner {
id
shortSha
runnerType
active
paused
accessLevel
runUntagged
locked
......
......@@ -7,7 +7,7 @@ fragment ListItemShared on CiRunner {
shortSha
version
ipAddress
active
paused
locked
jobCount
tagList
......
# Mutation executed for the pause/resume button in the
# runner list and details views.
mutation runnerToggleActive($input: RunnerUpdateInput!) {
mutation runnerTogglePaused($input: RunnerUpdateInput!) {
runnerUpdate(input: $input) {
runner {
id
active
paused
}
errors
}
......
......@@ -2,7 +2,7 @@ fragment RunnerDetailsShared on CiRunner {
id
shortSha
runnerType
active
paused
accessLevel
runUntagged
locked
......
......@@ -4,7 +4,7 @@ export const runnerToModel = (runner) => {
description,
maximumTimeout,
accessLevel,
active,
paused,
locked,
runUntagged,
tagList = [],
......@@ -15,7 +15,7 @@ export const runnerToModel = (runner) => {
description,
maximumTimeout,
accessLevel,
active,
paused,
locked,
runUntagged,
tagList: tagList.join(', '),
......
......@@ -24,7 +24,7 @@ describe('RunnerStatusCell', () => {
propsData: {
runner: {
runnerType: INSTANCE_TYPE,
active: true,
paused: false,
status: STATUS_ONLINE,
jobExecutionStatus: JOB_STATUS_IDLE,
...runner,
......@@ -59,7 +59,7 @@ describe('RunnerStatusCell', () => {
it('Displays paused status', () => {
createComponent({
runner: {
active: false,
paused: true,
status: STATUS_ONLINE,
},
});
......
......@@ -236,7 +236,7 @@ describe('RunnerDeleteButton', () => {
createComponent({
props: {
runner: {
active: true,
paused: false,
},
compact: true,
},
......
......@@ -18,7 +18,6 @@ import { I18N_PROJECT_TYPE, I18N_STATUS_NEVER_CONTACTED } from '~/ci/runner/cons
import { allRunnersData, onlineContactTimeoutSecs, staleTimeoutSecs } from '../mock_data';
const mockRunners = allRunnersData.data.runners.nodes;
const mockActiveRunnersCount = mockRunners.length;
describe('RunnerList', () => {
let wrapper;
......@@ -44,7 +43,6 @@ describe('RunnerList', () => {
apolloProvider: createMockApollo([], {}, cacheConfig),
propsData: {
runners: mockRunners,
activeRunnersCount: mockActiveRunnersCount,
...props,
},
provide: {
......
......@@ -4,7 +4,7 @@ import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import { shallowMountExtended, mountExtended } from 'helpers/vue_test_utils_helper';
import runnerToggleActiveMutation from '~/ci/runner/graphql/shared/runner_toggle_active.mutation.graphql';
import runnerTogglePausedMutation from '~/ci/runner/graphql/shared/runner_toggle_paused.mutation.graphql';
import waitForPromises from 'helpers/wait_for_promises';
import { captureException } from '~/ci/runner/sentry_utils';
import { createAlert } from '~/alert';
......@@ -27,7 +27,7 @@ jest.mock('~/ci/runner/sentry_utils');
describe('RunnerPauseButton', () => {
let wrapper;
let runnerToggleActiveHandler;
let runnerTogglePausedHandler;
const getTooltip = () => getBinding(wrapper.element, 'gl-tooltip').value;
const findBtn = () => wrapper.findComponent(GlButton);
......@@ -39,12 +39,12 @@ describe('RunnerPauseButton', () => {
propsData: {
runner: {
id: mockRunner.id,
active: mockRunner.active,
paused: mockRunner.paused,
...runner,
},
...propsData,
},
apolloProvider: createMockApollo([[runnerToggleActiveMutation, runnerToggleActiveHandler]]),
apolloProvider: createMockApollo([[runnerTogglePausedMutation, runnerTogglePausedHandler]]),
directives: {
GlTooltip: createMockDirective('gl-tooltip'),
},
......@@ -57,13 +57,13 @@ describe('RunnerPauseButton', () => {
};
beforeEach(() => {
runnerToggleActiveHandler = jest.fn().mockImplementation(({ input }) => {
runnerTogglePausedHandler = jest.fn().mockImplementation(({ input }) => {
return Promise.resolve({
data: {
runnerUpdate: {
runner: {
id: input.id,
active: input.active,
paused: !input.paused,
},
errors: [],
},
......@@ -76,15 +76,15 @@ describe('RunnerPauseButton', () => {
describe('Pause/Resume action', () => {
describe.each`
runnerState | icon | content | tooltip | isActive | newActiveValue
${'paused'} | ${'play'} | ${I18N_RESUME} | ${I18N_RESUME_TOOLTIP} | ${false} | ${true}
${'active'} | ${'pause'} | ${I18N_PAUSE} | ${I18N_PAUSE_TOOLTIP} | ${true} | ${false}
`('When the runner is $runnerState', ({ icon, content, tooltip, isActive, newActiveValue }) => {
runnerState | icon | content | tooltip | isPaused | newPausedValue
${'paused'} | ${'play'} | ${I18N_RESUME} | ${I18N_RESUME_TOOLTIP} | ${true} | ${false}
${'active'} | ${'pause'} | ${I18N_PAUSE} | ${I18N_PAUSE_TOOLTIP} | ${false} | ${true}
`('When the runner is $runnerState', ({ icon, content, tooltip, isPaused, newPausedValue }) => {
beforeEach(() => {
createComponent({
props: {
runner: {
active: isActive,
paused: isPaused,
},
},
});
......@@ -106,7 +106,7 @@ describe('RunnerPauseButton', () => {
describe(`Before the ${icon} button is clicked`, () => {
it('The mutation has not been called', () => {
expect(runnerToggleActiveHandler).toHaveBeenCalledTimes(0);
expect(runnerTogglePausedHandler).not.toHaveBeenCalled();
});
});
......@@ -134,12 +134,12 @@ describe('RunnerPauseButton', () => {
await clickAndWait();
});
it(`The mutation to that sets active to ${newActiveValue} is called`, () => {
expect(runnerToggleActiveHandler).toHaveBeenCalledTimes(1);
expect(runnerToggleActiveHandler).toHaveBeenCalledWith({
it(`The mutation to that sets "paused" to ${newPausedValue} is called`, () => {
expect(runnerTogglePausedHandler).toHaveBeenCalledTimes(1);
expect(runnerTogglePausedHandler).toHaveBeenCalledWith({
input: {
id: mockRunner.id,
active: newActiveValue,
paused: newPausedValue,
},
});
});
......@@ -158,7 +158,7 @@ describe('RunnerPauseButton', () => {
const mockErrorMsg = 'Update error!';
beforeEach(async () => {
runnerToggleActiveHandler.mockRejectedValueOnce(new Error(mockErrorMsg));
runnerTogglePausedHandler.mockRejectedValueOnce(new Error(mockErrorMsg));
await clickAndWait();
});
......@@ -180,12 +180,12 @@ describe('RunnerPauseButton', () => {
const mockErrorMsg2 = 'User not allowed!';
beforeEach(async () => {
runnerToggleActiveHandler.mockResolvedValueOnce({
runnerTogglePausedHandler.mockResolvedValueOnce({
data: {
runnerUpdate: {
runner: {
id: mockRunner.id,
active: isActive,
paused: isPaused,
},
errors: [mockErrorMsg, mockErrorMsg2],
},
......@@ -215,7 +215,7 @@ describe('RunnerPauseButton', () => {
createComponent({
props: {
runner: {
active: true,
paused: false,
},
compact: true,
},
......
......@@ -56,7 +56,7 @@ describe('RunnerUpdateForm', () => {
const submitFormAndWait = () => submitForm().then(waitForPromises);
const getFieldsModel = () => ({
active: !findPausedCheckbox().element.checked,
paused: findPausedCheckbox().element.checked,
accessLevel: findProtectedCheckbox().element.checked
? ACCESS_LEVEL_REF_PROTECTED
: ACCESS_LEVEL_NOT_PROTECTED,
......@@ -179,8 +179,8 @@ describe('RunnerUpdateForm', () => {
describe('On submit, runner gets updated', () => {
it.each`
test | initialValue | findCheckbox | checked | submitted
${'pauses'} | ${{ active: true }} | ${findPausedCheckbox} | ${true} | ${{ active: false }}
${'activates'} | ${{ active: false }} | ${findPausedCheckbox} | ${false} | ${{ active: true }}
${'pauses'} | ${{ paused: false }} | ${findPausedCheckbox} | ${true} | ${{ paused: true }}
${'activates'} | ${{ paused: true }} | ${findPausedCheckbox} | ${false} | ${{ paused: false }}
${'unprotects'} | ${{ accessLevel: ACCESS_LEVEL_NOT_PROTECTED }} | ${findProtectedCheckbox} | ${true} | ${{ accessLevel: ACCESS_LEVEL_REF_PROTECTED }}
${'protects'} | ${{ accessLevel: ACCESS_LEVEL_REF_PROTECTED }} | ${findProtectedCheckbox} | ${false} | ${{ accessLevel: ACCESS_LEVEL_NOT_PROTECTED }}
${'"runs untagged jobs"'} | ${{ runUntagged: true }} | ${findRunUntaggedCheckbox} | ${false} | ${{ runUntagged: false }}
......
......@@ -12,7 +12,7 @@ const mockRunner = {
description: mockDescription,
maximumTimeout: 100,
accessLevel: ACCESS_LEVEL_NOT_PROTECTED,
active: true,
paused: false,
locked: true,
runUntagged: true,
tagList: ['tag-1', 'tag-2'],
......@@ -79,7 +79,7 @@ describe('~/ci/runner/runner_update_form_utils', () => {
${',,,,, commas'} | ${['commas']}
${'more ,,,,, commas'} | ${['more', 'commas']}
${' trimmed , trimmed2 '} | ${['trimmed', 'trimmed2']}
`('collect tags separated by commas for "$value"', ({ tagList, tagListInput }) => {
`('collect comma-separated tags "$tagList" as $tagListInput', ({ tagList, tagListInput }) => {
const variables = modelToUpdateMutationVariables({
...mockModel,
tagList,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment