diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-25 09:10:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-25 09:10:36 +0300 |
commit | 866b1f8ed7db9b29b1188ffcba309b92572f354b (patch) | |
tree | 48f59dd9b5a292e58e8ce20fbff7e95b6178afe1 /spec/frontend/webhooks | |
parent | 01fbd09ea9ea4eeae52ed9fb4f7cc4dd97b4eb69 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/webhooks')
-rw-r--r-- | spec/frontend/webhooks/components/__snapshots__/push_events_spec.js.snap | 453 | ||||
-rw-r--r-- | spec/frontend/webhooks/components/push_events_spec.js | 117 |
2 files changed, 570 insertions, 0 deletions
diff --git a/spec/frontend/webhooks/components/__snapshots__/push_events_spec.js.snap b/spec/frontend/webhooks/components/__snapshots__/push_events_spec.js.snap new file mode 100644 index 00000000000..3dbff024a6b --- /dev/null +++ b/spec/frontend/webhooks/components/__snapshots__/push_events_spec.js.snap @@ -0,0 +1,453 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Webhook push events form editor component Different push events rules when editing existing hook with "all_branches" strategy selected 1`] = ` +<gl-form-radio-group-stub + checked="all_branches" + disabledfield="disabled" + htmlfield="html" + name="hook[branch_filter_strategy]" + options="" + textfield="text" + valuefield="value" +> + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_all_branches" + value="all_branches" + > + <div + data-qa-selector="strategy_radio_all" + > + All branches + </div> + </gl-form-radio-stub> + + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_wildcard" + value="wildcard" + > + <div + data-qa-selector="strategy_radio_wildcard" + > + + Wildcard pattern + + </div> + </gl-form-radio-stub> + + <div + class="gl-ml-6" + > + <!----> + </div> + + <!----> + + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_regex" + value="regex" + > + <div + data-qa-selector="strategy_radio_regex" + > + + Regular expression + + </div> + </gl-form-radio-stub> + + <div + class="gl-ml-6" + > + <!----> + </div> + + <!----> +</gl-form-radio-group-stub> +`; + +exports[`Webhook push events form editor component Different push events rules when editing existing hook with "regex" strategy selected 1`] = ` +<gl-form-radio-group-stub + checked="regex" + disabledfield="disabled" + htmlfield="html" + name="hook[branch_filter_strategy]" + options="" + textfield="text" + valuefield="value" +> + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_all_branches" + value="all_branches" + > + <div + data-qa-selector="strategy_radio_all" + > + All branches + </div> + </gl-form-radio-stub> + + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_wildcard" + value="wildcard" + > + <div + data-qa-selector="strategy_radio_wildcard" + > + + Wildcard pattern + + </div> + </gl-form-radio-stub> + + <div + class="gl-ml-6" + > + <!----> + </div> + + <!----> + + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_regex" + value="regex" + > + <div + data-qa-selector="strategy_radio_regex" + > + + Regular expression + + </div> + </gl-form-radio-stub> + + <div + class="gl-ml-6" + > + <gl-form-input-stub + data-qa-selector="webhook_branch_filter_field" + data-testid="webhook_branch_filter_field" + name="hook[push_events_branch_filter]" + value="foo" + /> + </div> + + <p + class="form-text text-muted custom-control" + > + <gl-sprintf-stub + message="Regex such as %{REGEX_CODE} is supported." + /> + </p> +</gl-form-radio-group-stub> +`; + +exports[`Webhook push events form editor component Different push events rules when editing existing hook with "wildcard" strategy selected 1`] = ` +<gl-form-radio-group-stub + checked="wildcard" + disabledfield="disabled" + htmlfield="html" + name="hook[branch_filter_strategy]" + options="" + textfield="text" + valuefield="value" +> + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_all_branches" + value="all_branches" + > + <div + data-qa-selector="strategy_radio_all" + > + All branches + </div> + </gl-form-radio-stub> + + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_wildcard" + value="wildcard" + > + <div + data-qa-selector="strategy_radio_wildcard" + > + + Wildcard pattern + + </div> + </gl-form-radio-stub> + + <div + class="gl-ml-6" + > + <gl-form-input-stub + data-qa-selector="webhook_branch_filter_field" + data-testid="webhook_branch_filter_field" + name="hook[push_events_branch_filter]" + value="foo" + /> + </div> + + <p + class="form-text text-muted custom-control" + > + <gl-sprintf-stub + message="Wildcards such as %{WILDCARD_CODE_STABLE} or %{WILDCARD_CODE_PRODUCTION} are supported." + /> + </p> + + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_regex" + value="regex" + > + <div + data-qa-selector="strategy_radio_regex" + > + + Regular expression + + </div> + </gl-form-radio-stub> + + <div + class="gl-ml-6" + > + <!----> + </div> + + <!----> +</gl-form-radio-group-stub> +`; + +exports[`Webhook push events form editor component Different push events rules when editing new hook all_branches should be selected by default 1`] = ` +<gl-form-radio-group-stub + checked="all_branches" + disabledfield="disabled" + htmlfield="html" + name="hook[branch_filter_strategy]" + options="" + textfield="text" + valuefield="value" +> + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_all_branches" + value="all_branches" + > + <div + data-qa-selector="strategy_radio_all" + > + All branches + </div> + </gl-form-radio-stub> + + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_wildcard" + value="wildcard" + > + <div + data-qa-selector="strategy_radio_wildcard" + > + + Wildcard pattern + + </div> + </gl-form-radio-stub> + + <div + class="gl-ml-6" + > + <!----> + </div> + + <!----> + + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_regex" + value="regex" + > + <div + data-qa-selector="strategy_radio_regex" + > + + Regular expression + + </div> + </gl-form-radio-stub> + + <div + class="gl-ml-6" + > + <!----> + </div> + + <!----> +</gl-form-radio-group-stub> +`; + +exports[`Webhook push events form editor component Different push events rules when editing new hook should be able to set regex rule 1`] = ` +<gl-form-radio-group-stub + checked="regex" + disabledfield="disabled" + htmlfield="html" + name="hook[branch_filter_strategy]" + options="" + textfield="text" + valuefield="value" +> + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_all_branches" + value="all_branches" + > + <div + data-qa-selector="strategy_radio_all" + > + All branches + </div> + </gl-form-radio-stub> + + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_wildcard" + value="wildcard" + > + <div + data-qa-selector="strategy_radio_wildcard" + > + + Wildcard pattern + + </div> + </gl-form-radio-stub> + + <div + class="gl-ml-6" + > + <!----> + </div> + + <!----> + + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_regex" + value="regex" + > + <div + data-qa-selector="strategy_radio_regex" + > + + Regular expression + + </div> + </gl-form-radio-stub> + + <div + class="gl-ml-6" + > + <gl-form-input-stub + data-qa-selector="webhook_branch_filter_field" + data-testid="webhook_branch_filter_field" + name="hook[push_events_branch_filter]" + value="" + /> + </div> + + <p + class="form-text text-muted custom-control" + > + <gl-sprintf-stub + message="Regex such as %{REGEX_CODE} is supported." + /> + </p> +</gl-form-radio-group-stub> +`; + +exports[`Webhook push events form editor component Different push events rules when editing new hook should be able to set wildcard rule 1`] = ` +<gl-form-radio-group-stub + checked="wildcard" + disabledfield="disabled" + htmlfield="html" + name="hook[branch_filter_strategy]" + options="" + textfield="text" + valuefield="value" +> + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_all_branches" + value="all_branches" + > + <div + data-qa-selector="strategy_radio_all" + > + All branches + </div> + </gl-form-radio-stub> + + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_wildcard" + value="wildcard" + > + <div + data-qa-selector="strategy_radio_wildcard" + > + + Wildcard pattern + + </div> + </gl-form-radio-stub> + + <div + class="gl-ml-6" + > + <gl-form-input-stub + data-qa-selector="webhook_branch_filter_field" + data-testid="webhook_branch_filter_field" + name="hook[push_events_branch_filter]" + value="" + /> + </div> + + <p + class="form-text text-muted custom-control" + > + <gl-sprintf-stub + message="Wildcards such as %{WILDCARD_CODE_STABLE} or %{WILDCARD_CODE_PRODUCTION} are supported." + /> + </p> + + <gl-form-radio-stub + class="gl-mt-2 branch-filter-strategy-radio" + data-testid="rule_regex" + value="regex" + > + <div + data-qa-selector="strategy_radio_regex" + > + + Regular expression + + </div> + </gl-form-radio-stub> + + <div + class="gl-ml-6" + > + <!----> + </div> + + <!----> +</gl-form-radio-group-stub> +`; diff --git a/spec/frontend/webhooks/components/push_events_spec.js b/spec/frontend/webhooks/components/push_events_spec.js new file mode 100644 index 00000000000..ccb61c4049a --- /dev/null +++ b/spec/frontend/webhooks/components/push_events_spec.js @@ -0,0 +1,117 @@ +import { nextTick } from 'vue'; +import { GlFormCheckbox, GlFormRadioGroup } from '@gitlab/ui'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import PushEvents from '~/webhooks/components/push_events.vue'; + +describe('Webhook push events form editor component', () => { + let wrapper; + + const findPushEventsCheckBox = (w = wrapper) => w.findComponent(GlFormCheckbox); + const findPushEventsIndicator = (w = wrapper) => w.find('input[name="hook[push_events]"]'); + const findPushEventRulesGroup = (w = wrapper) => w.findComponent(GlFormRadioGroup); + const getPushEventsRuleValue = (w = wrapper) => findPushEventRulesGroup(w).vm.$attrs.checked; + const findWildcardRuleInput = (w = wrapper) => w.findByTestId('webhook_branch_filter_field'); + const findRegexRuleInput = (w = wrapper) => w.findByTestId('webhook_branch_filter_field'); + + const createComponent = (provides) => + shallowMountExtended(PushEvents, { + provide: { + isNewHook: true, + pushEvents: false, + strategy: 'wildcard', + pushEventsBranchFilter: '', + ...provides, + }, + }); + + describe('Renders push events checkbox', () => { + it('when it is a new hook', async () => { + wrapper = createComponent({ + isNewHook: true, + }); + await nextTick(); + + const checkbox = findPushEventsCheckBox(); + expect(checkbox.exists()).toBe(true); + expect(findPushEventRulesGroup().exists()).toBe(false); + expect(findPushEventsIndicator().attributes('value')).toBe('false'); + }); + + it('when it is not a new hook and push events is enabled', async () => { + wrapper = createComponent({ + isNewHook: false, + pushEvents: true, + }); + await nextTick(); + + expect(findPushEventsCheckBox().exists()).toBe(true); + expect(findPushEventRulesGroup().exists()).toBe(true); + expect(findPushEventsIndicator().attributes('value')).toBe('true'); + }); + }); + + describe('Different push events rules', () => { + describe('when editing new hook', () => { + beforeEach(async () => { + wrapper = createComponent({ + isNewHook: true, + }); + await nextTick(); + await findPushEventsCheckBox().vm.$emit('input', true); + await nextTick(); + }); + + it('all_branches should be selected by default', async () => { + expect(findPushEventRulesGroup().element).toMatchSnapshot(); + }); + + it('should be able to set wildcard rule', async () => { + expect(getPushEventsRuleValue()).toBe('all_branches'); + expect(findWildcardRuleInput().exists()).toBe(false); + expect(findRegexRuleInput().exists()).toBe(false); + + await findPushEventRulesGroup(wrapper).vm.$emit('input', 'wildcard'); + expect(findWildcardRuleInput().exists()).toBe(true); + expect(findPushEventRulesGroup().element).toMatchSnapshot(); + + const testVal = 'test-val'; + findWildcardRuleInput().vm.$emit('input', testVal); + await nextTick(); + expect(findWildcardRuleInput().attributes('value')).toBe(testVal); + }); + + it('should be able to set regex rule', async () => { + expect(getPushEventsRuleValue()).toBe('all_branches'); + expect(findRegexRuleInput().exists()).toBe(false); + expect(findWildcardRuleInput().exists()).toBe(false); + + await findPushEventRulesGroup(wrapper).vm.$emit('input', 'regex'); + expect(findRegexRuleInput().exists()).toBe(true); + expect(findPushEventRulesGroup().element).toMatchSnapshot(); + + const testVal = 'test-val'; + findRegexRuleInput().vm.$emit('input', testVal); + await nextTick(); + expect(findRegexRuleInput().attributes('value')).toBe(testVal); + }); + }); + + describe('when editing existing hook', () => { + it.each(['all_branches', 'wildcard', 'regex'])( + 'with "%s" strategy selected', + async (strategy) => { + wrapper = createComponent({ + isNewHook: false, + pushEvents: true, + pushEventsBranchFilter: 'foo', + strategy, + }); + await nextTick(); + + expect(findPushEventsIndicator().attributes('value')).toBe('true'); + expect(findPushEventRulesGroup().element).toMatchSnapshot(); + }, + ); + }); + }); +}); |