diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /spec/frontend/projects/settings/repository | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/frontend/projects/settings/repository')
3 files changed, 126 insertions, 6 deletions
diff --git a/spec/frontend/projects/settings/repository/branch_rules/app_spec.js b/spec/frontend/projects/settings/repository/branch_rules/app_spec.js index e12c3aeedd6..e920cd48163 100644 --- a/spec/frontend/projects/settings/repository/branch_rules/app_spec.js +++ b/spec/frontend/projects/settings/repository/branch_rules/app_spec.js @@ -1,18 +1,55 @@ +import Vue from 'vue'; +import VueApollo from 'vue-apollo'; +import createMockApollo from 'helpers/mock_apollo_helper'; +import waitForPromises from 'helpers/wait_for_promises'; import { mountExtended } from 'helpers/vue_test_utils_helper'; -import BranchRules from '~/projects/settings/repository/branch_rules/app.vue'; +import BranchRules, { i18n } from '~/projects/settings/repository/branch_rules/app.vue'; +import BranchRule from '~/projects/settings/repository/branch_rules/components/branch_rule.vue'; +import branchRulesQuery from '~/projects/settings/repository/branch_rules/graphql/queries/branch_rules.query.graphql'; +import createFlash from '~/flash'; +import { branchRulesMockResponse, propsDataMock } from './mock_data'; + +jest.mock('~/flash'); + +Vue.use(VueApollo); describe('Branch rules app', () => { let wrapper; + let fakeApollo; + + const branchRulesQuerySuccessHandler = jest.fn().mockResolvedValue(branchRulesMockResponse); + + const createComponent = async ({ queryHandler = branchRulesQuerySuccessHandler } = {}) => { + fakeApollo = createMockApollo([[branchRulesQuery, queryHandler]]); + + wrapper = mountExtended(BranchRules, { + apolloProvider: fakeApollo, + propsData: { + ...propsDataMock, + }, + }); - const createComponent = () => { - wrapper = mountExtended(BranchRules); + await waitForPromises(); }; - const findTitle = () => wrapper.find('strong'); + const findAllBranchRules = () => wrapper.findAllComponents(BranchRule); + const findEmptyState = () => wrapper.findByTestId('empty'); beforeEach(() => createComponent()); - it('renders a title', () => { - expect(findTitle().text()).toBe('Branch'); + it('displays an error if branch rules query fails', async () => { + await createComponent({ queryHandler: jest.fn().mockRejectedValue() }); + expect(createFlash).toHaveBeenCalledWith({ message: i18n.queryError }); + }); + + it('displays an empty state if no branch rules are present', async () => { + await createComponent({ queryHandler: jest.fn().mockRejectedValue() }); + expect(findEmptyState().text()).toBe(i18n.emptyState); + }); + + it('renders branch rules', () => { + const { nodes } = branchRulesMockResponse.data.project.branchRules; + expect(findAllBranchRules().at(0).text()).toBe(nodes[0].name); + expect(findAllBranchRules().at(1).text()).toBe(nodes[1].name); }); }); diff --git a/spec/frontend/projects/settings/repository/branch_rules/components/branch_rule_spec.js b/spec/frontend/projects/settings/repository/branch_rules/components/branch_rule_spec.js new file mode 100644 index 00000000000..924dab60704 --- /dev/null +++ b/spec/frontend/projects/settings/repository/branch_rules/components/branch_rule_spec.js @@ -0,0 +1,58 @@ +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import BranchRule, { + i18n, +} from '~/projects/settings/repository/branch_rules/components/branch_rule.vue'; + +const defaultProps = { + name: 'main', + isDefault: true, + isProtected: true, + approvalDetails: ['requires approval from TEST', '2 status checks'], +}; + +describe('Branch rule', () => { + let wrapper; + + const createComponent = (props = {}) => { + wrapper = shallowMountExtended(BranchRule, { propsData: { ...defaultProps, ...props } }); + }; + + const findDefaultBadge = () => wrapper.findByText(i18n.defaultLabel); + const findProtectedBadge = () => wrapper.findByText(i18n.protectedLabel); + const findBranchName = () => wrapper.findByText(defaultProps.name); + const findProtectionDetailsList = () => wrapper.findByRole('list'); + const findProtectionDetailsListItems = () => wrapper.findAllByRole('listitem'); + + beforeEach(() => createComponent()); + + it('renders the branch name', () => { + expect(findBranchName().exists()).toBe(true); + }); + + describe('badges', () => { + it('renders both default and protected badges', () => { + expect(findDefaultBadge().exists()).toBe(true); + expect(findProtectedBadge().exists()).toBe(true); + }); + + it('does not render default badge if isDefault is set to false', () => { + createComponent({ isDefault: false }); + expect(findDefaultBadge().exists()).toBe(false); + }); + + it('does not render protected badge if isProtected is set to false', () => { + createComponent({ isProtected: false }); + expect(findProtectedBadge().exists()).toBe(false); + }); + }); + + it('does not render the protection details list of no details are present', () => { + createComponent({ approvalDetails: null }); + expect(findProtectionDetailsList().exists()).toBe(false); + }); + + it('renders the protection details list items', () => { + expect(findProtectionDetailsListItems().at(0).text()).toBe(defaultProps.approvalDetails[0]); + expect(findProtectionDetailsListItems().at(1).text()).toBe(defaultProps.approvalDetails[1]); + }); +}); diff --git a/spec/frontend/projects/settings/repository/branch_rules/mock_data.js b/spec/frontend/projects/settings/repository/branch_rules/mock_data.js new file mode 100644 index 00000000000..14ed35f047d --- /dev/null +++ b/spec/frontend/projects/settings/repository/branch_rules/mock_data.js @@ -0,0 +1,25 @@ +export const branchRulesMockResponse = { + data: { + project: { + id: '123', + __typename: 'Project', + branchRules: { + __typename: 'BranchRuleConnection', + nodes: [ + { + name: 'main', + __typename: 'BranchRule', + }, + { + name: 'test-*', + __typename: 'BranchRule', + }, + ], + }, + }, + }, +}; + +export const propsDataMock = { + projectPath: 'some/project/path', +}; |