Commit 07426ad0 authored by Justin Ho Tuan Duong's avatar Justin Ho Tuan Duong Committed by Phil Hughes

Change ActiveToggle to ActiveCheckbox

Use GlFormCheckbox instead of GlToggle for setting
of "Active" integration.
parent 0245dd44
<script> <script>
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { GlFormGroup, GlToggle } from '@gitlab/ui'; import { GlFormGroup, GlFormCheckbox } from '@gitlab/ui';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
export default { export default {
name: 'ActiveToggle', name: 'ActiveCheckbox',
components: { components: {
GlFormGroup, GlFormGroup,
GlToggle, GlFormCheckbox,
},
props: {
initialActivated: {
type: Boolean,
required: true,
},
}, },
data() { data() {
return { return {
activated: this.initialActivated, activated: false,
}; };
}, },
computed: { computed: {
...mapGetters(['isInheriting']), ...mapGetters(['isInheriting', 'propsSource']),
}, },
mounted() { mounted() {
this.activated = this.propsSource.initialActivated;
// Initialize view // Initialize view
this.$nextTick(() => { this.$nextTick(() => {
this.onToggle(this.activated); this.onChange(this.activated);
}); });
}, },
methods: { methods: {
onToggle(e) { onChange(e) {
eventHub.$emit('toggle', e); eventHub.$emit('toggle', e);
}, },
}, },
...@@ -39,12 +34,15 @@ export default { ...@@ -39,12 +34,15 @@ export default {
<template> <template>
<gl-form-group :label="__('Enable integration')" label-for="service[active]"> <gl-form-group :label="__('Enable integration')" label-for="service[active]">
<gl-toggle <input name="service[active]" type="hidden" :value="activated || false" />
<gl-form-checkbox
v-model="activated" v-model="activated"
name="service[active]" name="service[active]"
class="gl-display-block gl-line-height-0" class="gl-display-block gl-line-height-0"
:disabled="isInheriting" :disabled="isInheriting"
@change="onToggle" @change="onChange"
/> >
{{ __('Active') }}
</gl-form-checkbox>
</gl-form-group> </gl-form-group>
</template> </template>
...@@ -3,7 +3,7 @@ import { mapState, mapActions, mapGetters } from 'vuex'; ...@@ -3,7 +3,7 @@ import { mapState, mapActions, mapGetters } from 'vuex';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import OverrideDropdown from './override_dropdown.vue'; import OverrideDropdown from './override_dropdown.vue';
import ActiveToggle from './active_toggle.vue'; import ActiveCheckbox from './active_checkbox.vue';
import JiraTriggerFields from './jira_trigger_fields.vue'; import JiraTriggerFields from './jira_trigger_fields.vue';
import JiraIssuesFields from './jira_issues_fields.vue'; import JiraIssuesFields from './jira_issues_fields.vue';
import TriggerFields from './trigger_fields.vue'; import TriggerFields from './trigger_fields.vue';
...@@ -13,7 +13,7 @@ export default { ...@@ -13,7 +13,7 @@ export default {
name: 'IntegrationForm', name: 'IntegrationForm',
components: { components: {
OverrideDropdown, OverrideDropdown,
ActiveToggle, ActiveCheckbox,
JiraTriggerFields, JiraTriggerFields,
JiraIssuesFields, JiraIssuesFields,
TriggerFields, TriggerFields,
...@@ -44,11 +44,7 @@ export default { ...@@ -44,11 +44,7 @@ export default {
:override="override" :override="override"
@change="setOverride" @change="setOverride"
/> />
<active-toggle <active-checkbox v-if="propsSource.showActive" :key="`${currentKey}-active-checkbox`" />
v-if="propsSource.showActive"
:key="`${currentKey}-active-toggle`"
v-bind="propsSource.activeToggleProps"
/>
<jira-trigger-fields <jira-trigger-fields
v-if="isJira" v-if="isJira"
:key="`${currentKey}-jira-trigger-fields`" :key="`${currentKey}-jira-trigger-fields`"
......
...@@ -35,9 +35,7 @@ function parseDatasetToProps(data) { ...@@ -35,9 +35,7 @@ function parseDatasetToProps(data) {
} = parseBooleanInData(booleanAttributes); } = parseBooleanInData(booleanAttributes);
return { return {
activeToggleProps: {
initialActivated: activated, initialActivated: activated,
},
showActive, showActive,
type, type,
triggerFieldsProps: { triggerFieldsProps: {
......
---
title: Change active toggle on integration settings page to checkbox
merge_request: 39586
author:
type: changed
...@@ -525,6 +525,7 @@ RSpec.describe 'Admin updates settings', :clean_gitlab_redis_shared_state, :do_n ...@@ -525,6 +525,7 @@ RSpec.describe 'Admin updates settings', :clean_gitlab_redis_shared_state, :do_n
end end
def check_all_events def check_all_events
page.check('Active')
page.check('Push') page.check('Push')
page.check('Issue') page.check('Issue')
page.check('Confidential Issue') page.check('Confidential Issue')
......
...@@ -8,7 +8,7 @@ RSpec.describe 'User activates issue tracker', :js do ...@@ -8,7 +8,7 @@ RSpec.describe 'User activates issue tracker', :js do
let(:url) { 'http://tracker.example.com' } let(:url) { 'http://tracker.example.com' }
def fill_form(disable: false, skip_new_issue_url: false) def fill_form(disable: false, skip_new_issue_url: false)
click_active_toggle if disable click_active_checkbox if disable
fill_in 'service_project_url', with: url fill_in 'service_project_url', with: url
fill_in 'service_issues_url', with: "#{url}/:id" fill_in 'service_issues_url', with: "#{url}/:id"
......
...@@ -28,7 +28,7 @@ RSpec.describe 'Set up Mattermost slash commands', :js do ...@@ -28,7 +28,7 @@ RSpec.describe 'Set up Mattermost slash commands', :js do
token = ('a'..'z').to_a.join token = ('a'..'z').to_a.join
fill_in 'service_token', with: token fill_in 'service_token', with: token
click_active_toggle click_active_checkbox
click_on 'Save changes' click_on 'Save changes'
expect(current_path).to eq(edit_project_service_path(project, :mattermost_slash_commands)) expect(current_path).to eq(edit_project_service_path(project, :mattermost_slash_commands))
......
...@@ -21,7 +21,7 @@ RSpec.describe 'Slack slash commands', :js do ...@@ -21,7 +21,7 @@ RSpec.describe 'Slack slash commands', :js do
it 'redirects to the integrations page after saving but not activating' do it 'redirects to the integrations page after saving but not activating' do
fill_in 'Token', with: 'token' fill_in 'Token', with: 'token'
click_active_toggle click_active_checkbox
click_on 'Save' click_on 'Save'
expect(current_path).to eq(edit_project_service_path(project, :slack_slash_commands)) expect(current_path).to eq(edit_project_service_path(project, :slack_slash_commands))
......
import { mount } from '@vue/test-utils';
import { GlFormCheckbox } from '@gitlab/ui';
import { createStore } from '~/integrations/edit/store';
import ActiveCheckbox from '~/integrations/edit/components/active_checkbox.vue';
describe('ActiveCheckbox', () => {
let wrapper;
const createComponent = (customStateProps = {}, isInheriting = false) => {
wrapper = mount(ActiveCheckbox, {
store: createStore({
customState: { ...customStateProps },
}),
computed: {
isInheriting: () => isInheriting,
},
});
};
afterEach(() => {
if (wrapper) {
wrapper.destroy();
wrapper = null;
}
});
const findGlFormCheckbox = () => wrapper.find(GlFormCheckbox);
const findInputInCheckbox = () => findGlFormCheckbox().find('input');
describe('template', () => {
describe('is inheriting adminSettings', () => {
it('renders GlFormCheckbox as disabled', () => {
createComponent({}, true);
expect(findGlFormCheckbox().exists()).toBe(true);
expect(findInputInCheckbox().attributes('disabled')).toBe('disabled');
});
});
describe('initialActivated is false', () => {
it('renders GlFormCheckbox as unchecked', () => {
createComponent({
initialActivated: false,
});
expect(findGlFormCheckbox().exists()).toBe(true);
expect(findGlFormCheckbox().vm.$attrs.checked).toBe(false);
expect(findInputInCheckbox().attributes('disabled')).toBeUndefined();
});
});
describe('initialActivated is true', () => {
beforeEach(() => {
createComponent({
initialActivated: true,
});
});
it('renders GlFormCheckbox as checked', () => {
expect(findGlFormCheckbox().exists()).toBe(true);
expect(findGlFormCheckbox().vm.$attrs.checked).toBe(true);
});
describe('on checkbox click', () => {
it('switches the form value', async () => {
findInputInCheckbox().trigger('click');
await wrapper.vm.$nextTick();
expect(findGlFormCheckbox().vm.$attrs.checked).toBe(false);
});
});
});
});
});
import { mount } from '@vue/test-utils';
import { GlToggle } from '@gitlab/ui';
import ActiveToggle from '~/integrations/edit/components/active_toggle.vue';
const GL_TOGGLE_ACTIVE_CLASS = 'is-checked';
const GL_TOGGLE_DISABLED_CLASS = 'is-disabled';
describe('ActiveToggle', () => {
let wrapper;
const defaultProps = {
initialActivated: true,
};
const createComponent = (props = {}, isInheriting = false) => {
wrapper = mount(ActiveToggle, {
propsData: { ...defaultProps, ...props },
computed: {
isInheriting: () => isInheriting,
},
});
};
afterEach(() => {
if (wrapper) {
wrapper.destroy();
wrapper = null;
}
});
const findGlToggle = () => wrapper.find(GlToggle);
const findButtonInToggle = () => findGlToggle().find('button');
const findInputInToggle = () => findGlToggle().find('input');
describe('template', () => {
describe('is inheriting adminSettings', () => {
it('renders GlToggle as disabled', () => {
createComponent({}, true);
expect(findGlToggle().exists()).toBe(true);
expect(findButtonInToggle().classes()).toContain(GL_TOGGLE_DISABLED_CLASS);
});
});
describe('initialActivated is false', () => {
it('renders GlToggle as inactive', () => {
createComponent({
initialActivated: false,
});
expect(findGlToggle().exists()).toBe(true);
expect(findButtonInToggle().classes()).not.toContain(GL_TOGGLE_ACTIVE_CLASS);
expect(findInputInToggle().attributes('value')).toBe('false');
});
});
describe('initialActivated is true', () => {
beforeEach(() => {
createComponent();
});
it('renders GlToggle as active', () => {
expect(findGlToggle().exists()).toBe(true);
expect(findButtonInToggle().classes()).toContain(GL_TOGGLE_ACTIVE_CLASS);
expect(findInputInToggle().attributes('value')).toBe('true');
});
describe('on toggle click', () => {
it('switches the form value', () => {
findButtonInToggle().trigger('click');
wrapper.vm.$nextTick(() => {
expect(findButtonInToggle().classes()).not.toContain(GL_TOGGLE_ACTIVE_CLASS);
expect(findInputInToggle().attributes('value')).toBe('false');
});
});
});
});
});
});
...@@ -3,7 +3,7 @@ import { mockIntegrationProps } from 'jest/integrations/edit/mock_data'; ...@@ -3,7 +3,7 @@ import { mockIntegrationProps } from 'jest/integrations/edit/mock_data';
import { createStore } from '~/integrations/edit/store'; import { createStore } from '~/integrations/edit/store';
import IntegrationForm from '~/integrations/edit/components/integration_form.vue'; import IntegrationForm from '~/integrations/edit/components/integration_form.vue';
import OverrideDropdown from '~/integrations/edit/components/override_dropdown.vue'; import OverrideDropdown from '~/integrations/edit/components/override_dropdown.vue';
import ActiveToggle from '~/integrations/edit/components/active_toggle.vue'; import ActiveCheckbox from '~/integrations/edit/components/active_checkbox.vue';
import JiraTriggerFields from '~/integrations/edit/components/jira_trigger_fields.vue'; import JiraTriggerFields from '~/integrations/edit/components/jira_trigger_fields.vue';
import JiraIssuesFields from '~/integrations/edit/components/jira_issues_fields.vue'; import JiraIssuesFields from '~/integrations/edit/components/jira_issues_fields.vue';
import TriggerFields from '~/integrations/edit/components/trigger_fields.vue'; import TriggerFields from '~/integrations/edit/components/trigger_fields.vue';
...@@ -21,7 +21,7 @@ describe('IntegrationForm', () => { ...@@ -21,7 +21,7 @@ describe('IntegrationForm', () => {
}), }),
stubs: { stubs: {
OverrideDropdown, OverrideDropdown,
ActiveToggle, ActiveCheckbox,
JiraTriggerFields, JiraTriggerFields,
TriggerFields, TriggerFields,
}, },
...@@ -39,27 +39,27 @@ describe('IntegrationForm', () => { ...@@ -39,27 +39,27 @@ describe('IntegrationForm', () => {
}); });
const findOverrideDropdown = () => wrapper.find(OverrideDropdown); const findOverrideDropdown = () => wrapper.find(OverrideDropdown);
const findActiveToggle = () => wrapper.find(ActiveToggle); const findActiveCheckbox = () => wrapper.find(ActiveCheckbox);
const findJiraTriggerFields = () => wrapper.find(JiraTriggerFields); const findJiraTriggerFields = () => wrapper.find(JiraTriggerFields);
const findJiraIssuesFields = () => wrapper.find(JiraIssuesFields); const findJiraIssuesFields = () => wrapper.find(JiraIssuesFields);
const findTriggerFields = () => wrapper.find(TriggerFields); const findTriggerFields = () => wrapper.find(TriggerFields);
describe('template', () => { describe('template', () => {
describe('showActive is true', () => { describe('showActive is true', () => {
it('renders ActiveToggle', () => { it('renders ActiveCheckbox', () => {
createComponent(); createComponent();
expect(findActiveToggle().exists()).toBe(true); expect(findActiveCheckbox().exists()).toBe(true);
}); });
}); });
describe('showActive is false', () => { describe('showActive is false', () => {
it('does not render ActiveToggle', () => { it('does not render ActiveCheckbox', () => {
createComponent({ createComponent({
showActive: false, showActive: false,
}); });
expect(findActiveToggle().exists()).toBe(false); expect(findActiveCheckbox().exists()).toBe(false);
}); });
}); });
......
// eslint-disable-next-line import/prefer-default-export // eslint-disable-next-line import/prefer-default-export
export const mockIntegrationProps = { export const mockIntegrationProps = {
id: 25, id: 25,
activeToggleProps: {
initialActivated: true, initialActivated: true,
},
showActive: true, showActive: true,
triggerFieldsProps: { triggerFieldsProps: {
initialTriggerCommit: false, initialTriggerCommit: false,
......
...@@ -5,7 +5,7 @@ RSpec.shared_context 'project service Jira context' do ...@@ -5,7 +5,7 @@ RSpec.shared_context 'project service Jira context' do
let(:test_url) { 'http://jira.example.com/rest/api/2/serverInfo' } let(:test_url) { 'http://jira.example.com/rest/api/2/serverInfo' }
def fill_form(disable: false) def fill_form(disable: false)
click_active_toggle if disable click_active_checkbox if disable
fill_in 'service_url', with: url fill_in 'service_url', with: url
fill_in 'service_username', with: 'username' fill_in 'service_username', with: 'username'
......
...@@ -18,8 +18,8 @@ RSpec.shared_context 'project service activation' do ...@@ -18,8 +18,8 @@ RSpec.shared_context 'project service activation' do
click_link(name) click_link(name)
end end
def click_active_toggle def click_active_checkbox
find('input[name="service[active]"] + button').click find('input[name="service[active]"]').click
end end
def click_test_integration def click_test_integration
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment