Fix MR and issue specs

This commit is contained in:
Luke "Jared" Bennett 2017-07-07 16:04:43 +01:00
parent c7f23e2564
commit f28cd19dde
No known key found for this signature in database
GPG key ID: 402ED51FB5D306C2
4 changed files with 18 additions and 15 deletions

View file

@ -1,6 +1,6 @@
import CloseReopenReportToggle from '../close_reopen_report_toggle';
export default function initCloseReopenReport() {
function initCloseReopenReport() {
const container = document.querySelector('.js-issuable-close-dropdown');
if (!container) return undefined;
@ -19,3 +19,9 @@ export default function initCloseReopenReport() {
return closeReopenReportToggle;
}
const IssuablesHelper = {
initCloseReopenReport,
};
export default IssuablesHelper;

View file

@ -6,7 +6,7 @@ import '~/lib/utils/text_utility';
import './flash';
import './task_list';
import CreateMergeRequestDropdown from './create_merge_request_dropdown';
import initCloseReopenReport from './helpers/issuables_helper';
import IssuablesHelper from './helpers/issuables_helper';
class Issue {
constructor() {
@ -98,10 +98,10 @@ class Issue {
}
initCloseReopenReport() {
this.closeReopenReportToggle = initCloseReopenReport();
this.closeReopenReportToggle = IssuablesHelper.initCloseReopenReport();
this.closeButtons = this.closeButtons.not('.issuable-close-button');
this.reopenButtons = this.reopenButtons.not('.issuable-close-button');
if (this.closeButtons) this.closeButtons = this.closeButtons.not('.issuable-close-button');
if (this.reopenButtons) this.reopenButtons = this.reopenButtons.not('.issuable-close-button');
}
disableCloseReopenButton($button, shouldDisable) {

View file

@ -4,7 +4,7 @@
import 'vendor/jquery.waitforimages';
import './task_list';
import './merge_request_tabs';
import initCloseReopenReport from './helpers/issuables_helper';
import IssuablesHelper from './helpers/issuables_helper';
(function() {
this.MergeRequest = (function() {
@ -26,7 +26,7 @@ import initCloseReopenReport from './helpers/issuables_helper';
this.initTabs();
this.initMRBtnListeners();
this.initCommitMessageListeners();
this.closeReopenReportToggle = initCloseReopenReport();
this.closeReopenReportToggle = IssuablesHelper.initCloseReopenReport();
if ($("a.btn-close").length) {
this.taskList = new gl.TaskList({

View file

@ -3,6 +3,7 @@
import '~/merge_request';
import CloseReopenReportToggle from '~/close_reopen_report_toggle';
import IssuablesHelper from '~/helpers/issuables_helper';
(function() {
describe('MergeRequest', function() {
@ -31,28 +32,24 @@ import CloseReopenReportToggle from '~/close_reopen_report_toggle';
describe('class constructor', () => {
it('calls .initCloseReopenReport', () => {
spyOn(MergeRequest.prototype, 'initCloseReopenReport');
spyOn(IssuablesHelper, 'initCloseReopenReport');
const mergeRequest = new MergeRequest();
new MergeRequest(); // eslint-disable-line no-new
expect(mergeRequest.initCloseReopenReport).toHaveBeenCalled();
expect(IssuablesHelper.initCloseReopenReport).toHaveBeenCalled();
});
});
describe('initCloseReopenReport', () => {
it('calls .initDroplab', () => {
const container = jasmine.createSpyObj('container', ['querySelector']);
const dropdownTrigger = {};
const dropdownList = {};
const button = {};
const mergeRequest = new MergeRequest();
spyOn(CloseReopenReportToggle.prototype, 'initDroplab');
spyOn(document, 'querySelector').and.returnValue(container);
container.querySelector.and.returnValues(dropdownTrigger, dropdownList, button);
mergeRequest.initCloseReopenReport();
new MergeRequest(); // eslint-disable-line no-new
expect(document.querySelector).toHaveBeenCalledWith('.js-issuable-close-dropdown');
expect(container.querySelector).toHaveBeenCalledWith('.js-issuable-close-toggle');