diff options
Diffstat (limited to 'spec/frontend/projects/settings/branch_rules/components/view')
4 files changed, 77 insertions, 10 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 bf4026b65db..27065a704e2 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 @@ -12,7 +12,11 @@ import { import Protection from '~/projects/settings/branch_rules/components/view/protection.vue'; import branchRulesQuery from '~/projects/settings/branch_rules/queries/branch_rules_details.query.graphql'; import { sprintf } from '~/locale'; -import { branchProtectionsMockResponse } from './mock_data'; +import { + branchProtectionsMockResponse, + approvalRulesMock, + statusChecksRulesMock, +} from './mock_data'; jest.mock('~/lib/utils/url_utility', () => ({ getParameterByName: jest.fn().mockReturnValue('main'), @@ -34,6 +38,7 @@ describe('View branch rules', () => { const projectPath = 'test/testing'; const protectedBranchesPath = 'protected/branches'; const approvalRulesPath = 'approval/rules'; + const statusChecksPath = 'status/checks'; const branchProtectionsMockRequestHandler = jest .fn() .mockResolvedValue(branchProtectionsMockResponse); @@ -43,7 +48,7 @@ describe('View branch rules', () => { wrapper = shallowMountExtended(RuleView, { apolloProvider: fakeApollo, - provide: { projectPath, protectedBranchesPath, approvalRulesPath }, + provide: { projectPath, protectedBranchesPath, approvalRulesPath, statusChecksPath }, }); await waitForPromises(); @@ -59,6 +64,7 @@ describe('View branch rules', () => { const findBranchProtections = () => wrapper.findAllComponents(Protection); const findForcePushTitle = () => wrapper.findByText(I18N.allowForcePushDescription); const findApprovalsTitle = () => wrapper.findByText(I18N.approvalsTitle); + const findStatusChecksTitle = () => wrapper.findByText(I18N.statusChecksTitle); it('gets the branch param from url and renders it in the view', () => { expect(util.getParameterByName).toHaveBeenCalledWith('branch'); @@ -105,9 +111,21 @@ describe('View branch rules', () => { expect(findApprovalsTitle().exists()).toBe(true); expect(findBranchProtections().at(2).props()).toMatchObject({ - header: sprintf(I18N.approvalsHeader, { total: 0 }), + header: sprintf(I18N.approvalsHeader, { total: 3 }), headerLinkHref: approvalRulesPath, headerLinkTitle: I18N.manageApprovalsLinkTitle, + approvals: approvalRulesMock, + }); + }); + + it('renders a branch protection component for status checks', () => { + expect(findStatusChecksTitle().exists()).toBe(true); + + expect(findBranchProtections().at(3).props()).toMatchObject({ + header: sprintf(I18N.statusChecksHeader, { total: 2 }), + headerLinkHref: statusChecksPath, + headerLinkTitle: I18N.statusChecksLinkTitle, + statusChecks: statusChecksRulesMock, }); }); }); diff --git a/spec/frontend/projects/settings/branch_rules/components/view/mock_data.js b/spec/frontend/projects/settings/branch_rules/components/view/mock_data.js index c3f573061da..c07d4673344 100644 --- a/spec/frontend/projects/settings/branch_rules/components/view/mock_data.js +++ b/spec/frontend/projects/settings/branch_rules/components/view/mock_data.js @@ -1,29 +1,34 @@ const usersMock = [ { + id: '123', username: 'usr1', webUrl: 'http://test.test/usr1', name: 'User 1', avatarUrl: 'http://test.test/avt1.png', }, { + id: '456', username: 'usr2', webUrl: 'http://test.test/usr2', name: 'User 2', avatarUrl: 'http://test.test/avt2.png', }, { + id: '789', username: 'usr3', webUrl: 'http://test.test/usr3', name: 'User 3', avatarUrl: 'http://test.test/avt3.png', }, { + id: '987', username: 'usr4', webUrl: 'http://test.test/usr4', name: 'User 4', avatarUrl: 'http://test.test/avt4.png', }, { + id: '654', username: 'usr5', webUrl: 'http://test.test/usr5', name: 'User 5', @@ -40,6 +45,22 @@ const approvalsRequired = 3; const groupsMock = [{ name: 'test_group_1' }, { name: 'test_group_2' }]; +export const approvalRulesMock = [ + { + __typename: 'ApprovalProjectRule', + id: '123', + name: 'test', + type: 'REGULAR', + eligibleApprovers: { nodes: usersMock }, + approvalsRequired, + }, +]; + +export const statusChecksRulesMock = [ + { __typename: 'StatusCheckRule', id: '123', name: 'test', externalUrl: 'https://test.test' }, + { __typename: 'StatusCheckRule', id: '456', name: 'test 2', externalUrl: 'https://test2.test2' }, +]; + export const protectionPropsMock = { header: 'Test protection', headerLinkTitle: 'Test link title', @@ -47,13 +68,8 @@ export const protectionPropsMock = { roles: accessLevelsMock, users: usersMock, groups: groupsMock, - approvals: [ - { - name: 'test', - eligibleApprovers: { nodes: usersMock }, - approvalsRequired, - }, - ], + approvals: approvalRulesMock, + statusChecks: statusChecksRulesMock, }; export const protectionRowPropsMock = { @@ -61,6 +77,7 @@ export const protectionRowPropsMock = { users: usersMock, accessLevels: accessLevelsMock, approvalsRequired, + statusCheckUrl: statusChecksRulesMock[0].externalUrl, }; export const accessLevelsMockResponse = [ @@ -116,6 +133,14 @@ export const branchProtectionsMockResponse = { edges: accessLevelsMockResponse, }, }, + approvalRules: { + __typename: 'ApprovalProjectRuleConnection', + nodes: approvalRulesMock, + }, + externalStatusChecks: { + __typename: 'ExternalStatusCheckConnection', + nodes: statusChecksRulesMock, + }, }, { __typename: 'BranchRule', @@ -133,6 +158,14 @@ export const branchProtectionsMockResponse = { edges: [], }, }, + approvalRules: { + __typename: 'ApprovalProjectRuleConnection', + nodes: [], + }, + externalStatusChecks: { + __typename: 'ExternalStatusCheckConnection', + nodes: [], + }, }, ], }, diff --git a/spec/frontend/projects/settings/branch_rules/components/view/protection_row_spec.js b/spec/frontend/projects/settings/branch_rules/components/view/protection_row_spec.js index b0a69bedd3e..a98b156f94e 100644 --- a/spec/frontend/projects/settings/branch_rules/components/view/protection_row_spec.js +++ b/spec/frontend/projects/settings/branch_rules/components/view/protection_row_spec.js @@ -27,6 +27,7 @@ describe('Branch rule protection row', () => { const findAccessLevels = () => wrapper.findAllByTestId('access-level'); const findApprovalsRequired = () => wrapper.findByText(`${protectionRowPropsMock.approvalsRequired} approvals required`); + const findStatusChecksUrl = () => wrapper.findByText(protectionRowPropsMock.statusCheckUrl); it('renders a title', () => { expect(findTitle().exists()).toBe(true); @@ -68,4 +69,8 @@ describe('Branch rule protection row', () => { it('renders the number of approvals required', () => { expect(findApprovalsRequired().exists()).toBe(true); }); + + it('renders status checks URL', () => { + expect(findStatusChecksUrl().exists()).toBe(true); + }); }); diff --git a/spec/frontend/projects/settings/branch_rules/components/view/protection_spec.js b/spec/frontend/projects/settings/branch_rules/components/view/protection_spec.js index e2fbb4f5bbb..caf967b4257 100644 --- a/spec/frontend/projects/settings/branch_rules/components/view/protection_spec.js +++ b/spec/frontend/projects/settings/branch_rules/components/view/protection_spec.js @@ -65,4 +65,15 @@ describe('Branch rule protection', () => { approvalsRequired: approval.approvalsRequired, }); }); + + it('renders a protection row for status checks', () => { + const statusCheck = protectionPropsMock.statusChecks[0]; + expect(findProtectionRows().at(4).props()).toMatchObject({ + title: statusCheck.name, + showDivider: false, + statusCheckUrl: statusCheck.externalUrl, + }); + + expect(findProtectionRows().at(5).props('showDivider')).toBe(true); + }); }); |