debian-mirror-gitlab/spec/frontend/issue_spec.js

93 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
2017-08-17 22:00:37 +05:30
import Issue from '~/issue';
2017-09-10 17:25:29 +05:30
import '~/lib/utils/text_utility';
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
describe('Issue', () => {
2021-02-22 17:27:13 +05:30
let $boxClosed;
let $boxOpen;
2020-03-13 15:44:24 +05:30
let testContext;
beforeEach(() => {
testContext = {};
});
2019-07-07 11:18:12 +05:30
preloadFixtures('issues/closed-issue.html');
preloadFixtures('issues/open-issue.html');
2017-08-17 22:00:37 +05:30
function expectVisibility($element, shouldBeVisible) {
if (shouldBeVisible) {
expect($element).not.toHaveClass('hidden');
} else {
expect($element).toHaveClass('hidden');
}
}
2021-02-22 17:27:13 +05:30
function expectIssueState(isIssueOpen) {
expectVisibility($boxClosed, !isIssueOpen);
expectVisibility($boxOpen, isIssueOpen);
}
function findElements() {
2018-03-17 18:26:18 +05:30
$boxClosed = $('div.status-box-issue-closed');
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect($boxClosed).toExist();
expect($boxClosed).toHaveText('Closed');
$boxOpen = $('div.status-box-open');
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect($boxOpen).toExist();
expect($boxOpen).toHaveText('Open');
}
2018-12-13 13:39:08 +05:30
[true, false].forEach(isIssueInitiallyOpen => {
2020-03-13 15:44:24 +05:30
describe(`with ${isIssueInitiallyOpen ? 'open' : 'closed'} issue`, () => {
2017-08-17 22:00:37 +05:30
const action = isIssueInitiallyOpen ? 'close' : 'reopen';
2018-03-17 18:26:18 +05:30
let mock;
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
function setup() {
testContext.issue = new Issue();
expectIssueState(isIssueInitiallyOpen);
testContext.$projectIssuesCounter = $('.issue_counter').first();
testContext.$projectIssuesCounter.text('1,001');
}
beforeEach(() => {
2017-08-17 22:00:37 +05:30
if (isIssueInitiallyOpen) {
2019-07-07 11:18:12 +05:30
loadFixtures('issues/open-issue.html');
2017-08-17 22:00:37 +05:30
} else {
2019-07-07 11:18:12 +05:30
loadFixtures('issues/closed-issue.html');
2017-08-17 22:00:37 +05:30
}
2018-03-17 18:26:18 +05:30
mock = new MockAdapter(axios);
mock.onGet(/(.*)\/related_branches$/).reply(200, {});
2020-03-13 15:44:24 +05:30
jest.spyOn(axios, 'get');
2018-03-17 18:26:18 +05:30
2017-09-10 17:25:29 +05:30
findElements(isIssueInitiallyOpen);
2018-03-17 18:26:18 +05:30
});
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
afterEach(() => {
mock.restore();
$('div.flash-alert').remove();
2017-08-17 22:00:37 +05:30
});
2021-02-22 17:27:13 +05:30
it(`${action}s the issue on dispatch of issuable_vue_app:change event`, () => {
2020-03-13 15:44:24 +05:30
setup();
2020-05-30 21:06:31 +05:30
2021-02-22 17:27:13 +05:30
document.dispatchEvent(
new CustomEvent('issuable_vue_app:change', {
detail: {
data: { id: 1 },
isClosed: isIssueInitiallyOpen,
},
}),
);
2020-05-30 21:06:31 +05:30
2021-02-22 17:27:13 +05:30
expectIssueState(!isIssueInitiallyOpen);
2020-05-30 21:06:31 +05:30
});
});
});
2017-08-17 22:00:37 +05:30
});