Commit 29e0f3bc authored by Jackie Fraser's avatar Jackie Fraser

Apply review feedback

parent 89d11eb6
import { mount, shallowMount, createLocalVue } from '@vue/test-utils'; import { mount, shallowMount } from '@vue/test-utils';
import MergeTrainPositionIndicator from 'ee/vue_merge_request_widget/components/merge_train_position_indicator.vue'; import MergeTrainPositionIndicator from 'ee/vue_merge_request_widget/components/merge_train_position_indicator.vue';
import VisualReviewAppLink from 'ee/vue_merge_request_widget/components/visual_review_app_link.vue'; import VisualReviewAppLink from 'ee/vue_merge_request_widget/components/visual_review_app_link.vue';
import { mockStore } from 'jest/vue_mr_widget/mock_data'; import { mockStore } from 'jest/vue_mr_widget/mock_data';
...@@ -11,23 +11,27 @@ describe('MrWidgetPipelineContainer', () => { ...@@ -11,23 +11,27 @@ describe('MrWidgetPipelineContainer', () => {
let wrapper; let wrapper;
let mock; let mock;
const factory = (method = shallowMount, mrUpdates = {}, provide = {}) => { beforeEach(() => {
const localVue = createLocalVue(); mock = new MockAdapter(axios);
mock.onGet().reply(200, {});
});
wrapper = method.call(this, localVue.extend(MrWidgetPipelineContainer), { const factory = (method = shallowMount, mrUpdates = {}, provide = {}) => {
wrapper = method.call(this, MrWidgetPipelineContainer, {
propsData: { propsData: {
mr: Object.assign({}, mockStore, mrUpdates), mr: Object.assign({}, mockStore, mrUpdates),
}, },
provide: { provide: {
...provide, ...provide,
}, },
localVue,
attachToDocument: true, attachToDocument: true,
}); });
}; };
afterEach(() => { afterEach(() => {
mock.restore();
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}); });
describe('merge train indicator', () => { describe('merge train indicator', () => {
...@@ -61,9 +65,6 @@ describe('MrWidgetPipelineContainer', () => { ...@@ -61,9 +65,6 @@ describe('MrWidgetPipelineContainer', () => {
describe('with anonymous visual review feedback feature flag enabled', () => { describe('with anonymous visual review feedback feature flag enabled', () => {
beforeEach(() => { beforeEach(() => {
mock = new MockAdapter(axios);
mock.onGet().reply(200, {});
factory( factory(
mount, mount,
{ {
...@@ -101,9 +102,6 @@ describe('MrWidgetPipelineContainer', () => { ...@@ -101,9 +102,6 @@ describe('MrWidgetPipelineContainer', () => {
describe('with anonymous visual review feedback feature flag disabled', () => { describe('with anonymous visual review feedback feature flag disabled', () => {
beforeEach(() => { beforeEach(() => {
mock = new MockAdapter(axios);
mock.onGet().reply(200, {});
factory( factory(
mount, mount,
{ {
......
...@@ -6,6 +6,7 @@ import filterByKey from 'ee/vue_shared/security_reports/store/utils/filter_by_ke ...@@ -6,6 +6,7 @@ import filterByKey from 'ee/vue_shared/security_reports/store/utils/filter_by_ke
import mountComponent from 'helpers/vue_mount_component_helper'; import mountComponent from 'helpers/vue_mount_component_helper';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import { trimText } from 'helpers/text_helper';
import mockData, { import mockData, {
baseIssues, baseIssues,
...@@ -39,13 +40,6 @@ describe('ee merge request widget options', () => { ...@@ -39,13 +40,6 @@ describe('ee merge request widget options', () => {
let mock; let mock;
let Component; let Component;
function removeBreakLine(data) {
return data
.replace(/\r?\n|\r/g, '')
.replace(/\s\s+/g, ' ')
.trim();
}
beforeEach(() => { beforeEach(() => {
delete mrWidgetOptions.extends.el; // Prevent component mounting delete mrWidgetOptions.extends.el; // Prevent component mounting
...@@ -114,7 +108,7 @@ describe('ee merge request widget options', () => { ...@@ -114,7 +108,7 @@ describe('ee merge request widget options', () => {
it('should render provided data', done => { it('should render provided data', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
removeBreakLine( trimText(
findSecurityWidget().querySelector( findSecurityWidget().querySelector(
`${SAST_SELECTOR} .report-block-list-issue-description`, `${SAST_SELECTOR} .report-block-list-issue-description`,
).textContent, ).textContent,
...@@ -136,7 +130,7 @@ describe('ee merge request widget options', () => { ...@@ -136,7 +130,7 @@ describe('ee merge request widget options', () => {
it('should render provided data', done => { it('should render provided data', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
removeBreakLine( trimText(
findSecurityWidget().querySelector( findSecurityWidget().querySelector(
`${SAST_SELECTOR} .report-block-list-issue-description`, `${SAST_SELECTOR} .report-block-list-issue-description`,
).textContent, ).textContent,
...@@ -157,9 +151,9 @@ describe('ee merge request widget options', () => { ...@@ -157,9 +151,9 @@ describe('ee merge request widget options', () => {
it('should render error indicator', done => { it('should render error indicator', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(trimText(findSecurityWidget().querySelector(SAST_SELECTOR).textContent)).toContain(
removeBreakLine(findSecurityWidget().querySelector(SAST_SELECTOR).textContent), 'SAST: Loading resulted in an error',
).toContain('SAST: Loading resulted in an error'); );
done(); done();
}); });
}); });
...@@ -188,9 +182,7 @@ describe('ee merge request widget options', () => { ...@@ -188,9 +182,7 @@ describe('ee merge request widget options', () => {
vm = mountComponent(Component, { mrData: gl.mrWidgetData }); vm = mountComponent(Component, { mrData: gl.mrWidgetData });
expect( expect(
removeBreakLine( trimText(findSecurityWidget().querySelector(DEPENDENCY_SCANNING_SELECTOR).textContent),
findSecurityWidget().querySelector(DEPENDENCY_SCANNING_SELECTOR).textContent,
),
).toContain('Dependency scanning is loading'); ).toContain('Dependency scanning is loading');
}); });
}); });
...@@ -206,7 +198,7 @@ describe('ee merge request widget options', () => { ...@@ -206,7 +198,7 @@ describe('ee merge request widget options', () => {
it('should render provided data', done => { it('should render provided data', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
removeBreakLine( trimText(
findSecurityWidget().querySelector( findSecurityWidget().querySelector(
`${DEPENDENCY_SCANNING_SELECTOR} .report-block-list-issue-description`, `${DEPENDENCY_SCANNING_SELECTOR} .report-block-list-issue-description`,
).textContent, ).textContent,
...@@ -232,7 +224,7 @@ describe('ee merge request widget options', () => { ...@@ -232,7 +224,7 @@ describe('ee merge request widget options', () => {
it('renders no new vulnerabilities message', done => { it('renders no new vulnerabilities message', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
removeBreakLine( trimText(
findSecurityWidget().querySelector( findSecurityWidget().querySelector(
`${DEPENDENCY_SCANNING_SELECTOR} .report-block-list-issue-description`, `${DEPENDENCY_SCANNING_SELECTOR} .report-block-list-issue-description`,
).textContent, ).textContent,
...@@ -254,7 +246,7 @@ describe('ee merge request widget options', () => { ...@@ -254,7 +246,7 @@ describe('ee merge request widget options', () => {
it('should render provided data', done => { it('should render provided data', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
removeBreakLine( trimText(
findSecurityWidget().querySelector( findSecurityWidget().querySelector(
`${DEPENDENCY_SCANNING_SELECTOR} .report-block-list-issue-description`, `${DEPENDENCY_SCANNING_SELECTOR} .report-block-list-issue-description`,
).textContent, ).textContent,
...@@ -275,9 +267,7 @@ describe('ee merge request widget options', () => { ...@@ -275,9 +267,7 @@ describe('ee merge request widget options', () => {
it('should render error indicator', done => { it('should render error indicator', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
removeBreakLine( trimText(findSecurityWidget().querySelector(DEPENDENCY_SCANNING_SELECTOR).textContent),
findSecurityWidget().querySelector(DEPENDENCY_SCANNING_SELECTOR).textContent,
),
).toContain('Dependency scanning: Loading resulted in an error'); ).toContain('Dependency scanning: Loading resulted in an error');
done(); done();
}); });
...@@ -305,9 +295,9 @@ describe('ee merge request widget options', () => { ...@@ -305,9 +295,9 @@ describe('ee merge request widget options', () => {
}; };
vm.$nextTick(() => { vm.$nextTick(() => {
expect( expect(trimText(vm.$el.querySelector('.js-codequality-widget').textContent)).toContain(
removeBreakLine(vm.$el.querySelector('.js-codequality-widget').textContent), 'Loading codeclimate report',
).toContain('Loading codeclimate report'); );
done(); done();
}); });
...@@ -328,20 +318,16 @@ describe('ee merge request widget options', () => { ...@@ -328,20 +318,16 @@ describe('ee merge request widget options', () => {
vm.mr.codeclimate = gl.mrWidgetData.codeclimate; vm.mr.codeclimate = gl.mrWidgetData.codeclimate;
// mock worker response // mock worker response
jest.spyOn(MRWidgetStore, 'doCodeClimateComparison').mockImplementation(() => jest.spyOn(MRWidgetStore, 'doCodeClimateComparison').mockResolvedValue({
Promise.resolve({
newIssues: filterByKey(parsedHeadIssues, parsedBaseIssues, 'fingerprint'), newIssues: filterByKey(parsedHeadIssues, parsedBaseIssues, 'fingerprint'),
resolvedIssues: filterByKey(parsedBaseIssues, parsedHeadIssues, 'fingerprint'), resolvedIssues: filterByKey(parsedBaseIssues, parsedHeadIssues, 'fingerprint'),
}), });
);
}); });
it('should render provided data', done => { it('should render provided data', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
removeBreakLine( trimText(vm.$el.querySelector('.js-codequality-widget .js-code-text').textContent),
vm.$el.querySelector('.js-codequality-widget .js-code-text').textContent,
),
).toEqual('Code quality improved on 1 point and degraded on 1 point'); ).toEqual('Code quality improved on 1 point and degraded on 1 point');
done(); done();
}); });
...@@ -354,9 +340,7 @@ describe('ee merge request widget options', () => { ...@@ -354,9 +340,7 @@ describe('ee merge request widget options', () => {
Vue.nextTick(() => { Vue.nextTick(() => {
expect( expect(
removeBreakLine( trimText(vm.$el.querySelector('.js-codequality-widget .js-code-text').textContent),
vm.$el.querySelector('.js-codequality-widget .js-code-text').textContent,
),
).toEqual('Code quality improved on 1 point'); ).toEqual('Code quality improved on 1 point');
done(); done();
}); });
...@@ -368,9 +352,7 @@ describe('ee merge request widget options', () => { ...@@ -368,9 +352,7 @@ describe('ee merge request widget options', () => {
vm.mr.codeclimateMetrics.resolvedIssues = []; vm.mr.codeclimateMetrics.resolvedIssues = [];
Vue.nextTick(() => { Vue.nextTick(() => {
expect( expect(
removeBreakLine( trimText(vm.$el.querySelector('.js-codequality-widget .js-code-text').textContent),
vm.$el.querySelector('.js-codequality-widget .js-code-text').textContent,
),
).toEqual('Code quality degraded on 1 point'); ).toEqual('Code quality degraded on 1 point');
done(); done();
}); });
...@@ -392,12 +374,10 @@ describe('ee merge request widget options', () => { ...@@ -392,12 +374,10 @@ describe('ee merge request widget options', () => {
vm.mr.codeclimate = gl.mrWidgetData.codeclimate; vm.mr.codeclimate = gl.mrWidgetData.codeclimate;
// mock worker response // mock worker response
jest.spyOn(MRWidgetStore, 'doCodeClimateComparison').mockImplementation(() => jest.spyOn(MRWidgetStore, 'doCodeClimateComparison').mockResolvedValue({
Promise.resolve({
newIssues: filterByKey([], [], 'fingerprint'), newIssues: filterByKey([], [], 'fingerprint'),
resolvedIssues: filterByKey([], [], 'fingerprint'), resolvedIssues: filterByKey([], [], 'fingerprint'),
}), });
);
}); });
afterEach(() => { afterEach(() => {
...@@ -407,9 +387,7 @@ describe('ee merge request widget options', () => { ...@@ -407,9 +387,7 @@ describe('ee merge request widget options', () => {
it('should render provided data', done => { it('should render provided data', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
removeBreakLine( trimText(vm.$el.querySelector('.js-codequality-widget .js-code-text').textContent),
vm.$el.querySelector('.js-codequality-widget .js-code-text').textContent,
),
).toEqual('No changes to code quality'); ).toEqual('No changes to code quality');
done(); done();
}); });
...@@ -430,9 +408,7 @@ describe('ee merge request widget options', () => { ...@@ -430,9 +408,7 @@ describe('ee merge request widget options', () => {
it('should render error indicator', done => { it('should render error indicator', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
removeBreakLine( trimText(vm.$el.querySelector('.js-codequality-widget .js-code-text').textContent),
vm.$el.querySelector('.js-codequality-widget .js-code-text').textContent,
),
).toContain('Failed to load codeclimate report'); ).toContain('Failed to load codeclimate report');
done(); done();
}); });
...@@ -460,17 +436,13 @@ describe('ee merge request widget options', () => { ...@@ -460,17 +436,13 @@ describe('ee merge request widget options', () => {
vm.mr.codeclimate = gl.mrWidgetData.codeclimate; vm.mr.codeclimate = gl.mrWidgetData.codeclimate;
// mock worker rejection // mock worker rejection
jest jest.spyOn(MRWidgetStore, 'doCodeClimateComparison').mockRejectedValue();
.spyOn(MRWidgetStore, 'doCodeClimateComparison')
.mockImplementation(() => Promise.reject());
}); });
it('should render error indicator', done => { it('should render error indicator', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
removeBreakLine( trimText(vm.$el.querySelector('.js-codequality-widget .js-code-text').textContent),
vm.$el.querySelector('.js-codequality-widget .js-code-text').textContent,
),
).toEqual('Failed to load codeclimate report'); ).toEqual('Failed to load codeclimate report');
done(); done();
}); });
...@@ -493,9 +465,7 @@ describe('ee merge request widget options', () => { ...@@ -493,9 +465,7 @@ describe('ee merge request widget options', () => {
it('should render error indicator', done => { it('should render error indicator', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
removeBreakLine( trimText(vm.$el.querySelector('.js-codequality-widget .js-code-text').textContent),
vm.$el.querySelector('.js-codequality-widget .js-code-text').textContent,
),
).toContain('Failed to load codeclimate report'); ).toContain('Failed to load codeclimate report');
done(); done();
}); });
...@@ -523,9 +493,9 @@ describe('ee merge request widget options', () => { ...@@ -523,9 +493,9 @@ describe('ee merge request widget options', () => {
}; };
vm.$nextTick(() => { vm.$nextTick(() => {
expect( expect(trimText(vm.$el.querySelector('.js-performance-widget').textContent)).toContain(
removeBreakLine(vm.$el.querySelector('.js-performance-widget').textContent), 'Loading performance report',
).toContain('Loading performance report'); );
done(); done();
}); });
...@@ -548,9 +518,7 @@ describe('ee merge request widget options', () => { ...@@ -548,9 +518,7 @@ describe('ee merge request widget options', () => {
it('should render provided data', done => { it('should render provided data', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
removeBreakLine( trimText(vm.$el.querySelector('.js-performance-widget .js-code-text').textContent),
vm.$el.querySelector('.js-performance-widget .js-code-text').textContent,
),
).toEqual('Performance metrics improved on 2 points and degraded on 1 point'); ).toEqual('Performance metrics improved on 2 points and degraded on 1 point');
done(); done();
}); });
...@@ -563,9 +531,7 @@ describe('ee merge request widget options', () => { ...@@ -563,9 +531,7 @@ describe('ee merge request widget options', () => {
Vue.nextTick(() => { Vue.nextTick(() => {
expect( expect(
removeBreakLine( trimText(vm.$el.querySelector('.js-performance-widget .js-code-text').textContent),
vm.$el.querySelector('.js-performance-widget .js-code-text').textContent,
),
).toEqual('Performance metrics improved on 2 points'); ).toEqual('Performance metrics improved on 2 points');
done(); done();
}); });
...@@ -578,9 +544,7 @@ describe('ee merge request widget options', () => { ...@@ -578,9 +544,7 @@ describe('ee merge request widget options', () => {
Vue.nextTick(() => { Vue.nextTick(() => {
expect( expect(
removeBreakLine( trimText(vm.$el.querySelector('.js-performance-widget .js-code-text').textContent),
vm.$el.querySelector('.js-performance-widget .js-code-text').textContent,
),
).toEqual('Performance metrics degraded on 1 point'); ).toEqual('Performance metrics degraded on 1 point');
done(); done();
}); });
...@@ -607,7 +571,7 @@ describe('ee merge request widget options', () => { ...@@ -607,7 +571,7 @@ describe('ee merge request widget options', () => {
it('should render provided data', () => { it('should render provided data', () => {
expect( expect(
removeBreakLine(vm.$el.querySelector('.js-performance-widget .js-code-text').textContent), trimText(vm.$el.querySelector('.js-performance-widget .js-code-text').textContent),
).toEqual('No changes to performance metrics'); ).toEqual('No changes to performance metrics');
}); });
...@@ -640,9 +604,7 @@ describe('ee merge request widget options', () => { ...@@ -640,9 +604,7 @@ describe('ee merge request widget options', () => {
it('should render error indicator', done => { it('should render error indicator', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
removeBreakLine( trimText(vm.$el.querySelector('.js-performance-widget .js-code-text').textContent),
vm.$el.querySelector('.js-performance-widget .js-code-text').textContent,
),
).toContain('Failed to load performance report'); ).toContain('Failed to load performance report');
done(); done();
}); });
...@@ -672,9 +634,7 @@ describe('ee merge request widget options', () => { ...@@ -672,9 +634,7 @@ describe('ee merge request widget options', () => {
vm = mountComponent(Component, { mrData: gl.mrWidgetData }); vm = mountComponent(Component, { mrData: gl.mrWidgetData });
expect( expect(
removeBreakLine( trimText(findSecurityWidget().querySelector(CONTAINER_SCANNING_SELECTOR).textContent),
findSecurityWidget().querySelector(CONTAINER_SCANNING_SELECTOR).textContent,
),
).toContain('Container scanning is loading'); ).toContain('Container scanning is loading');
}); });
}); });
...@@ -690,7 +650,7 @@ describe('ee merge request widget options', () => { ...@@ -690,7 +650,7 @@ describe('ee merge request widget options', () => {
it('should render provided data', done => { it('should render provided data', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
removeBreakLine( trimText(
findSecurityWidget().querySelector( findSecurityWidget().querySelector(
`${CONTAINER_SCANNING_SELECTOR} .report-block-list-issue-description`, `${CONTAINER_SCANNING_SELECTOR} .report-block-list-issue-description`,
).textContent, ).textContent,
...@@ -818,7 +778,7 @@ describe('ee merge request widget options', () => { ...@@ -818,7 +778,7 @@ describe('ee merge request widget options', () => {
vm = mountComponent(Component, { mrData: gl.mrWidgetData }); vm = mountComponent(Component, { mrData: gl.mrWidgetData });
expect( expect(
removeBreakLine(findSecurityWidget().querySelector(SECRET_SCANNING_SELECTOR).textContent), trimText(findSecurityWidget().querySelector(SECRET_SCANNING_SELECTOR).textContent),
).toContain('Secret scanning is loading'); ).toContain('Secret scanning is loading');
}); });
}); });
...@@ -832,16 +792,16 @@ describe('ee merge request widget options', () => { ...@@ -832,16 +792,16 @@ describe('ee merge request widget options', () => {
}); });
it('should render provided data', done => { it('should render provided data', done => {
setTimeout(() => { setImmediate(() => {
expect( expect(
removeBreakLine( trimText(
findSecurityWidget().querySelector( findSecurityWidget().querySelector(
`${SECRET_SCANNING_SELECTOR} .report-block-list-issue-description`, `${SECRET_SCANNING_SELECTOR} .report-block-list-issue-description`,
).textContent, ).textContent,
), ),
).toEqual('Secret scanning detected 2 new, and 1 fixed vulnerabilities'); ).toEqual('Secret scanning detected 2 new, and 1 fixed vulnerabilities');
done(); done();
}, 0); });
}); });
}); });
...@@ -854,14 +814,14 @@ describe('ee merge request widget options', () => { ...@@ -854,14 +814,14 @@ describe('ee merge request widget options', () => {
}); });
it('should render error indicator', done => { it('should render error indicator', done => {
setTimeout(() => { setImmediate(() => {
expect( expect(
findSecurityWidget() findSecurityWidget()
.querySelector(SECRET_SCANNING_SELECTOR) .querySelector(SECRET_SCANNING_SELECTOR)
.textContent.trim(), .textContent.trim(),
).toContain('Secret scanning: Loading resulted in an error'); ).toContain('Secret scanning: Loading resulted in an error');
done(); done();
}, 0); });
}); });
}); });
}); });
...@@ -1173,7 +1133,7 @@ describe('ee merge request widget options', () => { ...@@ -1173,7 +1133,7 @@ describe('ee merge request widget options', () => {
}, },
}); });
expect(vm.service).toEqual(expect.objectContaining(convertObjectPropsToCamelCase(paths))); expect(vm.service).toMatchObject(convertObjectPropsToCamelCase(paths));
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment