pad.pub0.org/tests/frontend/specs/embed_value.js

134 lines
4.0 KiB
JavaScript
Raw Normal View History

describe('embed links', function () {
const objectify = function (str) {
const hash = {};
const parts = str.split('&');
for (let i = 0; i < parts.length; i++) {
const keyValue = parts[i].split('=');
2012-10-08 17:38:53 +00:00
hash[keyValue[0]] = keyValue[1];
}
return hash;
};
2012-10-08 17:38:53 +00:00
const checkiFrameCode = function (embedCode, readonly) {
// turn the code into an html element
const $embediFrame = $(embedCode);
2012-10-08 17:38:53 +00:00
// read and check the frame attributes
const width = $embediFrame.attr('width');
const height = $embediFrame.attr('height');
const name = $embediFrame.attr('name');
expect(width).to.be('100%');
expect(height).to.be('600');
expect(name).to.be(readonly ? 'embed_readonly' : 'embed_readwrite');
// parse the url
const src = $embediFrame.attr('src');
const questionMark = src.indexOf('?');
const url = src.substr(0, questionMark);
const paramsStr = src.substr(questionMark + 1);
const params = objectify(paramsStr);
const expectedParams = {
showControls: 'true',
showChat: 'true',
showLineNumbers: 'true',
useMonospaceFont: 'false',
};
// check the url
if (readonly) {
expect(url.indexOf('r.') > 0).to.be(true);
2012-10-08 17:38:53 +00:00
} else {
expect(url).to.be(helper.padChrome$.window.location.href);
}
// check if all parts of the url are like expected
2012-10-08 17:38:53 +00:00
expect(params).to.eql(expectedParams);
};
2012-10-08 17:38:53 +00:00
describe('read and write', function () {
// create a new pad before each test run
beforeEach(function (cb) {
2012-10-08 17:38:53 +00:00
helper.newPad(cb);
2012-11-01 23:19:59 +00:00
this.timeout(60000);
2012-10-08 17:38:53 +00:00
});
describe('the share link', function () {
it('is the actual pad url', function (done) {
const chrome$ = helper.padChrome$;
2012-10-08 17:38:53 +00:00
// open share dropdown
chrome$('.buttonicon-embed').click();
2012-10-08 17:38:53 +00:00
// get the link of the share field + the actual pad url and compare them
const shareLink = chrome$('#linkinput').val();
const padURL = chrome$.window.location.href;
2012-10-08 17:38:53 +00:00
expect(shareLink).to.be(padURL);
done();
});
});
describe('the embed as iframe code', function () {
it('is an iframe with the the correct url parameters and correct size', function (done) {
const chrome$ = helper.padChrome$;
2012-10-08 17:38:53 +00:00
// open share dropdown
chrome$('.buttonicon-embed').click();
2012-10-08 17:38:53 +00:00
// get the link of the share field + the actual pad url and compare them
const embedCode = chrome$('#embedinput').val();
checkiFrameCode(embedCode, false);
2012-10-08 17:38:53 +00:00
done();
});
});
});
describe('when read only option is set', function () {
beforeEach(function (cb) {
2012-10-08 17:38:53 +00:00
helper.newPad(cb);
2012-11-01 23:19:59 +00:00
this.timeout(60000);
2012-10-08 17:38:53 +00:00
});
describe('the share link', function () {
it('shows a read only url', function (done) {
const chrome$ = helper.padChrome$;
2012-10-08 17:38:53 +00:00
// open share dropdown
chrome$('.buttonicon-embed').click();
2013-03-01 14:04:33 +00:00
chrome$('#readonlyinput').click();
chrome$('#readonlyinput:checkbox:not(:checked)').attr('checked', 'checked');
2012-10-08 17:38:53 +00:00
// get the link of the share field + the actual pad url and compare them
const shareLink = chrome$('#linkinput').val();
const containsReadOnlyLink = shareLink.indexOf('r.') > 0;
2012-10-08 17:38:53 +00:00
expect(containsReadOnlyLink).to.be(true);
done();
});
});
describe('the embed as iframe code', function () {
it('is an iframe with the the correct url parameters and correct size', function (done) {
const chrome$ = helper.padChrome$;
2012-10-08 17:38:53 +00:00
// open share dropdown
chrome$('.buttonicon-embed').click();
// check read only checkbox, a bit hacky
2013-03-01 14:04:33 +00:00
chrome$('#readonlyinput').click();
chrome$('#readonlyinput:checkbox:not(:checked)').attr('checked', 'checked');
2012-10-08 17:38:53 +00:00
// get the link of the share field + the actual pad url and compare them
const embedCode = chrome$('#embedinput').val();
2012-10-08 17:38:53 +00:00
checkiFrameCode(embedCode, true);
2012-10-08 17:38:53 +00:00
done();
});
});
});
});