'use strict';
describe('import indents functionality', function () {
beforeEach(function (cb) {
helper.newPad(cb); // creates a new pad
this.timeout(60000);
});
function getinnertext() {
const inner = helper.padInner$;
let newtext = '';
inner('div').each((line, el) => {
newtext += `${el.innerHTML}\n`;
});
return newtext;
}
function importrequest(data, importurl, type) {
let error;
const result = $.ajax({
url: importurl,
type: 'post',
processData: false,
async: false,
contentType: 'multipart/form-data; boundary=boundary',
accepts: {
text: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
},
data: [
'Content-Type: multipart/form-data; boundary=--boundary',
'',
'--boundary',
`Content-Disposition: form-data; name="file"; filename="import.${type}"`,
'Content-Type: text/plain',
'',
data,
'',
'--boundary',
].join('\r\n'),
error(res) {
error = res;
},
});
expect(error).to.be(undefined);
return result;
}
function exportfunc(link) {
const exportresults = [];
$.ajaxSetup({
async: false,
});
$.get(`${link}/export/html`, (data) => {
const start = data.indexOf('
');
const end = data.indexOf('');
const html = data.substr(start + 6, end - start - 6);
exportresults.push(['html', html]);
});
$.get(`${link}/export/txt`, (data) => {
exportresults.push(['txt', data]);
});
return exportresults;
}
xit('import a pad with indents from html', function (done) {
const importurl = `${helper.padChrome$.window.location.href}/import`;
/* eslint-disable-next-line max-len */
const htmlWithIndents = '- indent line 1
- indent line 2
- indent2 line 1
- indent2 line 2
';
importrequest(htmlWithIndents, importurl, 'html');
helper.waitFor(() => expect(getinnertext()).to.be(
'\n' +
'\n' +
'\n' +
'\n' +
'
\n'));
const results = exportfunc(helper.padChrome$.window.location.href);
/* eslint-disable-next-line max-len */
expect(results[0][1]).to.be('- indent line 1
- indent line 2
- indent2 line 1
- indent2 line 2
');
expect(results[1][1])
.to.be('\tindent line 1\n\tindent line 2\n\t\tindent2 line 1\n\t\tindent2 line 2\n\n');
done();
});
xit('import a pad with indented lists and newlines from html', function (done) {
const importurl = `${helper.padChrome$.window.location.href}/import`;
/* eslint-disable-next-line max-len */
const htmlWithIndents = '
';
importrequest(htmlWithIndents, importurl, 'html');
helper.waitFor(() => expect(getinnertext()).to.be(
'\n' +
'
\n' +
'\n' +
'\n' +
'
\n' +
'\n' +
'
\n'));
const results = exportfunc(helper.padChrome$.window.location.href);
/* eslint-disable-next-line max-len */
expect(results[0][1]).to.be('
');
/* eslint-disable-next-line max-len */
expect(results[1][1]).to.be('\tindent line 1\n\n\tindent 1 line 2\n\t\tindent 2 times line 1\n\n\t\tindent 2 times line 2\n\n');
done();
});
xit('import with 8 levels of indents and newlines and attributes from html', function (done) {
const importurl = `${helper.padChrome$.window.location.href}/import`;
/* eslint-disable-next-line max-len */
const htmlWithIndents = '
indent4 line 2 bisuindent4 line 2 bs- indent4 line 2 u
uis
';
importrequest(htmlWithIndents, importurl, 'html');
helper.waitFor(() => expect(getinnertext()).to.be(
'\n
\n' +
'\n' +
'\n
\n' +
'\n' +
'\n' +
'\n' +
'\n' +
'\n' +
'\n' +
'
\n'));
const results = exportfunc(helper.padChrome$.window.location.href);
/* eslint-disable-next-line max-len */
expect(results[0][1]).to.be('
indent4 line 2 bisuindent4 line 2 bs- indent4 line 2 u
uis
');
/* eslint-disable-next-line max-len */
expect(results[1][1]).to.be('\tindent line 1\n\n\tindent line 2\n\t\tindent2 line 1\n\n\t\t\t\tindent4 line 2 bisu\n\t\t\t\tindent4 line 2 bs\n\t\t\t\tindent4 line 2 uuis\n\t\t\t\t\t\t\t\tfoo\n\t\t\t\t\t\t\t\tfoobar bs\n\t\t\t\t\tfoobar\n\n');
done();
});
});