diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-07 15:08:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-07 15:08:06 +0300 |
commit | ebe0e306bbd6e913763bf1865b7778c001994e31 (patch) | |
tree | 49b9dc98391420a4c2a050e07bc5e6001bccdbbe /spec/frontend/projects | |
parent | 47da68850624438b5b5b9ff9d648b1e83282c446 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/projects')
-rw-r--r-- | spec/frontend/projects/settings/branch_rules/components/view/index_spec.js | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/spec/frontend/projects/settings/branch_rules/components/view/index_spec.js b/spec/frontend/projects/settings/branch_rules/components/view/index_spec.js index 714e0df596e..005a019ddaa 100644 --- a/spec/frontend/projects/settings/branch_rules/components/view/index_spec.js +++ b/spec/frontend/projects/settings/branch_rules/components/view/index_spec.js @@ -9,6 +9,10 @@ import Protection from '~/projects/settings/branch_rules/components/view/protect import { I18N, ALL_BRANCHES_WILDCARD, + REQUIRED_ICON, + NOT_REQUIRED_ICON, + REQUIRED_ICON_CLASS, + NOT_REQUIRED_ICON_CLASS, } from '~/projects/settings/branch_rules/components/view/constants'; import branchRulesQuery from 'ee_else_ce/projects/settings/branch_rules/queries/branch_rules_details.query.graphql'; import { sprintf } from '~/locale'; @@ -39,12 +43,13 @@ describe('View branch rules', () => { let fakeApollo; const projectPath = 'test/testing'; const protectedBranchesPath = 'protected/branches'; - const branchProtectionsMockRequestHandler = jest - .fn() - .mockResolvedValue(branchProtectionsMockResponse); + const branchProtectionsMockRequestHandler = (response = branchProtectionsMockResponse) => + jest.fn().mockResolvedValue(response); - const createComponent = async () => { - fakeApollo = createMockApollo([[branchRulesQuery, branchProtectionsMockRequestHandler]]); + const createComponent = async (mockResponse) => { + fakeApollo = createMockApollo([ + [branchRulesQuery, branchProtectionsMockRequestHandler(mockResponse)], + ]); wrapper = shallowMountExtended(RuleView, { apolloProvider: fakeApollo, @@ -63,7 +68,9 @@ describe('View branch rules', () => { const findBranchTitle = () => wrapper.findByTestId('branch-title'); const findBranchProtectionTitle = () => wrapper.findByText(I18N.protectBranchTitle); const findBranchProtections = () => wrapper.findAllComponents(Protection); - const findForcePushTitle = () => wrapper.findByText(I18N.allowForcePushDescription); + const findForcePushIcon = () => wrapper.findByTestId('force-push-icon'); + const findForcePushTitle = (title) => wrapper.findByText(title); + const findForcePushDescription = () => wrapper.findByText(I18N.forcePushDescription); const findApprovalsTitle = () => wrapper.findByText(I18N.approvalsTitle); const findStatusChecksTitle = () => wrapper.findByText(I18N.statusChecksTitle); const findMatchingBranchesLink = () => @@ -123,9 +130,23 @@ describe('View branch rules', () => { }); }); - it('renders force push protection', () => { - expect(findForcePushTitle().exists()).toBe(true); - }); + it.each` + allowForcePush | iconName | iconClass | title + ${true} | ${REQUIRED_ICON} | ${REQUIRED_ICON_CLASS} | ${I18N.allowForcePushTitle} + ${false} | ${NOT_REQUIRED_ICON} | ${NOT_REQUIRED_ICON_CLASS} | ${I18N.doesNotAllowForcePushTitle} + `( + 'renders force push section with the correct icon, title and description', + async ({ allowForcePush, iconName, iconClass, title }) => { + const mockResponse = branchProtectionsMockResponse; + mockResponse.data.project.branchRules.nodes[0].branchProtection.allowForcePush = allowForcePush; + await createComponent(mockResponse); + + expect(findForcePushIcon().props('name')).toBe(iconName); + expect(findForcePushIcon().attributes('class')).toBe(iconClass); + expect(findForcePushTitle(title).exists()).toBe(true); + expect(findForcePushDescription().exists()).toBe(true); + }, + ); it('renders a branch protection component for merge rules', () => { expect(findBranchProtections().at(1).props()).toMatchObject({ |