diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-09 09:10:17 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-09 09:10:17 +0000 |
commit | ad0265eead72a624ce7a020847db4f0f0c877e57 (patch) | |
tree | 206e0564b02aa9530e3c95f70eb10a77e074bdf0 /spec/frontend | |
parent | 4dfc8711171fe0c04bc6b8b224687603026dea46 (diff) | |
download | gitlab-ce-ad0265eead72a624ce7a020847db4f0f0c877e57.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
6 files changed, 155 insertions, 45 deletions
diff --git a/spec/frontend/ide/components/commit_sidebar/actions_spec.js b/spec/frontend/ide/components/commit_sidebar/actions_spec.js index b3b98a64891..a303e2b9bee 100644 --- a/spec/frontend/ide/components/commit_sidebar/actions_spec.js +++ b/spec/frontend/ide/components/commit_sidebar/actions_spec.js @@ -17,7 +17,11 @@ describe('IDE commit sidebar actions', () => { let store; let vm; - const createComponent = ({ hasMR = false, currentBranchId = 'master' } = {}) => { + const createComponent = ({ + hasMR = false, + currentBranchId = 'master', + emptyRepo = false, + } = {}) => { const Component = Vue.extend(commitActions); vm = createComponentWithStore(Component, store); @@ -27,6 +31,7 @@ describe('IDE commit sidebar actions', () => { const proj = { ...projectData }; proj.branches[currentBranchId] = branches.find(branch => branch.name === currentBranchId); + proj.empty_repo = emptyRepo; Vue.set(vm.$store.state.projects, 'abcproject', proj); @@ -52,24 +57,27 @@ describe('IDE commit sidebar actions', () => { vm = null; }); + const findText = () => vm.$el.textContent; + const findRadios = () => Array.from(vm.$el.querySelectorAll('input[type="radio"]')); + it('renders 2 groups', () => { createComponent(); - expect(vm.$el.querySelectorAll('input[type="radio"]').length).toBe(2); + expect(findRadios().length).toBe(2); }); it('renders current branch text', () => { createComponent(); - expect(vm.$el.textContent).toContain('Commit to master branch'); + expect(findText()).toContain('Commit to master branch'); }); it('hides merge request option when project merge requests are disabled', done => { - createComponent({ mergeRequestsEnabled: false }); + createComponent({ hasMR: false }); vm.$nextTick(() => { - expect(vm.$el.querySelectorAll('input[type="radio"]').length).toBe(2); - expect(vm.$el.textContent).not.toContain('Create a new branch and merge request'); + expect(findRadios().length).toBe(2); + expect(findText()).not.toContain('Create a new branch and merge request'); done(); }); @@ -119,6 +127,7 @@ describe('IDE commit sidebar actions', () => { it.each` input | expectedOption ${{ currentBranchId: BRANCH_DEFAULT }} | ${consts.COMMIT_TO_NEW_BRANCH} + ${{ currentBranchId: BRANCH_DEFAULT, emptyRepo: true }} | ${consts.COMMIT_TO_CURRENT_BRANCH} ${{ currentBranchId: BRANCH_PROTECTED, hasMR: true }} | ${consts.COMMIT_TO_CURRENT_BRANCH} ${{ currentBranchId: BRANCH_PROTECTED, hasMR: false }} | ${consts.COMMIT_TO_CURRENT_BRANCH} ${{ currentBranchId: BRANCH_PROTECTED_NO_ACCESS, hasMR: true }} | ${consts.COMMIT_TO_NEW_BRANCH} @@ -138,4 +147,15 @@ describe('IDE commit sidebar actions', () => { }, ); }); + + describe('when empty project', () => { + beforeEach(() => { + createComponent({ emptyRepo: true }); + }); + + it('only renders commit to current branch', () => { + expect(findRadios().length).toBe(1); + expect(findText()).toContain('Commit to master branch'); + }); + }); }); diff --git a/spec/frontend/ide/stores/getters_spec.js b/spec/frontend/ide/stores/getters_spec.js index 011be95c1d2..408ea2b2939 100644 --- a/spec/frontend/ide/stores/getters_spec.js +++ b/spec/frontend/ide/stores/getters_spec.js @@ -280,39 +280,21 @@ describe('IDE store getters', () => { }); describe('canPushToBranch', () => { - it('returns false when no currentBranch exists', () => { - const localGetters = { - currentProject: undefined, - }; - - expect(getters.canPushToBranch({}, localGetters)).toBeFalsy(); - }); - - it('returns true when can_push to currentBranch', () => { - const localGetters = { - currentProject: { - default_branch: 'master', - }, - currentBranch: { - can_push: true, - }, - }; - - expect(getters.canPushToBranch({}, localGetters)).toBeTruthy(); - }); - - it('returns false when !can_push to currentBranch', () => { - const localGetters = { - currentProject: { - default_branch: 'master', - }, - currentBranch: { - can_push: false, - }, - }; - - expect(getters.canPushToBranch({}, localGetters)).toBeFalsy(); - }); + it.each` + currentBranch | canPushCode | expectedValue + ${undefined} | ${undefined} | ${false} + ${{ can_push: true }} | ${false} | ${true} + ${{ can_push: true }} | ${true} | ${true} + ${{ can_push: false }} | ${false} | ${false} + ${{ can_push: false }} | ${true} | ${false} + ${undefined} | ${true} | ${true} + ${undefined} | ${false} | ${false} + `( + 'with currentBranch ($currentBranch) and canPushCode ($canPushCode), it is $expectedValue', + ({ currentBranch, canPushCode, expectedValue }) => { + expect(getters.canPushToBranch({}, { currentBranch, canPushCode })).toBe(expectedValue); + }, + ); }); describe('isFileDeletedAndReadded', () => { @@ -422,6 +404,7 @@ describe('IDE store getters', () => { getterName | permissionKey ${'canReadMergeRequests'} | ${'readMergeRequest'} ${'canCreateMergeRequests'} | ${'createMergeRequestIn'} + ${'canPushCode'} | ${'pushCode'} `('$getterName', ({ getterName, permissionKey }) => { it.each([true, false])('finds permission for current project (%s)', val => { localState.projects[TEST_PROJECT_ID] = { diff --git a/spec/frontend/ide/stores/modules/commit/getters_spec.js b/spec/frontend/ide/stores/modules/commit/getters_spec.js index 07445c22917..adbfd7c6835 100644 --- a/spec/frontend/ide/stores/modules/commit/getters_spec.js +++ b/spec/frontend/ide/stores/modules/commit/getters_spec.js @@ -292,4 +292,15 @@ describe('IDE commit module getters', () => { expect(getters.shouldHideNewMrOption(state, localGetters, null, rootGetters)).toBeFalsy(); }); }); + + describe('shouldDisableNewMrOption', () => { + it.each` + rootGetters | expectedValue + ${{ canCreateMergeRequests: false, emptyRepo: false }} | ${true} + ${{ canCreateMergeRequests: true, emptyRepo: true }} | ${true} + ${{ canCreateMergeRequests: true, emptyRepo: false }} | ${false} + `('with $rootGetters, it is $expectedValue', ({ rootGetters, expectedValue }) => { + expect(getters.shouldDisableNewMrOption(state, getters, {}, rootGetters)).toBe(expectedValue); + }); + }); }); diff --git a/spec/frontend/monitoring/components/charts/annotations_spec.js b/spec/frontend/monitoring/components/charts/annotations_spec.js index 100b13eabf4..69bf1fe4ced 100644 --- a/spec/frontend/monitoring/components/charts/annotations_spec.js +++ b/spec/frontend/monitoring/components/charts/annotations_spec.js @@ -1,27 +1,90 @@ import { generateAnnotationsSeries } from '~/monitoring/components/charts/annotations'; -import { deploymentData } from '../../mock_data'; +import { deploymentData, annotationsData } from '../../mock_data'; describe('annotations spec', () => { describe('generateAnnotationsSeries', () => { - it('default options', () => { + it('with default options', () => { const annotations = generateAnnotationsSeries(); - expect(annotations).toEqual([]); + + expect(annotations).toEqual( + expect.objectContaining({ + type: 'scatter', + yAxisIndex: 1, + data: [], + markLine: { + data: [], + symbol: 'none', + silent: true, + }, + }), + ); }); - it('with deployments', () => { - const annotations = generateAnnotationsSeries(deploymentData); + it('when only deployments data is passed', () => { + const annotations = generateAnnotationsSeries({ deployments: deploymentData }); expect(annotations).toEqual( expect.objectContaining({ type: 'scatter', yAxisIndex: 1, data: expect.any(Array), + markLine: { + data: [], + symbol: 'none', + silent: true, + }, }), ); annotations.data.forEach(annotation => { expect(annotation).toEqual(expect.any(Object)); }); + + expect(annotations.data).toHaveLength(deploymentData.length); + }); + + it('when only annotations data is passed', () => { + const annotations = generateAnnotationsSeries({ + annotations: annotationsData, + }); + + expect(annotations).toEqual( + expect.objectContaining({ + type: 'scatter', + yAxisIndex: 1, + data: expect.any(Array), + markLine: expect.any(Object), + }), + ); + + annotations.markLine.data.forEach(annotation => { + expect(annotation).toEqual(expect.any(Object)); + }); + + expect(annotations.data).toHaveLength(annotationsData.length); + expect(annotations.markLine.data).toHaveLength(annotationsData.length); + }); + + it('when deploments and annotations data is passed', () => { + const annotations = generateAnnotationsSeries({ + deployments: deploymentData, + annotations: annotationsData, + }); + + expect(annotations).toEqual( + expect.objectContaining({ + type: 'scatter', + yAxisIndex: 1, + data: expect.any(Array), + markLine: expect.any(Object), + }), + ); + + annotations.markLine.data.forEach(annotation => { + expect(annotation).toEqual(expect.any(Object)); + }); + + expect(annotations.data).toHaveLength(deploymentData.length + annotationsData.length); }); }); }); diff --git a/spec/frontend/monitoring/components/charts/time_series_spec.js b/spec/frontend/monitoring/components/charts/time_series_spec.js index f2478a583dc..c9b670fd7a8 100644 --- a/spec/frontend/monitoring/components/charts/time_series_spec.js +++ b/spec/frontend/monitoring/components/charts/time_series_spec.js @@ -169,6 +169,7 @@ describe('Time series component', () => { componentSubType: type, value: [mockDate, 5.55555], dataIndex: 0, + ...(type === 'scatter' && { name: 'deployments' }), }, ], value: mockDate, @@ -225,6 +226,10 @@ describe('Time series component', () => { timeSeriesChart.vm.formatTooltipText(generateSeriesData('scatter')); }); + it('set tooltip type to deployments', () => { + expect(timeSeriesChart.vm.tooltip.type).toBe('deployments'); + }); + it('formats tooltip title', () => { expect(timeSeriesChart.vm.tooltip.title).toBe('16 Jul 2019, 10:14AM'); }); @@ -521,7 +526,11 @@ describe('Time series component', () => { const commitUrl = `${mockProjectDir}/-/commit/${mockSha}`; beforeEach(done => { - timeSeriesAreaChart.vm.tooltip.isDeployment = true; + timeSeriesAreaChart.setData({ + tooltip: { + type: 'deployments', + }, + }); timeSeriesAreaChart.vm.$nextTick(done); }); diff --git a/spec/frontend/monitoring/mock_data.js b/spec/frontend/monitoring/mock_data.js index dde47178c1d..c9f2b110147 100644 --- a/spec/frontend/monitoring/mock_data.js +++ b/spec/frontend/monitoring/mock_data.js @@ -210,6 +210,30 @@ export const deploymentData = [ }, ]; +export const annotationsData = [ + { + id: 'gid://gitlab/Metrics::Dashboard::Annotation/1', + from: '2020-04-01T12:51:58.373Z', + to: null, + panelId: null, + description: 'This is a test annotation', + }, + { + id: 'gid://gitlab/Metrics::Dashboard::Annotation/2', + description: 'test annotation 2', + from: '2020-04-02T12:51:58.373Z', + to: null, + panelId: null, + }, + { + id: 'gid://gitlab/Metrics::Dashboard::Annotation/3', + description: 'test annotation 3', + from: '2020-04-04T12:51:58.373Z', + to: null, + panelId: null, + }, +]; + export const metricsNewGroupsAPIResponse = [ { group: 'System metrics (Kubernetes)', |