1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
import MockAdapter from 'axios-mock-adapter';
import $ from 'jquery';
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
import { TEST_HOST } from 'spec/test_constants';
import waitForPromises from 'helpers/wait_for_promises';
import { createAlert } from '~/flash';
import axios from '~/lib/utils/axios_utils';
import { HTTP_STATUS_CONFLICT } from '~/lib/utils/http_status';
import MergeRequest from '~/merge_request';
jest.mock('~/flash');
describe('MergeRequest', () => {
const test = {};
describe('task lists', () => {
let mock;
beforeEach(() => {
loadHTMLFixture('merge_requests/merge_request_with_task_list.html');
jest.spyOn(axios, 'patch');
mock = new MockAdapter(axios);
mock
.onPatch(`${TEST_HOST}/frontend-fixtures/merge-requests-project/-/merge_requests/1.json`)
.reply(200, {});
test.merge = new MergeRequest();
return test.merge;
});
afterEach(() => {
mock.restore();
resetHTMLFixture();
});
it('modifies the Markdown field', async () => {
jest.spyOn($, 'ajax').mockImplementation();
const changeEvent = document.createEvent('HTMLEvents');
changeEvent.initEvent('change', true, true);
$('input[type=checkbox]').first().attr('checked', true)[0].dispatchEvent(changeEvent);
await waitForPromises();
expect($('.js-task-list-field').val()).toBe(
'- [x] Task List Item\n- [ ]\n- [ ] Task List Item 2\n',
);
});
it('ensure that task with only spaces does not get checked incorrectly', async () => {
// fixed in 'deckar01-task_list', '2.2.1' gem
jest.spyOn($, 'ajax').mockImplementation();
const changeEvent = document.createEvent('HTMLEvents');
changeEvent.initEvent('change', true, true);
$('input[type=checkbox]').last().attr('checked', true)[0].dispatchEvent(changeEvent);
await waitForPromises();
expect($('.js-task-list-field').val()).toBe(
'- [ ] Task List Item\n- [ ]\n- [x] Task List Item 2\n',
);
});
describe('tasklist', () => {
const lineNumber = 8;
const lineSource = '- [ ] item 8';
const index = 3;
const checked = true;
it('submits an ajax request on tasklist:changed', async () => {
$('.js-task-list-field').trigger({
type: 'tasklist:changed',
detail: { lineNumber, lineSource, index, checked },
});
await waitForPromises();
expect(axios.patch).toHaveBeenCalledWith(
`${TEST_HOST}/frontend-fixtures/merge-requests-project/-/merge_requests/1.json`,
{
merge_request: {
description: '- [ ] Task List Item\n- [ ]\n- [ ] Task List Item 2\n',
lock_version: 0,
update_task: { line_number: lineNumber, line_source: lineSource, index, checked },
},
},
);
});
it('shows an error notification when tasklist update failed', async () => {
mock
.onPatch(`${TEST_HOST}/frontend-fixtures/merge-requests-project/-/merge_requests/1.json`)
.reply(HTTP_STATUS_CONFLICT, {});
$('.js-task-list-field').trigger({
type: 'tasklist:changed',
detail: { lineNumber, lineSource, index, checked },
});
await waitForPromises();
expect(createAlert).toHaveBeenCalledWith(
expect.objectContaining({
message:
'Someone edited this merge request at the same time you did. Please refresh the page to see changes.',
}),
);
});
});
});
describe('hideCloseButton', () => {
describe('merge request of current_user', () => {
beforeEach(() => {
loadHTMLFixture('merge_requests/merge_request_of_current_user.html');
test.el = document.querySelector('.js-issuable-actions');
MergeRequest.hideCloseButton();
});
it('hides the close button', () => {
const smallCloseItem = test.el.querySelector('.js-close-item');
expect(smallCloseItem).toHaveClass('hidden');
});
});
});
});
|