Commit d2fb555c authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch '225275-add-glcheckbox-to-squah-commits' into 'master'

Resolve "Improve "squash_before_merge" to utilize GlFormCheckbox"

See merge request gitlab-org/gitlab!48338
parents e8468b40 10441c65
<script> <script>
import { GlIcon, GlTooltipDirective } from '@gitlab/ui'; import { GlIcon, GlTooltipDirective, GlFormCheckbox } from '@gitlab/ui';
import { SQUASH_BEFORE_MERGE } from '../../i18n'; import { SQUASH_BEFORE_MERGE } from '../../i18n';
export default { export default {
components: { components: {
GlIcon, GlIcon,
GlFormCheckbox,
}, },
directives: { directives: {
GlTooltip: GlTooltipDirective, GlTooltip: GlTooltipDirective,
...@@ -32,32 +33,23 @@ export default { ...@@ -32,32 +33,23 @@ export default {
tooltipTitle() { tooltipTitle() {
return this.isDisabled ? this.$options.i18n.tooltipTitle : null; return this.isDisabled ? this.$options.i18n.tooltipTitle : null;
}, },
tooltipFocusable() {
return this.isDisabled ? '0' : null;
},
}, },
}; };
</script> </script>
<template> <template>
<div class="inline"> <div class="gl-display-flex gl-align-items-center">
<label <gl-form-checkbox
v-gl-tooltip v-gl-tooltip
:class="{ 'gl-text-gray-400': isDisabled }" :checked="value"
:tabindex="tooltipFocusable" :disabled="isDisabled"
data-testid="squashLabel" name="squash"
class="qa-squash-checkbox js-squash-checkbox gl-mb-0 gl-mr-2"
:title="tooltipTitle" :title="tooltipTitle"
@change="checked => $emit('input', checked)"
> >
<input
:checked="value"
:disabled="isDisabled"
type="checkbox"
name="squash"
class="qa-squash-checkbox js-squash-checkbox"
@change="$emit('input', $event.target.checked)"
/>
{{ $options.i18n.checkboxLabel }} {{ $options.i18n.checkboxLabel }}
</label> </gl-form-checkbox>
<a <a
v-if="helpPath" v-if="helpPath"
v-gl-tooltip v-gl-tooltip
......
---
title: Add GlFormCheckbox to squash commits
merge_request: 48338
author:
type: changed
import { createLocalVue, shallowMount } from '@vue/test-utils'; import { createLocalVue, shallowMount } from '@vue/test-utils';
import { GlFormCheckbox } from '@gitlab/ui';
import SquashBeforeMerge from '~/vue_merge_request_widget/components/states/squash_before_merge.vue'; import SquashBeforeMerge from '~/vue_merge_request_widget/components/states/squash_before_merge.vue';
import { SQUASH_BEFORE_MERGE } from '~/vue_merge_request_widget/i18n'; import { SQUASH_BEFORE_MERGE } from '~/vue_merge_request_widget/i18n';
...@@ -20,17 +21,15 @@ describe('Squash before merge component', () => { ...@@ -20,17 +21,15 @@ describe('Squash before merge component', () => {
wrapper.destroy(); wrapper.destroy();
}); });
const findLabel = () => wrapper.find('[data-testid="squashLabel"]'); const findCheckbox = () => wrapper.find(GlFormCheckbox);
describe('checkbox', () => { describe('checkbox', () => {
const findCheckbox = () => wrapper.find('.js-squash-checkbox');
it('is unchecked if passed value prop is false', () => { it('is unchecked if passed value prop is false', () => {
createComponent({ createComponent({
value: false, value: false,
}); });
expect(findCheckbox().element.checked).toBeFalsy(); expect(findCheckbox().vm.$attrs.checked).toBe(false);
}); });
it('is checked if passed value prop is true', () => { it('is checked if passed value prop is true', () => {
...@@ -38,22 +37,7 @@ describe('Squash before merge component', () => { ...@@ -38,22 +37,7 @@ describe('Squash before merge component', () => {
value: true, value: true,
}); });
expect(findCheckbox().element.checked).toBeTruthy(); expect(findCheckbox().vm.$attrs.checked).toBe(true);
});
it('changes value on click', done => {
createComponent({
value: false,
});
findCheckbox().element.checked = true;
findCheckbox().trigger('change');
wrapper.vm.$nextTick(() => {
expect(findCheckbox().element.checked).toBeTruthy();
done();
});
}); });
it('is disabled if isDisabled prop is true', () => { it('is disabled if isDisabled prop is true', () => {
...@@ -62,31 +46,12 @@ describe('Squash before merge component', () => { ...@@ -62,31 +46,12 @@ describe('Squash before merge component', () => {
isDisabled: true, isDisabled: true,
}); });
expect(findCheckbox().attributes('disabled')).toBeTruthy(); expect(findCheckbox().vm.$attrs.disabled).toBe(true);
});
});
describe('label', () => {
describe.each`
isDisabled | expectation
${true} | ${'grays out text if it is true'}
${false} | ${'does not gray out text if it is false'}
`('isDisabled prop', ({ isDisabled, expectation }) => {
beforeEach(() => {
createComponent({
value: false,
isDisabled,
});
});
it(expectation, () => {
expect(findLabel().classes('gl-text-gray-400')).toBe(isDisabled);
});
}); });
}); });
describe('tooltip', () => { describe('tooltip', () => {
const tooltipTitle = () => findLabel().attributes('title'); const tooltipTitle = () => findCheckbox().attributes('title');
it('does not render when isDisabled is false', () => { it('does not render when isDisabled is false', () => {
createComponent({ createComponent({
...@@ -114,7 +79,7 @@ describe('Squash before merge component', () => { ...@@ -114,7 +79,7 @@ describe('Squash before merge component', () => {
const aboutLink = wrapper.find('a'); const aboutLink = wrapper.find('a');
expect(aboutLink.exists()).toBeFalsy(); expect(aboutLink.exists()).toBe(false);
}); });
it('is rendered if help path is passed', () => { it('is rendered if help path is passed', () => {
...@@ -125,7 +90,7 @@ describe('Squash before merge component', () => { ...@@ -125,7 +90,7 @@ describe('Squash before merge component', () => {
const aboutLink = wrapper.find('a'); const aboutLink = wrapper.find('a');
expect(aboutLink.exists()).toBeTruthy(); expect(aboutLink.exists()).toBe(true);
}); });
it('should have a correct help path if passed', () => { it('should have a correct help path if passed', () => {
......
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