2018-03-09 15:18:59 -05:00
|
|
|
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';
|
2017-05-16 17:01:51 -04:00
|
|
|
import '~/lib/utils/text_utility';
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2020-01-10 13:07:43 -05:00
|
|
|
describe('Issue', () => {
|
2020-12-01 07:09:17 -05:00
|
|
|
let $boxClosed;
|
|
|
|
let $boxOpen;
|
2020-01-10 13:07:43 -05:00
|
|
|
let testContext;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
testContext = {};
|
|
|
|
});
|
|
|
|
|
2019-03-26 12:03:28 -04:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
function expectIssueState(isIssueOpen) {
|
|
|
|
expectVisibility($boxClosed, !isIssueOpen);
|
|
|
|
expectVisibility($boxOpen, isIssueOpen);
|
|
|
|
}
|
|
|
|
|
2020-11-27 16:09:14 -05:00
|
|
|
function findElements() {
|
2017-12-12 22:44:59 -05:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
[true, false].forEach((isIssueInitiallyOpen) => {
|
2020-01-10 13:07:43 -05:00
|
|
|
describe(`with ${isIssueInitiallyOpen ? 'open' : 'closed'} issue`, () => {
|
2017-04-12 15:40:35 -04:00
|
|
|
const action = isIssueInitiallyOpen ? 'close' : 'reopen';
|
2018-01-30 09:53:28 -05:00
|
|
|
let mock;
|
2017-04-12 15:40:35 -04:00
|
|
|
|
2020-01-10 13:07:43 -05:00
|
|
|
function setup() {
|
|
|
|
testContext.issue = new Issue();
|
|
|
|
expectIssueState(isIssueInitiallyOpen);
|
|
|
|
|
|
|
|
testContext.$projectIssuesCounter = $('.issue_counter').first();
|
|
|
|
testContext.$projectIssuesCounter.text('1,001');
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-04-12 15:40:35 -04:00
|
|
|
if (isIssueInitiallyOpen) {
|
2019-03-26 12:03:28 -04:00
|
|
|
loadFixtures('issues/open-issue.html');
|
2017-04-12 15:40:35 -04:00
|
|
|
} else {
|
2019-03-26 12:03:28 -04:00
|
|
|
loadFixtures('issues/closed-issue.html');
|
2017-04-12 15:40:35 -04:00
|
|
|
}
|
|
|
|
|
2018-01-31 12:51:53 -05:00
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mock.onGet(/(.*)\/related_branches$/).reply(200, {});
|
2020-01-10 13:07:43 -05:00
|
|
|
jest.spyOn(axios, 'get');
|
2018-01-31 12:51:53 -05:00
|
|
|
|
2017-07-05 12:36:58 -04:00
|
|
|
findElements(isIssueInitiallyOpen);
|
2017-04-12 15:40:35 -04:00
|
|
|
});
|
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
|
|
|
});
|
|
|
|
|
2020-11-27 16:09:14 -05:00
|
|
|
it(`${action}s the issue on dispatch of issuable_vue_app:change event`, () => {
|
2020-01-10 13:07:43 -05:00
|
|
|
setup();
|
2018-01-31 12:51:53 -05:00
|
|
|
|
2020-11-27 16:09:14 -05:00
|
|
|
document.dispatchEvent(
|
|
|
|
new CustomEvent('issuable_vue_app:change', {
|
|
|
|
detail: {
|
|
|
|
data: { id: 1 },
|
|
|
|
isClosed: isIssueInitiallyOpen,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2018-01-31 12:51:53 -05:00
|
|
|
|
2020-11-27 16:09:14 -05:00
|
|
|
expectIssueState(!isIssueInitiallyOpen);
|
2017-04-12 15:40:35 -04:00
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
2017-03-01 14:54:04 -05:00
|
|
|
});
|