debian-mirror-gitlab/spec/frontend/issues/create_merge_request_dropdown_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

118 lines
3.7 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
import MockAdapter from 'axios-mock-adapter';
2021-03-08 18:12:59 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2019-09-30 21:07:59 +05:30
import confidentialState from '~/confidential_merge_request/state';
2022-03-02 08:16:31 +05:30
import CreateMergeRequestDropdown from '~/issues/create_merge_request_dropdown';
2021-03-11 19:13:27 +05:30
import axios from '~/lib/utils/axios_utils';
2018-11-08 19:23:39 +05:30
describe('CreateMergeRequestDropdown', () => {
let axiosMock;
let dropdown;
beforeEach(() => {
axiosMock = new MockAdapter(axios);
2019-09-30 21:07:59 +05:30
document.body.innerHTML = `
2018-11-08 19:23:39 +05:30
<div id="dummy-wrapper-element">
<div class="available"></div>
<div class="unavailable">
2022-06-21 17:19:12 +05:30
<div class="js-create-mr-spinner"></div>
2018-11-08 19:23:39 +05:30
<div class="text"></div>
</div>
<div class="js-ref"></div>
2019-09-30 21:07:59 +05:30
<div class="js-create-mr"></div>
2021-04-29 21:17:54 +05:30
<div class="js-create-merge-request">
<span class="js-spinner"></span>
</div>
2018-11-08 19:23:39 +05:30
<div class="js-create-target"></div>
<div class="js-dropdown-toggle"></div>
</div>
2019-09-30 21:07:59 +05:30
`;
2018-11-08 19:23:39 +05:30
const dummyElement = document.getElementById('dummy-wrapper-element');
dropdown = new CreateMergeRequestDropdown(dummyElement);
dropdown.refsPath = `${TEST_HOST}/dummy/refs?search=`;
});
afterEach(() => {
axiosMock.restore();
});
describe('getRef', () => {
2022-06-21 17:19:12 +05:30
it('escapes branch names correctly', async () => {
2018-11-08 19:23:39 +05:30
const endpoint = `${dropdown.refsPath}contains%23hash`;
2019-09-30 21:07:59 +05:30
jest.spyOn(axios, 'get');
2018-11-08 19:23:39 +05:30
axiosMock.onGet(endpoint).replyOnce({});
2022-06-21 17:19:12 +05:30
await dropdown.getRef('contains#hash');
expect(axios.get).toHaveBeenCalledWith(
endpoint,
expect.objectContaining({ cancelToken: expect.anything() }),
);
2018-11-08 19:23:39 +05:30
});
});
describe('updateCreatePaths', () => {
it('escapes branch names correctly', () => {
dropdown.createBranchPath = `${TEST_HOST}/branches?branch_name=some-branch&issue=42`;
2022-04-04 11:22:00 +05:30
dropdown.createMrPath = `${TEST_HOST}/create_merge_request?merge_request%5Bsource_branch%5D=test&merge_request%5Btarget_branch%5D=master&merge_request%5Bissue_iid%5D=42`;
2018-11-08 19:23:39 +05:30
dropdown.updateCreatePaths('branch', 'contains#hash');
expect(dropdown.createBranchPath).toBe(
`${TEST_HOST}/branches?branch_name=contains%23hash&issue=42`,
);
2018-12-13 13:39:08 +05:30
2018-11-08 19:23:39 +05:30
expect(dropdown.createMrPath).toBe(
2022-04-04 11:22:00 +05:30
`${TEST_HOST}/create_merge_request?merge_request%5Bsource_branch%5D=contains%23hash&merge_request%5Btarget_branch%5D=master&merge_request%5Bissue_iid%5D=42`,
2018-11-08 19:23:39 +05:30
);
});
});
2019-09-30 21:07:59 +05:30
describe('enable', () => {
beforeEach(() => {
dropdown.createMergeRequestButton.classList.add('disabled');
});
afterEach(() => {
confidentialState.selectedProject = {};
});
it('enables button when not confidential issue', () => {
dropdown.enable();
expect(dropdown.createMergeRequestButton.classList).not.toContain('disabled');
});
it('enables when can create confidential issue', () => {
2022-07-23 23:45:48 +05:30
document.querySelector('.js-create-mr').dataset.isConfidential = 'true';
2019-09-30 21:07:59 +05:30
confidentialState.selectedProject = { name: 'test' };
dropdown.enable();
expect(dropdown.createMergeRequestButton.classList).not.toContain('disabled');
});
it('does not enable when can not create confidential issue', () => {
2022-07-23 23:45:48 +05:30
document.querySelector('.js-create-mr').dataset.isConfidential = 'true';
2019-09-30 21:07:59 +05:30
dropdown.enable();
expect(dropdown.createMergeRequestButton.classList).toContain('disabled');
});
});
2021-04-29 21:17:54 +05:30
describe('setLoading', () => {
it.each`
loading | hasClass
${true} | ${false}
${false} | ${true}
`('it toggle loading spinner when loading is $loading', ({ loading, hasClass }) => {
dropdown.setLoading(loading);
expect(document.querySelector('.js-spinner').classList.contains('gl-display-none')).toEqual(
hasClass,
);
});
});
2018-11-08 19:23:39 +05:30
});