Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/projects/settings/branch_rules/components/protections')
-rw-r--r--spec/frontend/projects/settings/branch_rules/components/protections/index_spec.js57
-rw-r--r--spec/frontend/projects/settings/branch_rules/components/protections/merge_protections_spec.js53
-rw-r--r--spec/frontend/projects/settings/branch_rules/components/protections/push_protections_spec.js50
3 files changed, 160 insertions, 0 deletions
diff --git a/spec/frontend/projects/settings/branch_rules/components/protections/index_spec.js b/spec/frontend/projects/settings/branch_rules/components/protections/index_spec.js
new file mode 100644
index 00000000000..3592fa50622
--- /dev/null
+++ b/spec/frontend/projects/settings/branch_rules/components/protections/index_spec.js
@@ -0,0 +1,57 @@
+import { nextTick } from 'vue';
+import { GlLink } from '@gitlab/ui';
+import { mountExtended } from 'helpers/vue_test_utils_helper';
+import Protections, {
+ i18n,
+} from '~/projects/settings/branch_rules/components/protections/index.vue';
+import PushProtections from '~/projects/settings/branch_rules/components/protections/push_protections.vue';
+import MergeProtections from '~/projects/settings/branch_rules/components/protections/merge_protections.vue';
+import { protections } from '../../mock_data';
+
+describe('Branch Protections', () => {
+ let wrapper;
+
+ const createComponent = async () => {
+ wrapper = mountExtended(Protections, {
+ propsData: { protections },
+ });
+ await nextTick();
+ };
+
+ const findHeading = () => wrapper.find('h4');
+ const findHelpText = () => wrapper.findByTestId('protections-help-text');
+ const findHelpLink = () => wrapper.findComponent(GlLink);
+ const findPushProtections = () => wrapper.findComponent(PushProtections);
+ const findMergeProtections = () => wrapper.findComponent(MergeProtections);
+
+ beforeEach(() => createComponent());
+
+ afterEach(() => {
+ wrapper.destroy();
+ });
+
+ it('renders a heading', () => {
+ expect(findHeading().text()).toBe(i18n.protections);
+ });
+
+ it('renders help text', () => {
+ expect(findHelpText().text()).toMatchInterpolatedText(i18n.protectionsHelpText);
+ expect(findHelpLink().attributes('href')).toBe('/help/user/project/protected_branches');
+ });
+
+ it('renders a PushProtections component with correct props', () => {
+ expect(findPushProtections().props('membersAllowedToPush')).toStrictEqual(
+ protections.membersAllowedToPush,
+ );
+ expect(findPushProtections().props('allowForcePush')).toBe(protections.allowForcePush);
+ });
+
+ it('renders a MergeProtections component with correct props', () => {
+ expect(findMergeProtections().props('membersAllowedToMerge')).toStrictEqual(
+ protections.membersAllowedToMerge,
+ );
+ expect(findMergeProtections().props('requireCodeOwnersApproval')).toBe(
+ protections.requireCodeOwnersApproval,
+ );
+ });
+});
diff --git a/spec/frontend/projects/settings/branch_rules/components/protections/merge_protections_spec.js b/spec/frontend/projects/settings/branch_rules/components/protections/merge_protections_spec.js
new file mode 100644
index 00000000000..0e168a2ad78
--- /dev/null
+++ b/spec/frontend/projects/settings/branch_rules/components/protections/merge_protections_spec.js
@@ -0,0 +1,53 @@
+import { GlFormGroup, GlFormCheckbox } from '@gitlab/ui';
+import { mountExtended } from 'helpers/vue_test_utils_helper';
+import MergeProtections, {
+ i18n,
+} from '~/projects/settings/branch_rules/components/protections/merge_protections.vue';
+import { membersAllowedToMerge, requireCodeOwnersApproval } from '../../mock_data';
+
+describe('Merge Protections', () => {
+ let wrapper;
+
+ const propsData = {
+ membersAllowedToMerge,
+ requireCodeOwnersApproval,
+ };
+
+ const createComponent = () => {
+ wrapper = mountExtended(MergeProtections, {
+ propsData,
+ });
+ };
+
+ const findFormGroup = () => wrapper.findComponent(GlFormGroup);
+ const findCodeOwnersApprovalCheckbox = () => wrapper.findComponent(GlFormCheckbox);
+
+ beforeEach(() => createComponent());
+
+ afterEach(() => {
+ wrapper.destroy();
+ });
+
+ it('renders a form group with the correct label', () => {
+ expect(findFormGroup().text()).toContain(i18n.allowedToMerge);
+ });
+
+ describe('Require code owners approval checkbox', () => {
+ it('renders a checkbox with the correct props', () => {
+ expect(findCodeOwnersApprovalCheckbox().vm.$attrs.checked).toBe(
+ propsData.requireCodeOwnersApproval,
+ );
+ });
+
+ it('renders help text', () => {
+ expect(findCodeOwnersApprovalCheckbox().text()).toContain(i18n.requireApprovalTitle);
+ expect(findCodeOwnersApprovalCheckbox().text()).toContain(i18n.requireApprovalHelpText);
+ });
+
+ it('emits a change-allow-force-push event when changed', () => {
+ findCodeOwnersApprovalCheckbox().vm.$emit('change', false);
+
+ expect(wrapper.emitted('change-require-code-owners-approval')[0]).toEqual([false]);
+ });
+ });
+});
diff --git a/spec/frontend/projects/settings/branch_rules/components/protections/push_protections_spec.js b/spec/frontend/projects/settings/branch_rules/components/protections/push_protections_spec.js
new file mode 100644
index 00000000000..d54dad08338
--- /dev/null
+++ b/spec/frontend/projects/settings/branch_rules/components/protections/push_protections_spec.js
@@ -0,0 +1,50 @@
+import { GlFormGroup, GlSprintf, GlFormCheckbox } from '@gitlab/ui';
+import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
+import PushProtections, {
+ i18n,
+} from '~/projects/settings/branch_rules/components/protections/push_protections.vue';
+import { membersAllowedToPush, allowForcePush } from '../../mock_data';
+
+describe('Push Protections', () => {
+ let wrapper;
+ const propsData = {
+ membersAllowedToPush,
+ allowForcePush,
+ };
+
+ const createComponent = () => {
+ wrapper = shallowMountExtended(PushProtections, {
+ propsData,
+ });
+ };
+
+ const findFormGroup = () => wrapper.findComponent(GlFormGroup);
+ const findAllowForcePushCheckbox = () => wrapper.findComponent(GlFormCheckbox);
+ const findHelpText = () => wrapper.findComponent(GlSprintf);
+
+ beforeEach(() => createComponent());
+
+ afterEach(() => {
+ wrapper.destroy();
+ });
+
+ it('renders a form group with the correct label', () => {
+ expect(findFormGroup().attributes('label')).toBe(i18n.allowedToPush);
+ });
+
+ describe('Allow force push checkbox', () => {
+ it('renders a checkbox with the correct props', () => {
+ expect(findAllowForcePushCheckbox().vm.$attrs.checked).toBe(propsData.allowForcePush);
+ });
+
+ it('renders help text', () => {
+ expect(findHelpText().attributes('message')).toBe(i18n.forcePushTitle);
+ });
+
+ it('emits a change-allow-force-push event when changed', () => {
+ findAllowForcePushCheckbox().vm.$emit('change', false);
+
+ expect(wrapper.emitted('change-allow-force-push')[0]).toEqual([false]);
+ });
+ });
+});