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

93 lines
2.3 KiB
JavaScript
Raw Normal View History

import $ from 'jquery';
2018-01-31 04:27:30 -05:00
import MockAdapter from 'axios-mock-adapter';
2018-01-30 09:53:28 -05:00
import axios from '~/lib/utils/axios_utils';
2017-03-01 14:54:04 -05:00
import Issue from '~/issue';
import '~/lib/utils/text_utility';
2016-07-24 16:45:11 -04:00
describe('Issue', () => {
let $boxClosed;
let $boxOpen;
let testContext;
beforeEach(() => {
testContext = {};
});
preloadFixtures('issues/closed-issue.html');
preloadFixtures('issues/open-issue.html');
2016-08-26 19:06:57 -04:00
function expectVisibility($element, shouldBeVisible) {
if (shouldBeVisible) {
expect($element).not.toHaveClass('hidden');
} else {
expect($element).toHaveClass('hidden');
}
}
function expectIssueState(isIssueOpen) {
expectVisibility($boxClosed, !isIssueOpen);
expectVisibility($boxOpen, isIssueOpen);
}
function findElements() {
$boxClosed = $('div.status-box-issue-closed');
2018-10-09 14:03:09 -04:00
2017-01-11 22:49:57 -05:00
expect($boxClosed).toExist();
expect($boxClosed).toHaveText('Closed');
2016-08-26 19:06:57 -04:00
2017-01-11 22:49:57 -05:00
$boxOpen = $('div.status-box-open');
2018-10-09 14:03:09 -04:00
2017-01-11 22:49:57 -05:00
expect($boxOpen).toExist();
expect($boxOpen).toHaveText('Open');
2016-08-26 19:06:57 -04:00
}
[true, false].forEach((isIssueInitiallyOpen) => {
describe(`with ${isIssueInitiallyOpen ? 'open' : 'closed'} issue`, () => {
const action = isIssueInitiallyOpen ? 'close' : 'reopen';
2018-01-30 09:53:28 -05: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 12:51:53 -05:00
mock = new MockAdapter(axios);
mock.onGet(/(.*)\/related_branches$/).reply(200, {});
jest.spyOn(axios, 'get');
2018-01-31 12:51:53 -05:00
findElements(isIssueInitiallyOpen);
});
2016-08-26 19:06:57 -04:00
2018-01-30 09:53:28 -05:00
afterEach(() => {
mock.restore();
2018-01-31 12:51:53 -05:00
$('div.flash-alert').remove();
2018-01-30 09:53:28 -05:00
});
it(`${action}s the issue on dispatch of issuable_vue_app:change event`, () => {
setup();
2018-01-31 12:51:53 -05:00
document.dispatchEvent(
new CustomEvent('issuable_vue_app:change', {
detail: {
data: { id: 1 },
isClosed: isIssueInitiallyOpen,
},
}),
);
2018-01-31 12:51:53 -05:00
expectIssueState(!isIssueInitiallyOpen);
});
2016-07-24 16:45:11 -04:00
});
});
2017-03-01 14:54:04 -05:00
});