diff options
Diffstat (limited to 'spec/frontend/vue_mr_widget')
6 files changed, 91 insertions, 160 deletions
diff --git a/spec/frontend/vue_mr_widget/components/added_commit_message_spec.js b/spec/frontend/vue_mr_widget/components/added_commit_message_spec.js new file mode 100644 index 00000000000..150680caa7e --- /dev/null +++ b/spec/frontend/vue_mr_widget/components/added_commit_message_spec.js @@ -0,0 +1,31 @@ +import { shallowMount } from '@vue/test-utils'; +import AddedCommentMessage from '~/vue_merge_request_widget/components/added_commit_message.vue'; + +let wrapper; + +function factory(propsData) { + wrapper = shallowMount(AddedCommentMessage, { + propsData: { + isFastForwardEnabled: false, + targetBranch: 'main', + ...propsData, + }, + provide: { + glFeatures: { + restructuredMrWidget: true.valueOf, + }, + }, + }); +} + +describe('Widget added commit message', () => { + afterEach(() => { + wrapper.destroy(); + }); + + it('displays changes where not merged when state is closed', () => { + factory({ state: 'closed' }); + + expect(wrapper.element.outerHTML).toContain('The changes were not merged'); + }); +}); diff --git a/spec/frontend/vue_mr_widget/components/extensions/utils_spec.js b/spec/frontend/vue_mr_widget/components/extensions/utils_spec.js index 98cfc04eb25..5799799ad5e 100644 --- a/spec/frontend/vue_mr_widget/components/extensions/utils_spec.js +++ b/spec/frontend/vue_mr_widget/components/extensions/utils_spec.js @@ -2,16 +2,18 @@ import { generateText } from '~/vue_merge_request_widget/components/extensions/u describe('generateText', () => { it.each` - text | expectedText - ${'%{strong_start}Hello world%{strong_end}'} | ${'<span class="gl-font-weight-bold">Hello world</span>'} - ${'%{success_start}Hello world%{success_end}'} | ${'<span class="gl-font-weight-bold gl-text-green-500">Hello world</span>'} - ${'%{danger_start}Hello world%{danger_end}'} | ${'<span class="gl-font-weight-bold gl-text-red-500">Hello world</span>'} - ${'%{critical_start}Hello world%{critical_end}'} | ${'<span class="gl-font-weight-bold gl-text-red-800">Hello world</span>'} - ${'%{same_start}Hello world%{same_end}'} | ${'<span class="gl-font-weight-bold gl-text-gray-700">Hello world</span>'} - ${'%{small_start}Hello world%{small_end}'} | ${'<span class="gl-font-sm gl-text-gray-700">Hello world</span>'} - ${'%{strong_start}%{danger_start}Hello world%{danger_end}%{strong_end}'} | ${'<span class="gl-font-weight-bold"><span class="gl-font-weight-bold gl-text-red-500">Hello world</span></span>'} - ${'%{no_exist_start}Hello world%{no_exist_end}'} | ${'Hello world'} - ${['array']} | ${null} + text | expectedText + ${'%{strong_start}Hello world%{strong_end}'} | ${'<span class="gl-font-weight-bold">Hello world</span>'} + ${'%{success_start}Hello world%{success_end}'} | ${'<span class="gl-font-weight-bold gl-text-green-500">Hello world</span>'} + ${'%{danger_start}Hello world%{danger_end}'} | ${'<span class="gl-font-weight-bold gl-text-red-500">Hello world</span>'} + ${'%{critical_start}Hello world%{critical_end}'} | ${'<span class="gl-font-weight-bold gl-text-red-800">Hello world</span>'} + ${'%{same_start}Hello world%{same_end}'} | ${'<span class="gl-font-weight-bold gl-text-gray-700">Hello world</span>'} + ${'%{small_start}Hello world%{small_end}'} | ${'<span class="gl-font-sm gl-text-gray-700">Hello world</span>'} + ${'%{strong_start}%{danger_start}Hello world%{danger_end}%{strong_end}'} | ${'<span class="gl-font-weight-bold"><span class="gl-font-weight-bold gl-text-red-500">Hello world</span></span>'} + ${'%{no_exist_start}Hello world%{no_exist_end}'} | ${'Hello world'} + ${{ text: 'Hello world', href: 'http://www.example.com' }} | ${'<a class="gl-text-decoration-underline" href="http://www.example.com">Hello world</a>'} + ${{ prependText: 'Hello', text: 'world', href: 'http://www.example.com' }} | ${'Hello <a class="gl-text-decoration-underline" href="http://www.example.com">world</a>'} + ${['array']} | ${null} `('generates $expectedText from $text', ({ text, expectedText }) => { expect(generateText(text)).toBe(expectedText); }); diff --git a/spec/frontend/vue_mr_widget/components/mr_widget_header_spec.js b/spec/frontend/vue_mr_widget/components/mr_widget_header_spec.js index 5a1f17573d4..ed6dc598845 100644 --- a/spec/frontend/vue_mr_widget/components/mr_widget_header_spec.js +++ b/spec/frontend/vue_mr_widget/components/mr_widget_header_spec.js @@ -1,7 +1,5 @@ import { shallowMount, mount } from '@vue/test-utils'; -import { nextTick } from 'vue'; import Header from '~/vue_merge_request_widget/components/mr_widget_header.vue'; -import WebIdeLink from '~/vue_shared/components/web_ide_link.vue'; describe('MRWidgetHeader', () => { let wrapper; @@ -17,16 +15,6 @@ describe('MRWidgetHeader', () => { gon.relative_url_root = ''; }); - const expectDownloadDropdownItems = () => { - const downloadEmailPatchesEl = wrapper.find('.js-download-email-patches'); - const downloadPlainDiffEl = wrapper.find('.js-download-plain-diff'); - - expect(downloadEmailPatchesEl.text().trim()).toBe('Email patches'); - expect(downloadEmailPatchesEl.attributes('href')).toBe('/mr/email-patches'); - expect(downloadPlainDiffEl.text().trim()).toBe('Plain diff'); - expect(downloadPlainDiffEl.attributes('href')).toBe('/mr/plainDiffPath'); - }; - const commonMrProps = { divergedCommitsCount: 1, sourceBranch: 'mr-widget-refactor', @@ -36,8 +24,6 @@ describe('MRWidgetHeader', () => { statusPath: 'abc', }; - const findWebIdeButton = () => wrapper.findComponent(WebIdeLink); - describe('computed', () => { describe('shouldShowCommitsBehindText', () => { it('return true when there are divergedCommitsCount', () => { @@ -133,136 +119,6 @@ describe('MRWidgetHeader', () => { }); }); - describe('with an open merge request', () => { - const mrDefaultOptions = { - iid: 1, - divergedCommitsCount: 12, - sourceBranch: 'mr-widget-refactor', - sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>', - sourceBranchRemoved: false, - targetBranchPath: 'foo/bar/commits-path', - targetBranchTreePath: 'foo/bar/tree/path', - targetBranch: 'main', - isOpen: true, - canPushToSourceBranch: true, - emailPatchesPath: '/mr/email-patches', - plainDiffPath: '/mr/plainDiffPath', - statusPath: 'abc', - sourceProjectFullPath: 'root/gitlab-ce', - targetProjectFullPath: 'gitlab-org/gitlab-ce', - gitpodEnabled: true, - showGitpodButton: true, - gitpodUrl: 'http://gitpod.localhost', - userPreferencesGitpodPath: '/-/profile/preferences#user_gitpod_enabled', - userProfileEnableGitpodPath: '/-/profile?user%5Bgitpod_enabled%5D=true', - }; - - it('renders checkout branch button with modal trigger', () => { - createComponent({ - mr: { ...mrDefaultOptions }, - }); - - const button = wrapper.find('.js-check-out-branch'); - - expect(button.text().trim()).toBe('Check out branch'); - }); - - it.each([ - [ - 'renders web ide button', - { - mrProps: {}, - relativeUrl: '', - webIdeUrl: - '/-/ide/project/root/gitlab-ce/merge_requests/1?target_project=gitlab-org%2Fgitlab-ce', - }, - ], - [ - 'renders web ide button with blank target_project, when mr has same target project', - { - mrProps: { targetProjectFullPath: 'root/gitlab-ce' }, - relativeUrl: '', - webIdeUrl: '/-/ide/project/root/gitlab-ce/merge_requests/1?target_project=', - }, - ], - [ - 'renders web ide button with relative url', - { - mrProps: { iid: 2 }, - relativeUrl: '/gitlab', - webIdeUrl: - '/gitlab/-/ide/project/root/gitlab-ce/merge_requests/2?target_project=gitlab-org%2Fgitlab-ce', - }, - ], - ])('%s', async (_, { mrProps, relativeUrl, webIdeUrl }) => { - gon.relative_url_root = relativeUrl; - createComponent({ - mr: { ...mrDefaultOptions, ...mrProps }, - }); - - await nextTick(); - - expect(findWebIdeButton().props()).toMatchObject({ - showEditButton: false, - showWebIdeButton: true, - webIdeText: 'Open in Web IDE', - gitpodText: 'Open in Gitpod', - gitpodEnabled: true, - showGitpodButton: true, - gitpodUrl: 'http://gitpod.localhost', - userPreferencesGitpodPath: mrDefaultOptions.userPreferencesGitpodPath, - userProfileEnableGitpodPath: mrDefaultOptions.userProfileEnableGitpodPath, - webIdeUrl, - }); - }); - - it('does not render web ide button if source branch is removed', async () => { - createComponent({ mr: { ...mrDefaultOptions, sourceBranchRemoved: true } }); - - await nextTick(); - - expect(findWebIdeButton().exists()).toBe(false); - }); - - it('renders download dropdown with links', () => { - createComponent({ - mr: { ...mrDefaultOptions }, - }); - - expectDownloadDropdownItems(); - }); - }); - - describe('with a closed merge request', () => { - beforeEach(() => { - createComponent({ - mr: { - divergedCommitsCount: 12, - sourceBranch: 'mr-widget-refactor', - sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>', - sourceBranchRemoved: false, - targetBranchPath: 'foo/bar/commits-path', - targetBranchTreePath: 'foo/bar/tree/path', - targetBranch: 'main', - isOpen: false, - emailPatchesPath: '/mr/email-patches', - plainDiffPath: '/mr/plainDiffPath', - statusPath: 'abc', - }, - }); - }); - - it('does not render checkout branch button with modal trigger', () => { - const button = wrapper.find('.js-check-out-branch'); - - expect(button.exists()).toBe(false); - }); - - it('renders download dropdown with links', () => { - expectDownloadDropdownItems(); - }); - }); - describe('without diverged commits', () => { beforeEach(() => { createComponent({ diff --git a/spec/frontend/vue_mr_widget/components/states/mr_widget_ready_to_merge_spec.js b/spec/frontend/vue_mr_widget/components/states/mr_widget_ready_to_merge_spec.js index 0e364eb6800..da3a323e8ea 100644 --- a/spec/frontend/vue_mr_widget/components/states/mr_widget_ready_to_merge_spec.js +++ b/spec/frontend/vue_mr_widget/components/states/mr_widget_ready_to_merge_spec.js @@ -59,6 +59,7 @@ const createTestMr = (customConfig) => { mergeImmediatelyDocsPath: 'path/to/merge/immediately/docs', transitionStateMachine: (transition) => eventHub.$emit('StateMachineValueChanged', transition), translateStateToMachine: () => this.transitionStateMachine(), + state: 'open', }; Object.assign(mr, customConfig.mr); @@ -321,7 +322,6 @@ describe('ReadyToMerge', () => { await waitForPromises(); - expect(wrapper.vm.isMakingRequest).toBeTruthy(); expect(eventHub.$emit).toHaveBeenCalledWith('MRWidgetUpdateRequested'); expect(eventHub.$emit).toHaveBeenCalledWith('StateMachineValueChanged', { transition: 'start-auto-merge', @@ -348,7 +348,6 @@ describe('ReadyToMerge', () => { await waitForPromises(); - expect(wrapper.vm.isMakingRequest).toBeTruthy(); expect(eventHub.$emit).toHaveBeenCalledWith('FailedToMerge', undefined); const params = wrapper.vm.service.merge.mock.calls[0][0]; @@ -371,7 +370,6 @@ describe('ReadyToMerge', () => { await waitForPromises(); - expect(wrapper.vm.isMakingRequest).toBeTruthy(); expect(wrapper.vm.mr.transitionStateMachine).toHaveBeenCalledWith({ transition: 'start-merge', }); diff --git a/spec/frontend/vue_mr_widget/extensions/test_report/index_spec.js b/spec/frontend/vue_mr_widget/extensions/test_report/index_spec.js index 88b8e32bd5d..2bc6860743a 100644 --- a/spec/frontend/vue_mr_widget/extensions/test_report/index_spec.js +++ b/spec/frontend/vue_mr_widget/extensions/test_report/index_spec.js @@ -16,6 +16,7 @@ import newErrorsTestReports from 'jest/reports/mock_data/new_errors_report.json' import newFailedTestReports from 'jest/reports/mock_data/new_failures_report.json'; import successTestReports from 'jest/reports/mock_data/no_failures_report.json'; import resolvedFailures from 'jest/reports/mock_data/resolved_failures.json'; +import recentFailures from 'jest/reports/mock_data/recent_failures_report.json'; const reportWithParsingErrors = failedReport; reportWithParsingErrors.suites[0].suite_errors = { @@ -101,6 +102,17 @@ describe('Test report extension', () => { expect(wrapper.text()).toContain(expectedResult); }); + it('displays report level recently failed count', async () => { + mockApi(httpStatusCodes.OK, recentFailures); + createComponent(); + + await waitForPromises(); + + expect(wrapper.text()).toContain( + '2 out of 3 failed tests have failed more than once in the last 14 days', + ); + }); + it('displays a link to the full report', async () => { mockApi(httpStatusCodes.OK); createComponent(); @@ -125,10 +137,10 @@ describe('Test report extension', () => { it('displays summary for each suite', async () => { await createExpandedWidgetWithData(); - expect(trimText(findAllExtensionListItems().at(0).text())).toBe( + expect(trimText(findAllExtensionListItems().at(0).text())).toContain( 'rspec:pg: 1 failed and 2 fixed test results, 8 total tests', ); - expect(trimText(findAllExtensionListItems().at(1).text())).toBe( + expect(trimText(findAllExtensionListItems().at(1).text())).toContain( 'java ant: 1 failed, 3 total tests', ); }); @@ -145,5 +157,37 @@ describe('Test report extension', () => { 'Base report parsing error: JUnit data parsing failed: string not matched', ); }); + + it('displays suite level recently failed count', async () => { + await createExpandedWidgetWithData(recentFailures); + + expect(trimText(findAllExtensionListItems().at(0).text())).toContain( + '1 out of 2 failed tests has failed more than once in the last 14 days', + ); + expect(trimText(findAllExtensionListItems().at(1).text())).toContain( + '1 out of 1 failed test has failed more than once in the last 14 days', + ); + }); + + it('displays the list of failed and fixed tests', async () => { + await createExpandedWidgetWithData(); + + const firstSuite = trimText(findAllExtensionListItems().at(0).text()); + const secondSuite = trimText(findAllExtensionListItems().at(1).text()); + + expect(firstSuite).toContain('Test#subtract when a is 2 and b is 1 returns correct result'); + expect(firstSuite).toContain('Test#sum when a is 1 and b is 2 returns summary'); + expect(firstSuite).toContain('Test#sum when a is 100 and b is 200 returns summary'); + + expect(secondSuite).toContain('sumTest'); + }); + + it('displays the test level recently failed count', async () => { + await createExpandedWidgetWithData(recentFailures); + + expect(trimText(findAllExtensionListItems().at(0).text())).toContain( + 'Failed 8 times in main in the last 14 days', + ); + }); }); }); diff --git a/spec/frontend/vue_mr_widget/extentions/accessibility/index_spec.js b/spec/frontend/vue_mr_widget/extentions/accessibility/index_spec.js index ea422a57956..6d1b3bb34a5 100644 --- a/spec/frontend/vue_mr_widget/extentions/accessibility/index_spec.js +++ b/spec/frontend/vue_mr_widget/extentions/accessibility/index_spec.js @@ -107,7 +107,7 @@ describe('Accessibility extension', () => { it('displays report list item formatted', () => { const text = { newError: trimText(findAllExtensionListItems().at(0).text()), - resolvedError: findAllExtensionListItems().at(3).text(), + resolvedError: trimText(findAllExtensionListItems().at(3).text()), existingError: trimText(findAllExtensionListItems().at(6).text()), }; |