2022-05-04 15:09:12 +00:00
|
|
|
import { GlAlert } from '@gitlab/ui';
|
2020-10-08 15:08:17 +00:00
|
|
|
import MockAxiosAdapter from 'axios-mock-adapter';
|
2022-01-25 12:14:14 +00:00
|
|
|
import { nextTick } from 'vue';
|
2022-05-04 15:09:12 +00:00
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2020-10-08 15:08:17 +00:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
|
|
|
import SharedRunnersForm from '~/group_settings/components/shared_runners_form.vue';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
const UPDATE_PATH = '/test/update';
|
|
|
|
const RUNNER_ENABLED_VALUE = 'enabled';
|
|
|
|
const RUNNER_DISABLED_VALUE = 'disabled_and_unoverridable';
|
|
|
|
const RUNNER_ALLOW_OVERRIDE_VALUE = 'disabled_with_override';
|
2020-10-08 15:08:17 +00:00
|
|
|
|
|
|
|
describe('group_settings/components/shared_runners_form', () => {
|
|
|
|
let wrapper;
|
|
|
|
let mock;
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
const createComponent = (provide = {}) => {
|
|
|
|
wrapper = shallowMountExtended(SharedRunnersForm, {
|
2021-10-21 00:12:27 +00:00
|
|
|
provide: {
|
2022-05-04 15:09:12 +00:00
|
|
|
updatePath: UPDATE_PATH,
|
|
|
|
sharedRunnersSetting: RUNNER_ENABLED_VALUE,
|
|
|
|
parentSharedRunnersSetting: null,
|
|
|
|
runnerEnabledValue: RUNNER_ENABLED_VALUE,
|
|
|
|
runnerDisabledValue: RUNNER_DISABLED_VALUE,
|
|
|
|
runnerAllowOverrideValue: RUNNER_ALLOW_OVERRIDE_VALUE,
|
2021-10-21 00:12:27 +00:00
|
|
|
...provide,
|
2020-10-08 15:08:17 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
const findAlert = (variant) =>
|
|
|
|
wrapper
|
|
|
|
.findAllComponents(GlAlert)
|
|
|
|
.filter((w) => w.props('variant') === variant)
|
|
|
|
.at(0);
|
|
|
|
const findSharedRunnersToggle = () => wrapper.findByTestId('shared-runners-toggle');
|
|
|
|
const findOverrideToggle = () => wrapper.findByTestId('override-runners-toggle');
|
2021-10-21 00:12:27 +00:00
|
|
|
const getSharedRunnersSetting = () => JSON.parse(mock.history.put[0].data).shared_runners_setting;
|
2020-10-08 15:08:17 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAxiosAdapter(axios);
|
2022-05-04 15:09:12 +00:00
|
|
|
mock.onPut(UPDATE_PATH).reply(200);
|
2020-10-08 15:08:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
describe('default state', () => {
|
2020-10-08 15:08:17 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
it('"Enable shared runners" toggle is enabled', () => {
|
|
|
|
expect(findSharedRunnersToggle().props()).toMatchObject({
|
|
|
|
isLoading: false,
|
|
|
|
disabled: false,
|
|
|
|
});
|
2020-10-08 15:08:17 +00:00
|
|
|
});
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
it('"Override the group setting" is disabled', () => {
|
|
|
|
expect(findOverrideToggle().props()).toMatchObject({
|
|
|
|
isLoading: false,
|
|
|
|
disabled: true,
|
|
|
|
});
|
2020-10-08 15:08:17 +00:00
|
|
|
});
|
2022-05-04 15:09:12 +00:00
|
|
|
});
|
2020-10-08 15:08:17 +00:00
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
describe('When group disabled shared runners', () => {
|
|
|
|
it(`toggles are not disabled with setting ${RUNNER_DISABLED_VALUE}`, () => {
|
|
|
|
createComponent({ sharedRunnersSetting: RUNNER_DISABLED_VALUE });
|
|
|
|
|
|
|
|
expect(findSharedRunnersToggle().props('disabled')).toBe(false);
|
|
|
|
expect(findOverrideToggle().props('disabled')).toBe(false);
|
2020-10-08 15:08:17 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
describe('When parent group disabled shared runners', () => {
|
|
|
|
it('toggles are disabled', () => {
|
|
|
|
createComponent({
|
|
|
|
sharedRunnersSetting: RUNNER_DISABLED_VALUE,
|
|
|
|
parentSharedRunnersSetting: RUNNER_DISABLED_VALUE,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findSharedRunnersToggle().props('disabled')).toBe(true);
|
|
|
|
expect(findOverrideToggle().props('disabled')).toBe(true);
|
|
|
|
expect(findAlert('warning').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2020-10-08 15:08:17 +00:00
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
describe('loading state', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
2020-10-08 15:08:17 +00:00
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
it('is not loading by default', () => {
|
|
|
|
expect(findSharedRunnersToggle().props('isLoading')).toBe(false);
|
|
|
|
expect(findOverrideToggle().props('isLoading')).toBe(false);
|
|
|
|
});
|
2020-10-08 15:08:17 +00:00
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
it('is loading immediately after request', async () => {
|
|
|
|
findSharedRunnersToggle().vm.$emit('change', true);
|
2022-01-25 12:14:14 +00:00
|
|
|
await nextTick();
|
2020-10-08 15:08:17 +00:00
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
expect(findSharedRunnersToggle().props('isLoading')).toBe(true);
|
|
|
|
expect(findOverrideToggle().props('isLoading')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not update settings while loading', async () => {
|
|
|
|
findSharedRunnersToggle().vm.$emit('change', true);
|
|
|
|
findSharedRunnersToggle().vm.$emit('change', false);
|
|
|
|
await waitForPromises();
|
2020-10-08 15:08:17 +00:00
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
expect(mock.history.put.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is not loading state after completed request', async () => {
|
|
|
|
findSharedRunnersToggle().vm.$emit('change', true);
|
2020-10-08 15:08:17 +00:00
|
|
|
await waitForPromises();
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
expect(findSharedRunnersToggle().props('isLoading')).toBe(false);
|
|
|
|
expect(findOverrideToggle().props('isLoading')).toBe(false);
|
2020-10-08 15:08:17 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
describe('"Enable shared runners" toggle', () => {
|
2020-10-08 15:08:17 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
it('sends correct payload when turned on', async () => {
|
|
|
|
findSharedRunnersToggle().vm.$emit('change', true);
|
2020-10-08 15:08:17 +00:00
|
|
|
await waitForPromises();
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
expect(getSharedRunnersSetting()).toEqual(RUNNER_ENABLED_VALUE);
|
|
|
|
expect(findOverrideToggle().props('disabled')).toBe(true);
|
2020-10-08 15:08:17 +00:00
|
|
|
});
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
it('sends correct payload when turned off', async () => {
|
|
|
|
findSharedRunnersToggle().vm.$emit('change', false);
|
2020-10-08 15:08:17 +00:00
|
|
|
await waitForPromises();
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
expect(getSharedRunnersSetting()).toEqual(RUNNER_DISABLED_VALUE);
|
|
|
|
expect(findOverrideToggle().props('disabled')).toBe(false);
|
2020-10-08 15:08:17 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
describe('"Override the group setting" toggle', () => {
|
2020-10-08 15:08:17 +00:00
|
|
|
beforeEach(() => {
|
2022-05-04 15:09:12 +00:00
|
|
|
createComponent({ sharedRunnersSetting: RUNNER_ALLOW_OVERRIDE_VALUE });
|
2020-10-08 15:08:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('enabling the override toggle sends correct payload', async () => {
|
|
|
|
findOverrideToggle().vm.$emit('change', true);
|
|
|
|
await waitForPromises();
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
expect(getSharedRunnersSetting()).toEqual(RUNNER_ALLOW_OVERRIDE_VALUE);
|
2020-10-08 15:08:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('disabling the override toggle sends correct payload', async () => {
|
|
|
|
findOverrideToggle().vm.$emit('change', false);
|
|
|
|
await waitForPromises();
|
|
|
|
|
2022-05-04 15:09:12 +00:00
|
|
|
expect(getSharedRunnersSetting()).toEqual(RUNNER_DISABLED_VALUE);
|
2020-10-08 15:08:17 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe.each`
|
|
|
|
errorObj | message
|
|
|
|
${{}} | ${'An error occurred while updating configuration. Refresh the page and try again.'}
|
|
|
|
${{ error: 'Undefined error' }} | ${'Undefined error Refresh the page and try again.'}
|
|
|
|
`(`with error $errorObj`, ({ errorObj, message }) => {
|
|
|
|
beforeEach(async () => {
|
2022-05-04 15:09:12 +00:00
|
|
|
mock.onPut(UPDATE_PATH).reply(500, errorObj);
|
2020-10-08 15:08:17 +00:00
|
|
|
|
|
|
|
createComponent();
|
2022-05-04 15:09:12 +00:00
|
|
|
findSharedRunnersToggle().vm.$emit('change', false);
|
2020-10-08 15:08:17 +00:00
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('error should be shown', () => {
|
2022-05-04 15:09:12 +00:00
|
|
|
expect(findAlert('danger').text()).toBe(message);
|
2020-10-08 15:08:17 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|