').html(tc.wantPadLines[i]);
- if (!gotDiv[0].isEqualNode(wantDiv[0])) return false;
- }
- return true;
- });
- } catch (err) {
- const formatLine = (l) => ` ${JSON.stringify(l)}`;
- const g = helper.linesDiv().map((div) => formatLine(div.html())).join('\n');
- const w = tc.wantPadLines.map(formatLine).join('\n');
- throw new Error(`Import failed. Got pad lines:\n${g}\nWant pad lines:\n${w}`);
- }
- });
-
- it('export to HTML', async function () {
- const link = helper.padChrome$('#exporthtmla').attr('href');
- const url = new URL(link, helper.padChrome$.window.location.href).href;
- const gotHtml = await $.ajax({url, dataType: 'html'});
- const gotBody = $('body', htmlToDoc(gotHtml));
- gotBody.html(gotBody.html().replace(/^\s+|\s+$/g, ''));
- const wantBody = $('body', htmlBodyToDoc(tc.wantExportHtmlBody));
- if (!gotBody[0].isEqualNode(wantBody[0])) {
- throw new Error(`Got exported HTML body:\n ${JSON.stringify(gotBody.html())}\n` +
- `Want HTML body:\n ${JSON.stringify(wantBody.html())}`);
- }
- });
-
- it('export to text', async function () {
- const link = helper.padChrome$('#exportplaina').attr('href');
- const url = new URL(link, helper.padChrome$.window.location.href).href;
- const got = await $.ajax({url, dataType: 'text'});
- expect(got).to.be(tc.wantExportText);
- });
+ 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 newlines from txt', function (done) {
+ const importurl = `${helper.padChrome$.window.location.href}/import`;
+ const textWithNewLines = 'imported text\nnewline';
+ importrequest(textWithNewLines, importurl, 'txt');
+ helper.waitFor(() => expect(getinnertext())
+ .to.be('
imported text\n
newline\n
\n'));
+ const results = exportfunc(helper.padChrome$.window.location.href);
+ expect(results[0][1]).to.be('imported text
newline
');
+ expect(results[1][1]).to.be('imported text\nnewline\n\n');
+ done();
+ });
+ xit('import a pad with newlines from html', function (done) {
+ const importurl = `${helper.padChrome$.window.location.href}/import`;
+ const htmlWithNewLines = 'htmltext
newline';
+ importrequest(htmlWithNewLines, importurl, 'html');
+ helper.waitFor(() => expect(getinnertext())
+ .to.be('
htmltext\n
newline\n
\n'));
+ const results = exportfunc(helper.padChrome$.window.location.href);
+ expect(results[0][1]).to.be('htmltext
newline
');
+ expect(results[1][1]).to.be('htmltext\nnewline\n\n');
+ done();
+ });
+ xit('import a pad with attributes from html', function (done) {
+ const importurl = `${helper.padChrome$.window.location.href}/import`;
+ const htmlWithNewLines = 'htmltext
' +
+ 'newline';
+ importrequest(htmlWithNewLines, importurl, 'html');
+ helper.waitFor(() => expect(getinnertext())
+ .to.be('htmltext\n' +
+ 'newline\n
\n'));
+ const results = exportfunc(helper.padChrome$.window.location.href);
+ expect(results[0][1])
+ .to.be('htmltext
newline
');
+ expect(results[1][1]).to.be('htmltext\nnewline\n\n');
+ done();
+ });
+ xit('import a pad with bullets from html', function (done) {
+ const importurl = `${helper.padChrome$.window.location.href}/import`;
+ const htmlWithBullets = '- bullet line 1
' +
+ '- bullet line 2
- bullet2 line 1
' +
+ '- bullet2 line 2
';
+ importrequest(htmlWithBullets, importurl, 'html');
+ helper.waitFor(() => expect(getinnertext()).to.be(
+ '\n' +
+ '\n' +
+ '\n' +
+ '\n' +
+ '
\n'));
+ const results = exportfunc(helper.padChrome$.window.location.href);
+ expect(results[0][1]).to.be(
+ '- bullet line 1
- bullet line 2
' +
+ '- bullet2 line 1
- bullet2 line 2
');
+ expect(results[1][1])
+ .to.be('\t* bullet line 1\n\t* bullet line 2\n' +
+ '\t\t* bullet2 line 1\n\t\t* bullet2 line 2\n\n');
+ done();
+ });
+ xit('import a pad with bullets and newlines from html', function (done) {
+ const importurl = `${helper.padChrome$.window.location.href}/import`;
+ const htmlWithBullets = '
';
+ importrequest(htmlWithBullets, importurl, 'html');
+ helper.waitFor(() => expect(getinnertext()).to.be(
+ '\n' +
+ '
\n' +
+ '\n' +
+ '\n' +
+ '
\n' +
+ '\n' +
+ '
\n'));
+ const results = exportfunc(helper.padChrome$.window.location.href);
+ expect(results[0][1]).to.be(
+ '
' +
+ '- bullet line 2
' +
+ '
');
+ expect(results[1][1]).to.be(
+ '\t* bullet line 1\n\n\t* bullet line 2\n\t\t* bullet2 line 1\n\n\t\t* bullet2 line 2\n\n');
+ done();
+ });
+ xit('import a pad with bullets and newlines and attributes from html', function (done) {
+ const importurl = `${helper.padChrome$.window.location.href}/import`;
+ const htmlWithBullets = '
' +
+ '
' +
+ '- ' +
+ '
bullet4 line 2 bisu - ' +
+ '
bullet4 line 2 bs ' +
+ '- bullet4 line 2 u' +
+ '
uis
';
+ importrequest(htmlWithBullets, importurl, 'html');
+ helper.waitFor(() => expect(getinnertext()).to.be(
+ '\n
\n' +
+ '\n' +
+ '\n
\n' +
+ '- ' +
+ '
bullet4 line 2 bisu
\n' +
+ '\n' +
+ '- bullet4 line 2 u' +
+ '
uis
\n' +
+ '
\n'));
+ const results = exportfunc(helper.padChrome$.window.location.href);
+ expect(results[0][1]).to.be(
+ '' +
+ '
bullet4 line 2 bisu' +
+ 'bullet4 line 2 bs' +
+ '- bullet4 line 2 u
uis
');
+ expect(results[1][1]).to.be(
+ '\t* bullet line 1\n\n\t* bullet line 2\n\t\t* bullet2 line 1\n\n\t\t\t\t* bullet4 line 2' +
+ ' bisu\n\t\t\t\t* bullet4 line 2 bs\n\t\t\t\t* bullet4 line 2 uuis\n\n');
+ done();
+ });
+ xit('import a pad with nested bullets from html', function (done) {
+ const importurl = `${helper.padChrome$.window.location.href}/import`;
+ const htmlWithBullets = '' +
+ '- bullet4 line 2
' +
+ '- bullet4 line 2
- bullet4 line 2
- bullet3 line 1
' +
+ '
- bullet2 line 1
';
+ importrequest(htmlWithBullets, importurl, 'html');
+ const oldtext = getinnertext();
+ helper.waitFor(() => oldtext !== getinnertext()
+ // return expect(getinnertext()).to.be('\
+ // \n\
+ // \n\
+ // \n\
+ // \n\
+ // \n\
+ // \n\
+ //
\n')
+ );
+
+ const results = exportfunc(helper.padChrome$.window.location.href);
+ expect(results[0][1]).to.be(
+ '- bullet line 1
- bullet line 2
' +
+ '- bullet2 line 1
- bullet4 line 2
' +
+ '- bullet4 line 2
- bullet4 line 2
- bullet3 line 1
' +
+ '- bullet2 line 1
');
+ expect(results[1][1]).to.be(
+ '\t* bullet line 1\n\t* bullet line 2\n\t\t* bullet2 line 1\n\t\t\t\t* bullet4 line 2' +
+ '\n\t\t\t\t* bullet4 line 2\n\t\t\t\t* bullet4 line 2\n\t\t\t* bullet3 line 1' +
+ '\n\t* bullet2 line 1\n\n');
+ done();
+ });
+ xit('import with 8 levels of bullets and newlines and attributes from html', function (done) {
+ const importurl = `${helper.padChrome$.window.location.href}/import`;
+ const htmlWithBullets =
+ '
' +
+ '- ' +
+ '
bullet4 line 2 bisu ' +
+ 'bullet4 line 2 bs- bullet4 line 2 u' +
+ '
uis ' +
+ '
';
+ importrequest(htmlWithBullets, importurl, 'html');
+ helper.waitFor(() => expect(getinnertext()).to.be(
+ '\n
\n' +
+ '\n' +
+ '\n
\n' +
+ 'bullet4 line 2 bisu' +
+ '
\n' +
+ '\n' +
+ '- bullet4 line 2 u' +
+ '
uis' +
+ '
\n' +
+ '\n' +
+ '\n' +
+ '\n' +
+ '
\n'));
+ const results = exportfunc(helper.padChrome$.window.location.href);
+ expect(results[0][1]).to.be(
+ '
' +
+ '
' +
+ 'bullet4 line 2 bisu' +
+ 'bullet4 line 2 bs- bullet4 line 2 u' +
+ '
uis
');
+ expect(results[1][1]).to.be(
+ '\t* bullet line 1\n\n\t* bullet line 2\n\t\t* ' +
+ 'bullet2 line 1\n\n\t\t\t\t* bullet4 line 2 bisu\n\t\t\t\t* bullet4 line 2 ' +
+ 'bs\n\t\t\t\t* bullet4 line 2 uuis\n\t\t\t\t\t\t\t\t* foo\n\t\t\t\t\t\t\t\t* ' +
+ 'foobar bs\n\t\t\t\t\t* foobar\n\n');
+ done();
+ });
+
+ xit('import a pad with ordered lists from html', function (done) {
+ const importurl = `${helper.padChrome$.window.location.href}/import`;
+ const htmlWithBullets = '' +
+ '- number 1 line 1
' +
+ '- number 2 line 2
';
+ importrequest(htmlWithBullets, importurl, 'html');
+ console.error(getinnertext());
+ expect(getinnertext()).to.be(
+ '- number 1 line 1
\n' +
+ '- number 2 line 2
\n' +
+ '
\n');
+ const results = exportfunc(helper.padChrome$.window.location.href);
+ expect(results[0][1]).to.be(
+ '- number 1 line 1
' +
+ '
- number 2 line 2
');
+ expect(results[1][1]).to.be('');
+ done();
+ });
+ xit('import a pad with ordered lists and newlines from html', function (done) {
+ const importurl = `${helper.padChrome$.window.location.href}/import`;
+ const htmlWithBullets = '' +
+ '- number 9 line 1
' +
+ '- number 10 line 2
' +
+ '- number 2 times line 1
' +
+ '- number 2 times line 2
';
+ importrequest(htmlWithBullets, importurl, 'html');
+ expect(getinnertext()).to.be(
+ '- number 9 line 1
\n' +
+ '
\n' +
+ '- number 10 line 2
' +
+ '
\n' +
+ '- number 2 times line 1
\n' +
+ '
\n' +
+ '- number 2 times line 2
\n' +
+ '
\n');
+ const results = exportfunc(helper.padChrome$.window.location.href);
+ console.error(results);
+ done();
+ });
+ xit('import with nested ordered lists and attributes and newlines from html', function (done) {
+ const importurl = `${helper.padChrome$.window.location.href}/import`;
+ const htmlWithBullets = '- ' +
+ '
bold strikethrough italics underline' +
+ ' line 1bold ' +
+ '
' +
+ '- number 10 line 2
' +
+ '- number 2 times line 1
' +
+ '' +
+ '- number 2 times line 2
';
+ importrequest(htmlWithBullets, importurl, 'html');
+ expect(getinnertext()).to.be(
+ '' +
+ 'bold strikethrough italics underline' +
+ ' line 1bold
\n' +
+ '
\n' +
+ '- number 10 line 2
\n' +
+ '- ' +
+ 'number 2 times line 1
\n' +
+ '
\n' +
+ '- number 2 times line 2
\n' +
+ '
\n');
+ const results = exportfunc(helper.padChrome$.window.location.href);
+ console.error(results);
+ done();
+ });
});