2021-04-17 20:07:23 +05:30
|
|
|
import { getByText } from '@testing-library/dom';
|
2018-03-17 18:26:18 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2022-07-16 23:28:13 +05:30
|
|
|
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2021-04-17 20:07:23 +05:30
|
|
|
import { EVENT_ISSUABLE_VUE_APP_CHANGE } from '~/issuable/constants';
|
2022-01-26 12:08:38 +05:30
|
|
|
import Issue from '~/issues/issue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe('Issue', () => {
|
|
|
|
let testContext;
|
2021-04-17 20:07:23 +05:30
|
|
|
let mock;
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-04-17 20:07:23 +05:30
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mock.onGet(/(.*)\/related_branches$/).reply(200, {});
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
testContext = {};
|
2021-04-17 20:07:23 +05:30
|
|
|
testContext.issue = new Issue();
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
testContext.issue.dispose();
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
const getIssueCounter = () => document.querySelector('.issue_counter');
|
|
|
|
const getOpenStatusBox = () =>
|
|
|
|
getByText(document, (_, el) => el.textContent.match(/Open/), {
|
2022-07-16 23:28:13 +05:30
|
|
|
selector: '.issuable-status-badge-open',
|
2021-04-17 20:07:23 +05:30
|
|
|
});
|
|
|
|
const getClosedStatusBox = () =>
|
|
|
|
getByText(document, (_, el) => el.textContent.match(/Closed/), {
|
2022-07-16 23:28:13 +05:30
|
|
|
selector: '.issuable-status-badge-closed',
|
2021-04-17 20:07:23 +05:30
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe.each`
|
|
|
|
desc | isIssueInitiallyOpen | expectedCounterText
|
|
|
|
${'with an initially open issue'} | ${true} | ${'1,000'}
|
|
|
|
${'with an initially closed issue'} | ${false} | ${'1,002'}
|
|
|
|
`('$desc', ({ isIssueInitiallyOpen, expectedCounterText }) => {
|
|
|
|
beforeEach(() => {
|
|
|
|
if (isIssueInitiallyOpen) {
|
2022-07-16 23:28:13 +05:30
|
|
|
loadHTMLFixture('issues/open-issue.html');
|
2021-04-17 20:07:23 +05:30
|
|
|
} else {
|
2022-07-16 23:28:13 +05:30
|
|
|
loadHTMLFixture('issues/closed-issue.html');
|
2021-04-17 20:07:23 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
testContext.issueCounter = getIssueCounter();
|
|
|
|
testContext.statusBoxClosed = getClosedStatusBox();
|
|
|
|
testContext.statusBoxOpen = getOpenStatusBox();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
testContext.issueCounter.textContent = '1,001';
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it(`has the proper visible status box when ${isIssueInitiallyOpen ? 'open' : 'closed'}`, () => {
|
|
|
|
if (isIssueInitiallyOpen) {
|
|
|
|
expect(testContext.statusBoxClosed).toHaveClass('hidden');
|
|
|
|
expect(testContext.statusBoxOpen).not.toHaveClass('hidden');
|
|
|
|
} else {
|
|
|
|
expect(testContext.statusBoxClosed).not.toHaveClass('hidden');
|
|
|
|
expect(testContext.statusBoxOpen).toHaveClass('hidden');
|
2020-03-13 15:44:24 +05:30
|
|
|
}
|
2021-04-17 20:07:23 +05:30
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('when vue app triggers change', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
beforeEach(() => {
|
2021-02-22 17:27:13 +05:30
|
|
|
document.dispatchEvent(
|
2021-04-17 20:07:23 +05:30
|
|
|
new CustomEvent(EVENT_ISSUABLE_VUE_APP_CHANGE, {
|
2021-02-22 17:27:13 +05:30
|
|
|
detail: {
|
|
|
|
data: { id: 1 },
|
|
|
|
isClosed: isIssueInitiallyOpen,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2021-04-17 20:07:23 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('displays correct status box', () => {
|
|
|
|
if (isIssueInitiallyOpen) {
|
|
|
|
expect(testContext.statusBoxClosed).not.toHaveClass('hidden');
|
|
|
|
expect(testContext.statusBoxOpen).toHaveClass('hidden');
|
|
|
|
} else {
|
|
|
|
expect(testContext.statusBoxClosed).toHaveClass('hidden');
|
|
|
|
expect(testContext.statusBoxOpen).not.toHaveClass('hidden');
|
|
|
|
}
|
|
|
|
});
|
2020-05-30 21:06:31 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it('updates issueCounter text', () => {
|
|
|
|
expect(testContext.issueCounter).toBeVisible();
|
|
|
|
expect(testContext.issueCounter).toHaveText(expectedCounterText);
|
2020-05-30 21:06:31 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|