fixed task list spec
This commit is contained in:
parent
fc53a11503
commit
10cc5d1a80
2 changed files with 39 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
||||||
/* 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';
|
||||||
(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';
|
||||||
});
|
});
|
||||||
|
|
||||||
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) => {
|
|
||||||
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: {} });
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.js-task-list-field').trigger('tasklist:changed');
|
$('.js-task-list-field').trigger('tasklist:changed');
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
expect(axios.patch).toHaveBeenCalledWith(`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`, {
|
||||||
|
merge_request: { description: '- [ ] Task List Item' },
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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';
|
||||||
});
|
});
|
||||||
|
|
||||||
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) => {
|
|
||||||
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: {} });
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.js-task-list-container').trigger('tasklist:changed');
|
$('.js-task-list-container').trigger('tasklist:changed');
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
expect(axios.patch).toHaveBeenCalledWith(`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`, {
|
||||||
|
note: { note: '' },
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue