Commit 10cc5d1a authored by Phil Hughes's avatar Phil Hughes

fixed task list spec

parent fc53a115
/* eslint-disable space-before-function-paren, no-return-assign */ /* eslint-disable space-before-function-paren, no-return-assign */
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import MergeRequest from '~/merge_request'; import MergeRequest from '~/merge_request';
import CloseReopenReportToggle from '~/close_reopen_report_toggle'; import CloseReopenReportToggle from '~/close_reopen_report_toggle';
...@@ -8,11 +8,24 @@ import IssuablesHelper from '~/helpers/issuables_helper'; ...@@ -8,11 +8,24 @@ import IssuablesHelper from '~/helpers/issuables_helper';
(function() { (function() {
describe('MergeRequest', function() { describe('MergeRequest', function() {
describe('task lists', function() { describe('task lists', function() {
let mock;
preloadFixtures('merge_requests/merge_request_with_task_list.html.raw'); preloadFixtures('merge_requests/merge_request_with_task_list.html.raw');
beforeEach(function() { beforeEach(function() {
loadFixtures('merge_requests/merge_request_with_task_list.html.raw'); loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
spyOn(axios, 'patch').and.callThrough();
mock = new MockAdapter(axios);
mock.onPatch(`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`).reply(200, {});
return this.merge = new MergeRequest(); return this.merge = new MergeRequest();
}); });
afterEach(() => {
mock.restore();
});
it('modifies the Markdown field', function() { it('modifies the Markdown field', function() {
spyOn(jQuery, 'ajax').and.stub(); spyOn(jQuery, 'ajax').and.stub();
const changeEvent = document.createEvent('HTMLEvents'); const changeEvent = document.createEvent('HTMLEvents');
...@@ -22,15 +35,14 @@ import IssuablesHelper from '~/helpers/issuables_helper'; ...@@ -22,15 +35,14 @@ import IssuablesHelper from '~/helpers/issuables_helper';
}); });
it('submits an ajax request on tasklist:changed', (done) => { it('submits an ajax request on tasklist:changed', (done) => {
spyOn(axios, 'patch').and.callFake((url, data) => { $('.js-task-list-field').trigger('tasklist:changed');
expect(url).toBe(`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`);
expect(data.merge_request.description).not.toBe(null);
done();
return Promise.resolve({ data: {} }); setTimeout(() => {
expect(axios.patch).toHaveBeenCalledWith(`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`, {
merge_request: { description: '- [ ] Task List Item' },
});
done();
}); });
$('.js-task-list-field').trigger('tasklist:changed');
}); });
}); });
......
...@@ -50,13 +50,24 @@ import timeoutPromise from './helpers/set_timeout_promise_helper'; ...@@ -50,13 +50,24 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
}); });
describe('task lists', function() { describe('task lists', function() {
let mock;
beforeEach(function() { beforeEach(function() {
spyOn(axios, 'patch').and.callThrough();
mock = new MockAdapter(axios);
mock.onPatch(`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`).reply(200, {});
$('.js-comment-button').on('click', function(e) { $('.js-comment-button').on('click', function(e) {
e.preventDefault(); e.preventDefault();
}); });
this.notes = new Notes('', []); this.notes = new Notes('', []);
}); });
afterEach(() => {
mock.restore();
});
it('modifies the Markdown field', function() { it('modifies the Markdown field', function() {
const changeEvent = document.createEvent('HTMLEvents'); const changeEvent = document.createEvent('HTMLEvents');
changeEvent.initEvent('change', true, true); changeEvent.initEvent('change', true, true);
...@@ -66,15 +77,14 @@ import timeoutPromise from './helpers/set_timeout_promise_helper'; ...@@ -66,15 +77,14 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
}); });
it('submits an ajax request on tasklist:changed', function(done) { it('submits an ajax request on tasklist:changed', function(done) {
spyOn(axios, 'patch').and.callFake((url, data) => { $('.js-task-list-container').trigger('tasklist:changed');
expect(url).toBe(`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`);
expect(data.note).not.toBe(null);
done();
return Promise.resolve({ data: {} }); setTimeout(() => {
expect(axios.patch).toHaveBeenCalledWith(`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`, {
note: { note: '' },
});
done();
}); });
$('.js-task-list-container').trigger('tasklist:changed');
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment