gitlab-org--gitlab-foss/spec/frontend/issue_spec.js

123 lines
3.1 KiB
JavaScript
Raw Normal View History

/* eslint-disable one-var, no-use-before-define */
import $ from 'jquery';
2018-01-31 09:27:30 +00:00
import MockAdapter from 'axios-mock-adapter';
2018-01-30 14:53:28 +00:00
import axios from '~/lib/utils/axios_utils';
2017-03-01 19:54:04 +00:00
import Issue from '~/issue';
import '~/lib/utils/text_utility';
2016-07-24 20:45:11 +00:00
describe('Issue', () => {
let testContext;
beforeEach(() => {
testContext = {};
});
let $boxClosed, $boxOpen;
2016-08-26 23:06:57 +00:00
preloadFixtures('issues/closed-issue.html');
preloadFixtures('issues/issue-with-task-list.html');
preloadFixtures('issues/open-issue.html');
preloadFixtures('static/issue_with_mermaid_graph.html');
2016-08-26 23:06:57 +00:00
function expectIssueState(isIssueOpen) {
expectVisibility($boxClosed, !isIssueOpen);
expectVisibility($boxOpen, isIssueOpen);
}
function expectVisibility($element, shouldBeVisible) {
if (shouldBeVisible) {
expect($element).not.toHaveClass('hidden');
} else {
expect($element).toHaveClass('hidden');
}
}
function findElements() {
$boxClosed = $('div.status-box-issue-closed');
2018-10-09 18:03:09 +00:00
2017-01-12 03:49:57 +00:00
expect($boxClosed).toExist();
expect($boxClosed).toHaveText('Closed');
2016-08-26 23:06:57 +00:00
2017-01-12 03:49:57 +00:00
$boxOpen = $('div.status-box-open');
2018-10-09 18:03:09 +00:00
2017-01-12 03:49:57 +00:00
expect($boxOpen).toExist();
expect($boxOpen).toHaveText('Open');
2016-08-26 23:06:57 +00:00
}
2018-10-17 07:13:26 +00:00
[true, false].forEach(isIssueInitiallyOpen => {
describe(`with ${isIssueInitiallyOpen ? 'open' : 'closed'} issue`, () => {
const action = isIssueInitiallyOpen ? 'close' : 'reopen';
2018-01-30 14:53:28 +00:00
let mock;
function setup() {
testContext.issue = new Issue();
expectIssueState(isIssueInitiallyOpen);
testContext.$projectIssuesCounter = $('.issue_counter').first();
testContext.$projectIssuesCounter.text('1,001');
}
beforeEach(() => {
if (isIssueInitiallyOpen) {
loadFixtures('issues/open-issue.html');
} else {
loadFixtures('issues/closed-issue.html');
}
2018-01-31 17:51:53 +00:00
mock = new MockAdapter(axios);
mock.onGet(/(.*)\/related_branches$/).reply(200, {});
jest.spyOn(axios, 'get');
2018-01-31 17:51:53 +00:00
findElements(isIssueInitiallyOpen);
});
2016-08-26 23:06:57 +00:00
2018-01-30 14:53:28 +00:00
afterEach(() => {
mock.restore();
2018-01-31 17:51:53 +00:00
$('div.flash-alert').remove();
2018-01-30 14:53:28 +00:00
});
it(`${action}s the issue on dispatch of issuable_vue_app:change event`, () => {
setup();
2018-01-31 17:51:53 +00:00
document.dispatchEvent(
new CustomEvent('issuable_vue_app:change', {
detail: {
data: { id: 1 },
isClosed: isIssueInitiallyOpen,
},
}),
);
2018-01-31 17:51:53 +00:00
expectIssueState(!isIssueInitiallyOpen);
});
2016-07-24 20:45:11 +00:00
});
});
describe('when not displaying blocked warning', () => {
describe('when clicking a mermaid graph inside an issue description', () => {
let mock;
let spy;
beforeEach(() => {
loadFixtures('static/issue_with_mermaid_graph.html');
mock = new MockAdapter(axios);
spy = jest.spyOn(axios, 'put');
});
afterEach(() => {
mock.restore();
jest.clearAllMocks();
});
it('does not make a PUT request', () => {
Issue.prototype.initIssueBtnEventListeners();
$('svg a.js-issuable-actions').trigger('click');
expect(spy).not.toHaveBeenCalled();
});
});
});
2017-03-01 19:54:04 +00:00
});